IntSet backed by a sorted array of
non-overlapping intervals. It is particularly efficient for representing
large collections of numbers, where the majority of elements appear as part
of a sequential range of numbers that are all part of the set. For example,
the set { 1, 2, 3, 4, 7, 8 } may be represented as { [1, 4], [7, 8] }.
This class is able to represent sets containing any combination of values in
the range Integer#MIN_VALUE to Integer#MAX_VALUE
(inclusive).
| Modifier and Type | Field and Description |
|---|---|
| public static final IntervalSet | |
| public static final IntervalSet | |
| protected List | intervals
The list of sorted, disjoint intervals. |
| protected boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | add(int
the value to add el)Implements org. |
| public void | |
| protected void | |
| public IntervalSet | addAll(IntSet
The set to add to the current set. A set)null argument is
treated as though it were an empty set.Implements org. IntSet object to contain all elements that are
present in itself, the specified set, or both.
|
| public IntervalSet | and(IntSet
The set to intersect with the current set. A other)null
argument is treated as though it were an empty set.Implements org. IntSet object containing all elements that are
present in both the current set and the specified set a.
|
| public void | |
| public IntervalSet | |
| public IntervalSet | complement(IntSet
The set to compare with the current set. A vocabulary)null
argument is treated as though it were an empty set.Implements org. IntSet object containing all elements that are
present in elements but not present in the current set.
|
| public boolean | contains(int
The element to check for. el)Implements org. true if the set contains the specified element.
|
| protected String | |
| protected String | |
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. Implements org. |
| public List | |
| public int | Returns: the maximum value contained in the set. If the set is empty, this method returnsToken#INVALID_TYPE.Returns the maximum value contained in the set. |
| public int | Returns: the minimum value contained in the set. If the set is empty, this method returnsToken#INVALID_TYPE.Returns the minimum value contained in the set. |
| public int | getSingleElement()
Implements org. size is 1;
otherwise, returns Token#INVALID_TYPE.
|
| public int | |
| public boolean | isNil()
Implements org. true if this set contains no elements.
|
| public boolean | |
| public static IntervalSet | |
| public static IntervalSet | |
| public static IntervalSet | |
| public IntervalSet | or(IntSet
The set to union with the current set. A a)null argument
is treated as though it were an empty set.Implements org. IntSet object containing all elements that are
present in the current set, the specified set a, or both.
|
| public void | remove(int
the value to remove el)Implements org. |
| public void | |
| public int | size()
Implements org. |
| public IntervalSet | subtract(IntSet
The set to compare with the current set. A a)null
argument is treated as though it were an empty set.Implements org. IntSet object containing all elements that are
present in the current set but not present in the input set a.
|
| public static IntervalSet | |
| public int[] | |
| public IntegerList | |
| public List | toList()
Implements org. |
| public Set | |
| public String | toString()
Overrides java. Implements org. |
| public String | |
| public String | |
| public String |
| COMPLETE_CHAR_SET | back to summary |
|---|---|
| public static final IntervalSet COMPLETE_CHAR_SET | |
| EMPTY_SET | back to summary |
|---|---|
| public static final IntervalSet EMPTY_SET | |
| intervals | back to summary |
|---|---|
| protected List<Interval> intervals The list of sorted, disjoint intervals. | |
| readonly | back to summary |
|---|---|
| protected boolean readonly | |
| IntervalSet | back to summary |
|---|---|
| public IntervalSet(List<Interval> intervals) | |
| IntervalSet | back to summary |
|---|---|
| public IntervalSet(IntervalSet set) | |
| IntervalSet | back to summary |
|---|---|
| public IntervalSet(int... els) | |
| add | back to summary |
|---|---|
| public void add(int el) Implements org. Add a single element to the set. An isolated element is stored as a range el..el.
| |
| add | back to summary |
|---|---|
| public void add(int a, int b) Add interval; i.e., add all integers from a to b to set. If b<a, do nothing. Keep list in sorted order (by left range value). If overlap, combine ranges. For example, If this is {1..5, 10..20}, adding 6..7 yields {1..5, 6..7, 10..20}. Adding 4..8 yields {1..8, 10..20}. | |
| add | back to summary |
|---|---|
| protected void add(Interval addition) | |
| addAll | back to summary |
|---|---|
| public IntervalSet addAll(IntSet set) Implements org. Doc from org. Modify the current
| |
| and | back to summary |
|---|---|
| public IntervalSet and(IntSet other) Implements org. Doc from org. Return a new
| |
| clear | back to summary |
|---|---|
| public void clear() | |
| complement | back to summary |
|---|---|
| public IntervalSet complement(int minElement, int maxElement) | |
| complement | back to summary |
|---|---|
| public IntervalSet complement(IntSet vocabulary) Implements org. Doc from org. Return a new
| |
| contains | back to summary |
|---|---|
| public boolean contains(int el) Implements org. Doc from org. Returns
| |
| elementName | back to summary |
|---|---|
| protected String elementName(String[] tokenNames, int a)
Deprecated Use
| |
| elementName | back to summary |
|---|---|
protected String elementName(Vocabulary vocabulary, int a)
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Implements org. Are two IntervalSets equal? Because all intervals are sorted and disjoint, equals is a simple linear walk over both lists to make sure they are the same. Interval.equals() is used by the List.equals() method to check the ranges.
| |
| getIntervals | back to summary |
|---|---|
| public List Return a list of Interval objects. | |
| getMaxElement | back to summary |
|---|---|
| public int getMaxElement() Returns the maximum value contained in the set.
| |
| getMinElement | back to summary |
|---|---|
| public int getMinElement() Returns the minimum value contained in the set.
| |
| getSingleElement | back to summary |
|---|---|
| public int getSingleElement() Implements org. Doc from org. Returns the single value contained in the set, if
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isNil | back to summary |
|---|---|
| public boolean isNil() Implements org. Doc from org. Returns
| |
| isReadonly | back to summary |
|---|---|
| public boolean isReadonly() | |
| of | back to summary |
|---|---|
| public static IntervalSet of(int a) Create a set with a single element, el.
| |
| of | back to summary |
|---|---|
| public static IntervalSet of(int a, int b) Create a set with all ints within range [a..b] (inclusive) | |
| or | back to summary |
|---|---|
| public static IntervalSet or(IntervalSet[] sets) combine all sets in the array returned the or'd value | |
| or | back to summary |
|---|---|
| public IntervalSet or(IntSet a) Implements org. Doc from org. Return a new
This method is similar to
| |
| remove | back to summary |
|---|---|
| public void remove(int el) Implements org. Doc from org. Removes the specified value from the current set. If the current set does not contain the element, no changes are made.
| |
| setReadonly | back to summary |
|---|---|
| public void setReadonly(boolean readonly) | |
| size | back to summary |
|---|---|
| public int size() Implements org. Doc from org. Return the total number of elements represented by the current set.
| |
| subtract | back to summary |
|---|---|
| public IntervalSet subtract(IntSet a) Implements org. Doc from org. Return a new
| |
| subtract | back to summary |
|---|---|
| public static IntervalSet subtract(IntervalSet left, IntervalSet right) Compute the set difference between two interval sets. The specific
operation is
| |
| toArray | back to summary |
|---|---|
| public int[] toArray() | |
| toIntegerList | back to summary |
|---|---|
| public IntegerList toIntegerList() | |
| toList | back to summary |
|---|---|
| public List Implements org. Doc from org. Return a list containing the elements represented by the current set. The list is returned in ascending numerical order. | |
| toSet | back to summary |
|---|---|
| public Set | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Implements org. Doc from org.
| |
| toString | back to summary |
|---|---|
| public String toString(boolean elemAreChar) | |
| toString | back to summary |
|---|---|
| public String toString(String[] tokenNames)
Deprecated Use
| |
| toString | back to summary |
|---|---|
| public String toString(Vocabulary vocabulary) | |