public final class Progression extends java.lang.Object implements java.lang.Iterable<java.lang.Integer>, java.lang.Comparable<Progression>
Progressions API.
The class is also fully suitable for use in Map and Collection instances,
since it provides well-behaved implementations of equals,
hashCode, and compareTo. It is also completely immutable,
and is thus guaranteed to be thread-safe.| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Progression other) |
boolean |
contains(int integer)
Determines whether or not iteration over this progression would produce the given integer.
|
boolean |
equals(java.lang.Object object) |
int |
get(int index)
Returns the integer at the specified index in the progression.
|
int |
hashCode() |
java.util.Iterator<java.lang.Integer> |
iterator() |
int |
length()
Calculates the length of this progression, with the step value taken into account.
|
Progression |
reverse()
Creates a new
Progression instance whose starting value is this progression's ending value,
and vice versa. |
java.lang.Integer[] |
toArray()
Returns a new
Integer array filled with all the integers in this progression, in iteration order. |
java.lang.String |
toString() |
public Progression reverse()
Progression instance whose starting value is this progression's ending value,
and vice versa. This method is intended to be used to easily iterate backwards over an array.public boolean contains(int integer)
Progressions.progression(1, 5, 2).contains(3) would evaluate to true,
while Progressions.range(7, 5).contains(4) would evaluate to false.integer - the integer whose range is to be evaluatedProgressions.progression(int, int, int),
Progressions.range(int, int)public int get(int index)
Progressions.range(5, 9).get(2) would evaluate to 7, since 7 is the third
(counting from zero) integer in the range of 5, 6, 7, 8, 9.index - the index to look uptoArray(),
Progressions.range(int, int)get(int) may not
provide optimal performance. In those cases, it might be worth calling toArray()
and accessing the returned array by index instead, since it would produce the same results, without
unnecessary recalculation.public java.lang.Integer[] toArray()
Integer array filled with all the integers in this progression, in iteration order.
For example, Progressions.range(1, 5).toArray() will evaluate to an array containing the
integers 1, 2, 3, 4, 5.Progressions.range(int, int)public int length()
public java.util.Iterator<java.lang.Integer> iterator()
iterator in interface java.lang.Iterable<java.lang.Integer>public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object object)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic int compareTo(Progression other)
compareTo in interface java.lang.Comparable<Progression>