Package org.antlr.v4.runtime.misc
Interface IntSet
-
- All Known Implementing Classes:
IntervalSet
public interface IntSet
A generic set of integers.- See Also:
IntervalSet
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
add(int el)
Adds the specified value to the current set.IntSet
addAll(IntSet set)
Modify the currentIntSet
object to contain all elements that are present in itself, the specifiedset
, or both.IntSet
and(IntSet a)
Return a newIntSet
object containing all elements that are present in both the current set and the specified seta
.IntSet
complement(IntSet elements)
Return a newIntSet
object containing all elements that are present inelements
but not present in the current set.boolean
contains(int el)
Returnstrue
if the set contains the specified element.boolean
equals(Object obj)
boolean
isNil()
Returnstrue
if this set contains no elements.IntSet
or(IntSet a)
Return a newIntSet
object containing all elements that are present in the current set, the specified seta
, or both.void
remove(int el)
Removes the specified value from the current set.int
size()
Return the total number of elements represented by the current set.IntSet
subtract(IntSet a)
Return a newIntSet
object containing all elements that are present in the current set but not present in the input seta
.List<Integer>
toList()
Return a list containing the elements represented by the current set.String
toString()
-
-
-
Method Detail
-
add
void add(int el)
Adds the specified value to the current set.- Parameters:
el
- the value to add- Throws:
IllegalStateException
- if the current set is read-only
-
addAll
IntSet addAll(IntSet set)
Modify the currentIntSet
object to contain all elements that are present in itself, the specifiedset
, or both.- Parameters:
set
- The set to add to the current set. Anull
argument is treated as though it were an empty set.- Returns:
this
(to support chained calls)- Throws:
IllegalStateException
- if the current set is read-only
-
and
IntSet and(IntSet a)
Return a newIntSet
object containing all elements that are present in both the current set and the specified seta
.- Parameters:
a
- The set to intersect with the current set. Anull
argument is treated as though it were an empty set.- Returns:
- A new
IntSet
instance containing the intersection of the current set anda
. The valuenull
may be returned in place of an empty result set.
-
complement
IntSet complement(IntSet elements)
Return a newIntSet
object containing all elements that are present inelements
but not present in the current set. The following expressions are equivalent for input non-nullIntSet
instancesx
andy
.x.complement(y)
y.subtract(x)
- Parameters:
elements
- The set to compare with the current set. Anull
argument is treated as though it were an empty set.- Returns:
- A new
IntSet
instance containing the elements present inelements
but not present in the current set. The valuenull
may be returned in place of an empty result set.
-
or
IntSet or(IntSet a)
Return a newIntSet
object containing all elements that are present in the current set, the specified seta
, or both.This method is similar to
addAll(IntSet)
, but returns a newIntSet
instance instead of modifying the current set.- Parameters:
a
- The set to union with the current set. Anull
argument is treated as though it were an empty set.- Returns:
- A new
IntSet
instance containing the union of the current set anda
. The valuenull
may be returned in place of an empty result set.
-
subtract
IntSet subtract(IntSet a)
Return a newIntSet
object containing all elements that are present in the current set but not present in the input seta
. The following expressions are equivalent for input non-nullIntSet
instancesx
andy
.y.subtract(x)
x.complement(y)
- Parameters:
a
- The set to compare with the current set. Anull
argument is treated as though it were an empty set.- Returns:
- A new
IntSet
instance containing the elements present inelements
but not present in the current set. The valuenull
may be returned in place of an empty result set.
-
size
int size()
Return the total number of elements represented by the current set.- Returns:
- the total number of elements represented by the current set, regardless of the manner in which the elements are stored.
-
isNil
boolean isNil()
Returnstrue
if this set contains no elements.- Returns:
true
if the current set contains no elements; otherwise,false
.
-
contains
boolean contains(int el)
Returnstrue
if the set contains the specified element.- Parameters:
el
- The element to check for.- Returns:
true
if the set containsel
; otherwisefalse
.
-
remove
void remove(int el)
Removes the specified value from the current set. If the current set does not contain the element, no changes are made.- Parameters:
el
- the value to remove- Throws:
IllegalStateException
- if the current set is read-only
-
toList
List<Integer> toList()
Return a list containing the elements represented by the current set. The list is returned in ascending numerical order.- Returns:
- A list containing all element present in the current set, sorted in ascending numerical order.
-
-