Class Interval
- java.lang.Object
-
- org.eclipse.collections.impl.AbstractRichIterable<T>
-
- org.eclipse.collections.impl.lazy.AbstractLazyIterable<Integer>
-
- org.eclipse.collections.impl.list.Interval
-
- All Implemented Interfaces:
Serializable,Iterable<Integer>,Collection<Integer>,List<Integer>,RandomAccess,InternalIterable<Integer>,LazyIterable<Integer>,RichIterable<Integer>
public final class Interval extends AbstractLazyIterable<Integer> implements List<Integer>, Serializable, RandomAccess
An Interval is a range of integers that may be iterated over using a step value. Interval is an OO implementation of a for-loop.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, Integer element)booleanadd(Integer integer)booleanaddAll(int index, Collection<? extends Integer> collection)booleanaddAll(Collection<? extends Integer> collection)<R extends Collection<Integer>>
RaddAllTo(R targetCollection)Intervalby(int newStep)This instancebymethod allows Interval to act as a fluent builder for itself.voidclear()<T,R extends Collection<T>>
Rcollect(Function<? super Integer,? extends T> function, R target)booleancontains(int value)Returns true if the Interval contains the specified int value.booleancontains(Object object)booleancontainsAll(int... values)Returns true if the Interval contains all the specified int values.booleancontainsNone(int... values)Returns true if the Interval contains none of the specified int values.LazyIterable<Integer>distinct()LazyIterable<Integer>drop(int count)voideach(Procedure<? super Integer> procedure)booleanequals(Object otherList)static IntervalevensFromTo(int from, int to)Returns an Interval representing the even values from the value from to the value to.Numberfactorial()Returns the Number result of calculating factorial for the range.voidforEach(IntProcedure procedure)voidforEach(Procedure<? super Integer> procedure, int startIndex, int endIndex)voidforEach(Procedure<? super Integer> procedure, Executor executor)This method executes a void procedure against an executor, passing the current index of the interval.<P> voidforEachWith(IntObjectProcedure<? super P> procedure, P parameter)<P> voidforEachWith(Procedure2<? super Integer,? super P> procedure, P parameter)voidforEachWithIndex(IntIntProcedure procedure)voidforEachWithIndex(ObjectIntProcedure<? super Integer> objectIntProcedure)voidforEachWithIndex(ObjectIntProcedure<? super Integer> objectIntProcedure, int startIndex, int endIndex)static Intervalfrom(int newFrom)This staticfrommethod allows Interval to act as a fluent builder for itself.static IntervalfromTo(int from, int to)Returns an Interval starting from the value from to the specified value to with a step value of 1.static IntervalfromToBy(int from, int to, int stepBy)Returns an Interval for the range of integers inclusively between from and to with the specified stepBy value.static IntervalfromToExclusive(int from, int to)Returns an Interval starting from the value from until the specified value to (exclusive) with a step value of 1Integerget(int index)IntegergetFirst()IntegergetLast()inthashCode()intindexOf(Object object)doubleinjectInto(double injectedValue, DoubleObjectToDoubleFunction<? super Integer> function)intinjectInto(int injectedValue, IntObjectToIntFunction<? super Integer> function)longinjectInto(long injectedValue, LongObjectToLongFunction<? super Integer> function)<R> RinjectInto(R injectValue, Function2<? super R,? super Integer,? extends R> function)Iterator<Integer>iterator()intlastIndexOf(Object object)ListIterator<Integer>listIterator()ListIterator<Integer>listIterator(int index)static IntervaloddsFromTo(int from, int to)Returns an Interval representing the odd values from the value from to the value to.static IntervaloneTo(int count)Returns an Interval starting from 1 to the specified count value with a step value of 1.static IntervaloneToBy(int count, int step)Returns an Interval starting from 1 to the specified count value with a step value of step.Numberproduct()Returns the Number result of calculating product for the range.<R extends Collection<Integer>>
Rreject(Predicate<? super Integer> predicate, R target)Integerremove(int index)booleanremove(Object o)booleanremoveAll(Collection<?> collection)booleanretainAll(Collection<?> collection)voidreverseForEach(Procedure<? super Integer> procedure)<R> RreverseInjectInto(R injectValue, Function2<? super R,Integer,? extends R> function)IntervalreverseThis()Returns a new interval with the from and to values reversed and the step value negated.voidrun(Runnable runnable)This method runs a runnable a specified number of times against on the current thread.voidrun(Runnable runnable, Executor executor)This method runs a runnable a specified number of times against an executor.<R extends Collection<Integer>>
Rselect(Predicate<? super Integer> predicate, R target)Integerset(int index, Integer element)intsize()Returns the size of the interval.IntervalsubList(int fromIndex, int toIndex)LazyIterable<Integer>take(int count)Intervalto(int newTo)This instancetomethod allows Interval to act as a fluent builder for itself.Integer[]toArray()static Integer[]toArray(int from, int to)Returns an Integer array with the values inclusively between from and to.MutableBag<Integer>toBag()int[]toIntArray()Converts the interval to an Integer array.MutableList<Integer>toList()static Integer[]toReverseArray(int from, int to)static MutableList<Integer>toReverseList(int from, int to)Returns a MutableList representing the Integer values from the value from to the value to in reverse.MutableSet<Integer>toSet()static MutableSet<Integer>toSet(int from, int to)Returns a Set representing the Integer values from the value from to the value to.StringtoString()Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.static Intervalzero()Returns an Interval starting at zero.static IntervalzeroTo(int count)Returns an Interval starting from 0 to the specified count value with a step value of 1.static IntervalzeroToBy(int count, int step)Returns an Interval starting from 0 to the specified count value with a step value of step.-
Methods inherited from class org.eclipse.collections.impl.lazy.AbstractLazyIterable
asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, concatenate, dropWhile, flatCollect, getOnly, groupBy, groupByEach, groupByUniqueKey, into, isEmpty, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, partition, partitionWith, reject, rejectWith, select, selectInstancesOf, selectWith, sumByDouble, sumByFloat, sumByInt, sumByLong, takeWhile, tap, toArray, toStack, zip, zipWithIndex
-
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, collectIf, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countByEach, countWith, detect, detectOptional, detectWith, detectWithIfNone, detectWithOptional, flatCollect, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, rejectWith, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBiMap, toMap, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach
-
Methods inherited from interface org.eclipse.collections.api.LazyIterable
flatCollectWith
-
Methods inherited from interface java.util.List
containsAll, isEmpty, replaceAll, sort, spliterator, toArray
-
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, aggregateBy, aggregateInPlaceBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countBy, countByEach, countByEach, countByWith, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, makeString, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reduceInPlace, reduceInPlace, rejectWith, selectWith, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toMap, toMap, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
-
-
-
-
Method Detail
-
from
public static Interval from(int newFrom)
This staticfrommethod allows Interval to act as a fluent builder for itself. It works in conjunction with the instance methodsto(int)andby(int).Usage Example:
Interval interval1 = Interval.from(1).to(5); // results in: 1, 2, 3, 4, 5. Interval interval2 = Interval.from(1).to(10).by(2); // results in: 1, 3, 5, 7, 9.
-
to
public Interval to(int newTo)
This instancetomethod allows Interval to act as a fluent builder for itself. It works in conjunction with the static methodfrom(int)and instance methodby(int).Usage Example:
Interval interval1 = Interval.from(1).to(5); // results in: 1, 2, 3, 4, 5. Interval interval2 = Interval.from(1).to(10).by(2); // results in: 1, 3, 5, 7, 9.
-
by
public Interval by(int newStep)
This instancebymethod allows Interval to act as a fluent builder for itself. It works in conjunction with the static methodfrom(int)and instance methodto(int).Usage Example:
Interval interval1 = Interval.from(1).to(5); // results in: 1, 2, 3, 4, 5. Interval interval2 = Interval.from(1).to(10).by(2); // results in: 1, 3, 5, 7, 9.
-
zero
public static Interval zero()
Returns an Interval starting at zero.Usage Example:
Interval interval1 = Interval.zero().to(5); // results in: 0, 1, 2, 3, 4, 5. Interval interval2 = Interval.zero().to(10).by(2); // results in: 0, 2, 4, 6, 8, 10.
-
oneTo
public static Interval oneTo(int count)
Returns an Interval starting from 1 to the specified count value with a step value of 1.
-
oneToBy
public static Interval oneToBy(int count, int step)
Returns an Interval starting from 1 to the specified count value with a step value of step.
-
zeroTo
public static Interval zeroTo(int count)
Returns an Interval starting from 0 to the specified count value with a step value of 1.
-
zeroToBy
public static Interval zeroToBy(int count, int step)
Returns an Interval starting from 0 to the specified count value with a step value of step.
-
fromTo
public static Interval fromTo(int from, int to)
Returns an Interval starting from the value from to the specified value to with a step value of 1.
-
fromToExclusive
public static Interval fromToExclusive(int from, int to)
Returns an Interval starting from the value from until the specified value to (exclusive) with a step value of 1
-
evensFromTo
public static Interval evensFromTo(int from, int to)
Returns an Interval representing the even values from the value from to the value to.
-
oddsFromTo
public static Interval oddsFromTo(int from, int to)
Returns an Interval representing the odd values from the value from to the value to.
-
toSet
public static MutableSet<Integer> toSet(int from, int to)
Returns a Set representing the Integer values from the value from to the value to.
-
toReverseList
public static MutableList<Integer> toReverseList(int from, int to)
Returns a MutableList representing the Integer values from the value from to the value to in reverse.
-
toArray
public static Integer[] toArray(int from, int to)
Returns an Integer array with the values inclusively between from and to.
-
toReverseArray
public static Integer[] toReverseArray(int from, int to)
-
fromToBy
public static Interval fromToBy(int from, int to, int stepBy)
Returns an Interval for the range of integers inclusively between from and to with the specified stepBy value.
-
containsAll
public boolean containsAll(int... values)
Returns true if the Interval contains all the specified int values.
-
containsNone
public boolean containsNone(int... values)
Returns true if the Interval contains none of the specified int values.
-
contains
public boolean contains(Object object)
- Specified by:
containsin interfaceCollection<Integer>- Specified by:
containsin interfaceList<Integer>- Specified by:
containsin interfaceRichIterable<Integer>- Overrides:
containsin classAbstractRichIterable<Integer>
-
contains
public boolean contains(int value)
Returns true if the Interval contains the specified int value.
-
factorial
public Number factorial()
Returns the Number result of calculating factorial for the range.
-
product
public Number product()
Returns the Number result of calculating product for the range.
-
forEachWithIndex
public void forEachWithIndex(IntIntProcedure procedure)
-
forEachWithIndex
public void forEachWithIndex(ObjectIntProcedure<? super Integer> objectIntProcedure)
- Specified by:
forEachWithIndexin interfaceInternalIterable<Integer>- Overrides:
forEachWithIndexin classAbstractRichIterable<Integer>
-
forEachWith
public <P> void forEachWith(IntObjectProcedure<? super P> procedure, P parameter)
-
forEachWith
public <P> void forEachWith(Procedure2<? super Integer,? super P> procedure, P parameter)
- Specified by:
forEachWithin interfaceInternalIterable<Integer>- Overrides:
forEachWithin classAbstractRichIterable<Integer>
-
forEach
public void forEach(IntProcedure procedure)
-
each
public void each(Procedure<? super Integer> procedure)
- Specified by:
eachin interfaceRichIterable<Integer>
-
forEach
public void forEach(Procedure<? super Integer> procedure, Executor executor)
This method executes a void procedure against an executor, passing the current index of the interval.
-
run
public void run(Runnable runnable)
This method runs a runnable a specified number of times against on the current thread.
-
run
public void run(Runnable runnable, Executor executor)
This method runs a runnable a specified number of times against an executor. The method is effectively asynchronous because it does not wait for all the runnables to finish.
-
injectInto
public <R> R injectInto(R injectValue, Function2<? super R,? super Integer,? extends R> function)- Specified by:
injectIntoin interfaceRichIterable<Integer>- Overrides:
injectIntoin classAbstractRichIterable<Integer>
-
injectInto
public int injectInto(int injectedValue, IntObjectToIntFunction<? super Integer> function)- Specified by:
injectIntoin interfaceRichIterable<Integer>- Overrides:
injectIntoin classAbstractRichIterable<Integer>
-
injectInto
public long injectInto(long injectedValue, LongObjectToLongFunction<? super Integer> function)- Specified by:
injectIntoin interfaceRichIterable<Integer>- Overrides:
injectIntoin classAbstractRichIterable<Integer>
-
injectInto
public double injectInto(double injectedValue, DoubleObjectToDoubleFunction<? super Integer> function)- Specified by:
injectIntoin interfaceRichIterable<Integer>- Overrides:
injectIntoin classAbstractRichIterable<Integer>
-
reverseInjectInto
public <R> R reverseInjectInto(R injectValue, Function2<? super R,Integer,? extends R> function)
-
addAllTo
public <R extends Collection<Integer>> R addAllTo(R targetCollection)
-
collect
public <T,R extends Collection<T>> R collect(Function<? super Integer,? extends T> function, R target)
- Specified by:
collectin interfaceRichIterable<Integer>- Overrides:
collectin classAbstractRichIterable<Integer>
-
select
public <R extends Collection<Integer>> R select(Predicate<? super Integer> predicate, R target)
- Specified by:
selectin interfaceRichIterable<Integer>- Overrides:
selectin classAbstractRichIterable<Integer>
-
reject
public <R extends Collection<Integer>> R reject(Predicate<? super Integer> predicate, R target)
- Specified by:
rejectin interfaceRichIterable<Integer>- Overrides:
rejectin classAbstractRichIterable<Integer>
-
equals
public boolean equals(Object otherList)
-
hashCode
public int hashCode()
-
reverseThis
public Interval reverseThis()
Returns a new interval with the from and to values reversed and the step value negated.
-
size
public int size()
Returns the size of the interval.- Specified by:
sizein interfaceCollection<Integer>- Specified by:
sizein interfaceList<Integer>- Specified by:
sizein interfaceRichIterable<Integer>- Overrides:
sizein classAbstractLazyIterable<Integer>
-
toArray
public Integer[] toArray()
- Specified by:
toArrayin interfaceCollection<Integer>- Specified by:
toArrayin interfaceList<Integer>- Specified by:
toArrayin interfaceRichIterable<Integer>- Overrides:
toArrayin classAbstractRichIterable<Integer>
-
toIntArray
public int[] toIntArray()
Converts the interval to an Integer array.
-
toString
public String toString()
Description copied from class:AbstractRichIterableReturns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.Assert.assertEquals("[]", Lists.mutable.empty().toString()); Assert.assertEquals("[1]", Lists.mutable.with(1).toString()); Assert.assertEquals("[1, 2, 3]", Lists.mutable.with(1, 2, 3).toString());- Specified by:
toStringin interfaceRichIterable<Integer>- Overrides:
toStringin classAbstractRichIterable<Integer>- Returns:
- a string representation of this collection.
- See Also:
AbstractCollection.toString()
-
getFirst
public Integer getFirst()
- Specified by:
getFirstin interfaceLazyIterable<Integer>- Specified by:
getFirstin interfaceRichIterable<Integer>- Overrides:
getFirstin classAbstractLazyIterable<Integer>
-
getLast
public Integer getLast()
- Specified by:
getLastin interfaceRichIterable<Integer>- Overrides:
getLastin classAbstractLazyIterable<Integer>
-
forEachWithIndex
public void forEachWithIndex(ObjectIntProcedure<? super Integer> objectIntProcedure, int startIndex, int endIndex)
-
lastIndexOf
public int lastIndexOf(Object object)
- Specified by:
lastIndexOfin interfaceList<Integer>
-
toList
public MutableList<Integer> toList()
- Specified by:
toListin interfaceRichIterable<Integer>- Overrides:
toListin classAbstractRichIterable<Integer>
-
toSet
public MutableSet<Integer> toSet()
- Specified by:
toSetin interfaceRichIterable<Integer>- Overrides:
toSetin classAbstractRichIterable<Integer>
-
toBag
public MutableBag<Integer> toBag()
- Specified by:
toBagin interfaceRichIterable<Integer>- Overrides:
toBagin classAbstractRichIterable<Integer>
-
add
public boolean add(Integer integer)
-
remove
public boolean remove(Object o)
-
addAll
public boolean addAll(Collection<? extends Integer> collection)
-
addAll
public boolean addAll(int index, Collection<? extends Integer> collection)
-
removeAll
public boolean removeAll(Collection<?> collection)
-
retainAll
public boolean retainAll(Collection<?> collection)
-
clear
public void clear()
-
listIterator
public ListIterator<Integer> listIterator()
- Specified by:
listIteratorin interfaceList<Integer>
-
listIterator
public ListIterator<Integer> listIterator(int index)
- Specified by:
listIteratorin interfaceList<Integer>
-
subList
public Interval subList(int fromIndex, int toIndex)
-
take
public LazyIterable<Integer> take(int count)
- Specified by:
takein interfaceLazyIterable<Integer>- Overrides:
takein classAbstractLazyIterable<Integer>
-
drop
public LazyIterable<Integer> drop(int count)
- Specified by:
dropin interfaceLazyIterable<Integer>- Overrides:
dropin classAbstractLazyIterable<Integer>
-
distinct
public LazyIterable<Integer> distinct()
- Specified by:
distinctin interfaceLazyIterable<Integer>- Overrides:
distinctin classAbstractLazyIterable<Integer>
-
-