Package org.geotools.util
Class RangeSet<T extends Comparable<? super T>>
- Type Parameters:
T- The type of range elements.
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Range<T>>,Collection<Range<T>>,Set<Range<T>>,SortedSet<Range<T>>,Cloneable
public class RangeSet<T extends Comparable<? super T>>
extends AbstractSet<Range<T>>
implements SortedSet<Range<T>>, Cloneable, Serializable
An ordered set of ranges.
RangeSet objects store an arbitrary number of ranges in any
Java's primitives (int, float, etc.) or any comparable objects. Ranges may be
added in any order. When a range is added, RangeSet first looks for an existing range overlapping the
specified range. If an overlapping range is found, ranges are merged as of Range.union(org.geotools.util.Range<?>). Consequently, ranges
returned by iterator() may not be the same than added ranges.
All entries in this set can be seen as Range objects. This class is not thread-safe.
- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD), Andrea Aime
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(byte lower, byte upper) Add a range of values to this set.booleanadd(double lower, double upper) Add a range of values to this set.booleanadd(float lower, float upper) Add a range of values to this set.booleanadd(int lower, int upper) Add a range of values to this set.booleanadd(long lower, long upper) Add a range of values to this set.booleanadd(short lower, short upper) Add a range of values to this set.<N> booleanadd(Comparable<? super N> min, Comparable<? super N> max) Adds a range of values to this set.booleanAdd a range to this set.voidclear()Remove all elements from this set of ranges.clone()Returns a clone of this range set.Comparator<Range<T>>Returns the comparator associated with this sorted set.booleanReturnstrueif this set contains the specified element.booleanCompares the specified object with this set of ranges for equality.first()Returns the first (lowest) range currently in this sorted set.final doublegetMaxValueAsDouble(int index) Returns a range's maximum value as adouble.final doublegetMinValueAsDouble(int index) Returns a range's minimum value as adouble.inthashCode()Returns a hash value for this set of ranges.Returns a view of the portion of this sorted set whose elements are strictly less thanupper.<R> intindexOfRange(Comparable<R> value) If the specified value is inside a range, returns the index of this range.iterator()Returns an iterator over the elements in this set of ranges.last()Returns the last (highest) range currently in this sorted set.booleanremove(byte lower, byte upper) Remove a range of values from this set.booleanremove(double lower, double upper) Remove a range of values from this set.booleanremove(float lower, float upper) Remove a range of values from this set.booleanremove(int lower, int upper) Remove a range of values from this set.booleanremove(long lower, long upper) Remove a range of values from this set.booleanremove(short lower, short upper) Remove a range of values from this set.<N> booleanremove(Comparable<? super N> min, Comparable<? super N> max) Remove a range of values from this set.intsize()Returns the number of ranges in this set.Returns a view of the portion of this sorted set whose elements range fromlower, inclusive, toupper, exclusive.Returns a view of the portion of this sorted set whose elements are greater than or equal tolower.toString()Returns a string representation of this set of ranges.Methods inherited from class AbstractSet
removeAllMethods inherited from class AbstractCollection
addAll, containsAll, isEmpty, remove, retainAll, toArray, toArrayMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface Set
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayMethods inherited from interface SortedSet
spliterator
-
Constructor Details
-
RangeSet
Constructs an empty set of range.- Parameters:
type- The class of the range elements. It must be a primitive type or a class implementingComparable.- Throws:
IllegalArgumentException- iftypeis not a primitive type or a class implementingComparable.
-
-
Method Details
-
comparator
Returns the comparator associated with this sorted set.- Specified by:
comparatorin interfaceSortedSet<T extends Comparable<? super T>>
-
clear
public void clear()Remove all elements from this set of ranges.- Specified by:
clearin interfaceCollection<T extends Comparable<? super T>>- Specified by:
clearin interfaceSet<T extends Comparable<? super T>>- Overrides:
clearin classAbstractCollection<Range<T extends Comparable<? super T>>>
-
size
public int size()Returns the number of ranges in this set.- Specified by:
sizein interfaceCollection<T extends Comparable<? super T>>- Specified by:
sizein interfaceSet<T extends Comparable<? super T>>- Specified by:
sizein classAbstractCollection<Range<T extends Comparable<? super T>>>
-
add
Add a range to this set. Range may be added in any order. If the specified range overlap an existing range, the two range will be merged as ofRange.union(org.geotools.util.Range<?>).Note: current version do not support open interval (i.e.
Range.is[Min/Max]Included()must returntrue).- Specified by:
addin interfaceCollection<T extends Comparable<? super T>>- Specified by:
addin interfaceSet<T extends Comparable<? super T>>- Overrides:
addin classAbstractCollection<Range<T extends Comparable<? super T>>>- Parameters:
range- The range to add.- Returns:
trueif this set changed as a result of the call.
-
add
public <N> boolean add(Comparable<? super N> min, Comparable<? super N> max) throws IllegalArgumentException Adds a range of values to this set. Range may be added in any order. If the specified range overlap an existing range, the two ranges will be merged.- Parameters:
min- The lower value, inclusive.max- The upper value, inclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
add
Add a range of values to this set. Range may be added in any order. If the specified range overlap an existing range, the two ranges will be merged.- Parameters:
lower- The lower value, inclusive.upper- The upper value, inclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
add
Add a range of values to this set. Range may be added in any order. If the specified range overlap an existing range, the two ranges will be merged.- Parameters:
lower- The lower value, inclusive.upper- The upper value, inclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
add
Add a range of values to this set. Range may be added in any order. If the specified range overlap an existing range, the two ranges will be merged.- Parameters:
lower- The lower value, inclusive.upper- The upper value, inclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
add
Add a range of values to this set. Range may be added in any order. If the specified range overlap an existing range, the two ranges will be merged.- Parameters:
lower- The lower value, inclusive.upper- The upper value, inclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
add
Add a range of values to this set. Range may be added in any order. If the specified range overlap an existing range, the two ranges will be merged.- Parameters:
lower- The lower value, inclusive.upper- The upper value, inclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
add
Add a range of values to this set. Range may be added in any order. If the specified range overlap an existing range, the two ranges will be merged.- Parameters:
lower- The lower value, inclusive.upper- The upper value, inclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
remove
public <N> boolean remove(Comparable<? super N> min, Comparable<? super N> max) throws IllegalArgumentException Remove a range of values from this set. Range may be removed in any order.- Parameters:
min- The lower value to remove, exclusive.max- The upper value to remove, exclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
remove
Remove a range of values from this set. Range may be removed in any order.- Parameters:
lower- The lower value to remove, exclusive.upper- The upper value to remove, exclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
remove
Remove a range of values from this set. Range may be removed in any order.- Parameters:
lower- The lower value to remove, exclusive.upper- The upper value to remove, exclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
remove
Remove a range of values from this set. Range may be removed in any order.- Parameters:
lower- The lower value to remove, exclusive.upper- The upper value to remove, exclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
remove
Remove a range of values from this set. Range may be removed in any order.- Parameters:
lower- The lower value to remove, exclusive.upper- The upper value to remove, exclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
remove
Remove a range of values from this set. Range may be removed in any order.- Parameters:
lower- The lower value to remove, exclusive.upper- The upper value to remove, exclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
remove
Remove a range of values from this set. Range may be removed in any order.- Parameters:
lower- The lower value to remove, exclusive.upper- The upper value to remove, exclusive.- Returns:
trueif this set changed as a result of the call.- Throws:
IllegalArgumentException- ifloweris greater thanupper.
-
getMinValueAsDouble
public final double getMinValueAsDouble(int index) throws IndexOutOfBoundsException, ClassCastException Returns a range's minimum value as adouble. Theindexcan be any value from 0 inclusive to the set'ssizeexclusive. The returned values always increase withindex.- Parameters:
index- The range index, from 0 inclusive tosizeexclusive.- Returns:
- The minimum value for the range at the specified index.
- Throws:
IndexOutOfBoundsException- ifindexis out of bounds.ClassCastException- if range elements are not convertible to numbers.
-
getMaxValueAsDouble
public final double getMaxValueAsDouble(int index) throws IndexOutOfBoundsException, ClassCastException Returns a range's maximum value as adouble. Theindexcan be any value from 0 inclusive to the set'ssizeexclusive. The returned values always increase withindex.- Parameters:
index- The range index, from 0 inclusive tosizeexclusive.- Returns:
- The maximum value for the range at the specified index.
- Throws:
IndexOutOfBoundsException- ifindexis out of bounds.ClassCastException- if range elements are not convertible to numbers.
-
indexOfRange
If the specified value is inside a range, returns the index of this range. Otherwise, returns-1.- Parameters:
value- The value to search.- Returns:
- The index of the range which contains this value, or -1 if there is no such range.
-
contains
Returnstrueif this set contains the specified element.- Specified by:
containsin interfaceCollection<T extends Comparable<? super T>>- Specified by:
containsin interfaceSet<T extends Comparable<? super T>>- Overrides:
containsin classAbstractCollection<Range<T extends Comparable<? super T>>>- Parameters:
object- The object to compare to this set.- Returns:
trueif the given object is equals to this set.
-
first
Returns the first (lowest) range currently in this sorted set.- Specified by:
firstin interfaceSortedSet<T extends Comparable<? super T>>- Throws:
NoSuchElementException- if the set is empty.
-
last
Returns the last (highest) range currently in this sorted set.- Specified by:
lastin interfaceSortedSet<T extends Comparable<? super T>>- Throws:
NoSuchElementException- if the set is empty.
-
subSet
Returns a view of the portion of this sorted set whose elements range fromlower, inclusive, toupper, exclusive.- Specified by:
subSetin interfaceSortedSet<T extends Comparable<? super T>>- Parameters:
lower- Low endpoint (inclusive) of the sub set.upper- High endpoint (exclusive) of the sub set.- Returns:
- A view of the specified range within this sorted set.
-
headSet
Returns a view of the portion of this sorted set whose elements are strictly less thanupper.- Specified by:
headSetin interfaceSortedSet<T extends Comparable<? super T>>- Parameters:
upper- High endpoint (exclusive) of the headSet.- Returns:
- A view of the specified initial range of this sorted set.
-
tailSet
Returns a view of the portion of this sorted set whose elements are greater than or equal tolower.- Specified by:
tailSetin interfaceSortedSet<T extends Comparable<? super T>>- Parameters:
lower- Low endpoint (inclusive) of the tailSet.- Returns:
- A view of the specified final range of this sorted set.
-
iterator
Returns an iterator over the elements in this set of ranges. All elements areRangeobjects.- Specified by:
iteratorin interfaceCollection<T extends Comparable<? super T>>- Specified by:
iteratorin interfaceIterable<T extends Comparable<? super T>>- Specified by:
iteratorin interfaceSet<T extends Comparable<? super T>>- Specified by:
iteratorin classAbstractCollection<Range<T extends Comparable<? super T>>>
-
hashCode
public int hashCode()Returns a hash value for this set of ranges. This value need not remain consistent between different implementations of the same class.- Specified by:
hashCodein interfaceCollection<T extends Comparable<? super T>>- Specified by:
hashCodein interfaceSet<T extends Comparable<? super T>>- Overrides:
hashCodein classAbstractSet<Range<T extends Comparable<? super T>>>
-
equals
Compares the specified object with this set of ranges for equality.- Specified by:
equalsin interfaceCollection<T extends Comparable<? super T>>- Specified by:
equalsin interfaceSet<T extends Comparable<? super T>>- Overrides:
equalsin classAbstractSet<Range<T extends Comparable<? super T>>>- Parameters:
object- The object to compare with this range.- Returns:
trueif the given object is equals to this range.
-
clone
Returns a clone of this range set. -
toString
Returns a string representation of this set of ranges. The returned string is implementation dependent. It is usually provided for debugging purposes.- Overrides:
toStringin classAbstractCollection<Range<T extends Comparable<? super T>>>
-