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
ConstructorDescriptionRangeSet
(int stop) Constructs a range set for a sequence of numbers, starting at0
with 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, removeAll
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, remove, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods 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 at0
with 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
- ifstep
is0
.
-
-
Method Details
-
size
public int size()Returns the number of elements in this set.- Specified by:
size
in interfaceCollection<Integer>
- Specified by:
size
in interfaceSet<Integer>
- Specified by:
size
in classAbstractCollection<Integer>
-
isEmpty
public boolean isEmpty()Returnstrue
if this set contains no elements.- Specified by:
isEmpty
in interfaceCollection<Integer>
- Specified by:
isEmpty
in interfaceSet<Integer>
- Overrides:
isEmpty
in classAbstractCollection<Integer>
-
contains
Returnstrue
if this set contains the specified element.- Specified by:
contains
in interfaceCollection<Integer>
- Specified by:
contains
in interfaceSet<Integer>
- Overrides:
contains
in classAbstractCollection<Integer>
- Parameters:
o
- element whose presence in this set is to be tested.- Returns:
true
if 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.
-