public class IntervalSet extends Object implements IntSet
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).
| 限定符和类型 | 字段和说明 |
|---|---|
static IntervalSet |
COMPLETE_CHAR_SET |
static IntervalSet |
EMPTY_SET |
protected List<Interval> |
intervals
The list of sorted, disjoint intervals.
|
protected boolean |
readonly |
| 构造器和说明 |
|---|
IntervalSet(int... els) |
IntervalSet(IntervalSet set) |
IntervalSet(List<Interval> intervals) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
add(int el)
Add a single element to the set.
|
protected void |
add(Interval addition) |
void |
add(int a,
int b)
Add interval; i.e., add all integers from a to b to set.
|
IntervalSet |
addAll(IntSet set)
Modify the current
IntSet object to contain all elements that are
present in itself, the specified set, or both. |
IntervalSet |
and(IntSet other)
Return a new
IntSet object containing all elements that are
present in both the current set and the specified set a. |
void |
clear() |
IntervalSet |
complement(int minElement,
int maxElement) |
IntervalSet |
complement(IntSet vocabulary)
Return a new
IntSet object containing all elements that are
present in elements but not present in the current set. |
boolean |
contains(int el)
Returns
true if the set contains the specified element. |
protected String |
elementName(String[] tokenNames,
int a)
已过时。
Use
elementName(Vocabulary, int) instead. |
protected String |
elementName(Vocabulary vocabulary,
int a) |
boolean |
equals(Object obj)
Are two IntervalSets equal?
|
List<Interval> |
getIntervals()
Return a list of Interval objects.
|
int |
getMaxElement()
Returns the maximum value contained in the set.
|
int |
getMinElement()
Returns the minimum value contained in the set.
|
int |
getSingleElement()
Returns the single value contained in the set, if
IntSet.size() is 1;
otherwise, returns Token.INVALID_TYPE. |
int |
hashCode() |
boolean |
isNil()
Returns
true if this set contains no elements. |
boolean |
isReadonly() |
static IntervalSet |
of(int a)
Create a set with a single element, el.
|
static IntervalSet |
of(int a,
int b)
Create a set with all ints within range [a..b] (inclusive)
|
static IntervalSet |
or(IntervalSet[] sets)
combine all sets in the array returned the or'd value
|
IntervalSet |
or(IntSet a)
Return a new
IntSet object containing all elements that are
present in the current set, the specified set a, or both. |
void |
remove(int el)
Removes the specified value from the current set.
|
void |
setReadonly(boolean readonly) |
int |
size()
Return the total number of elements represented by the current set.
|
static IntervalSet |
subtract(IntervalSet left,
IntervalSet right)
Compute the set difference between two interval sets.
|
IntervalSet |
subtract(IntSet a)
Return a new
IntSet object containing all elements that are
present in the current set but not present in the input set a. |
int[] |
toArray() |
IntegerList |
toIntegerList() |
List<Integer> |
toList()
Return a list containing the elements represented by the current set.
|
Set<Integer> |
toSet() |
String |
toString() |
String |
toString(boolean elemAreChar) |
String |
toString(String[] tokenNames)
已过时。
Use
toString(Vocabulary) instead. |
String |
toString(Vocabulary vocabulary) |
public static final IntervalSet COMPLETE_CHAR_SET
public static final IntervalSet EMPTY_SET
protected boolean readonly
public IntervalSet(IntervalSet set)
public IntervalSet(int... els)
@NotNull public static IntervalSet of(int a)
public static IntervalSet of(int a, int b)
public void clear()
public void add(int el)
public void add(int a,
int b)
protected void add(Interval addition)
public static IntervalSet or(IntervalSet[] sets)
public IntervalSet addAll(IntSet set)
IntSetIntSet object to contain all elements that are
present in itself, the specified set, or both.public IntervalSet complement(int minElement, int maxElement)
public IntervalSet complement(IntSet vocabulary)
IntSet object containing all elements that are
present in elements but not present in the current set. The
following expressions are equivalent for input non-null IntSet
instances x and y.
x.complement(y)y.subtract(x)complement 在接口中 IntSetvocabulary - The set to compare with the current set. A null
argument is treated as though it were an empty set.IntSet instance containing the elements present in
elements but not present in the current set. The value
null may be returned in place of an empty result set.public IntervalSet subtract(IntSet a)
IntSetIntSet object containing all elements that are
present in the current set but not present in the input set a.
The following expressions are equivalent for input non-null
IntSet instances x and y.
y.subtract(x)x.complement(y)subtract 在接口中 IntSeta - The set to compare with the current set. A null
argument is treated as though it were an empty set.IntSet instance containing the elements present in
elements but not present in the current set. The value
null may be returned in place of an empty result set.@NotNull public static IntervalSet subtract(@Nullable IntervalSet left, @Nullable IntervalSet right)
left - right. If either of the input sets is
null, it is treated as though it was an empty set.public IntervalSet or(IntSet a)
IntSetIntSet object containing all elements that are
present in the current set, the specified set a, or both.
This method is similar to IntSet.addAll(IntSet), but returns a new
IntSet instance instead of modifying the current set.
public IntervalSet and(IntSet other)
IntSet object containing all elements that are
present in both the current set and the specified set a.public boolean contains(int el)
true if the set contains the specified element.public boolean isNil()
true if this set contains no elements.public int getSingleElement()
IntSet.size() is 1;
otherwise, returns Token.INVALID_TYPE.getSingleElement 在接口中 IntSetIntSet.size() is 1;
otherwise, returns Token.INVALID_TYPE.public int getMaxElement()
Token.INVALID_TYPE.public int getMinElement()
Token.INVALID_TYPE.public boolean equals(Object obj)
public String toString(boolean elemAreChar)
@Deprecated public String toString(String[] tokenNames)
toString(Vocabulary) instead.public String toString(@NotNull Vocabulary vocabulary)
@Deprecated protected String elementName(String[] tokenNames, int a)
elementName(Vocabulary, int) instead.@NotNull protected String elementName(@NotNull Vocabulary vocabulary, int a)
public int size()
IntSetpublic IntegerList toIntegerList()
public List<Integer> toList()
IntSetpublic int[] toArray()
public void remove(int el)
IntSetpublic boolean isReadonly()
public void setReadonly(boolean readonly)
Copyright © 1992–2022 Daniel Sun. All rights reserved.