Package org.forgerock.util
Class RangeSet
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Integer>,Collection<Integer>,Set<Integer>
Exposes a range of integer values as a set. Avoids the allocation of storage for all
values. Order of elements is guaranteed to be in the order from the specified start and
stop values.
If combination of start/stop/step values are not mathematically possible to represent as a set of values, it is represented by this implementation as an empty set.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRangeSet(int stop) Constructs a range set for a sequence of numbers, starting at0with the value to stop.RangeSet(int start, int stop) Constructs a range set for the specified range of integers with a step of1.RangeSet(int start, int stop, int step) Constructs a range set for the specified range of integers and increment. -
Method Summary
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAllMethods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, remove, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
add, addAll, clear, containsAll, remove, retainAll, spliterator, toArray, toArray
-
Constructor Details
-
RangeSet
public RangeSet(int stop) Constructs a range set for a sequence of numbers, starting at0with the value to stop. Equivalent to constructing the range set with:RangeSet(0, stop, 1).- Parameters:
stop- the point at which to stop the range (exclusive).
-
RangeSet
public RangeSet(int start, int stop) Constructs a range set for the specified range of integers with a step of1. Equivalent to constructing the range set with:RangeSet(start, stop, 1).- Parameters:
start- the start of the range (inclusive).stop- the point at which to stop the range (exclusive).
-
RangeSet
public RangeSet(int start, int stop, int step) Constructs a range set for the specified range of integers and increment.- Parameters:
start- the start of the range, inclusive.stop- the point at which to stop the range (exclusive).step- the step to increment for each value in the range.- Throws:
IllegalArgumentException- ifstepis0.
-
-
Method Details
-
size
public int size()Returns the number of elements in this set.- Specified by:
sizein interfaceCollection<Integer>- Specified by:
sizein interfaceSet<Integer>- Specified by:
sizein classAbstractCollection<Integer>
-
isEmpty
public boolean isEmpty()Returnstrueif this set contains no elements.- Specified by:
isEmptyin interfaceCollection<Integer>- Specified by:
isEmptyin interfaceSet<Integer>- Overrides:
isEmptyin classAbstractCollection<Integer>
-
contains
Returnstrueif this set contains the specified element.- Specified by:
containsin interfaceCollection<Integer>- Specified by:
containsin interfaceSet<Integer>- Overrides:
containsin classAbstractCollection<Integer>- Parameters:
o- element whose presence in this set is to be tested.- Returns:
trueif this set contains the specified element.
-
iterator
Returns an iterator over the elements in this set. The elements are returned in the order they are specified from start to stop.
-