Package org.antlr.v4.runtime.misc
Interface IntSet
-
- All Known Implementing Classes:
IntervalSet
public interface IntSetA generic set of integers.- See Also:
IntervalSet
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidadd(int el)Adds the specified value to the current set.IntSetaddAll(IntSet set)Modify the currentIntSetobject to contain all elements that are present in itself, the specifiedset, or both.IntSetand(IntSet a)Return a newIntSetobject containing all elements that are present in both the current set and the specified seta.IntSetcomplement(IntSet elements)Return a newIntSetobject containing all elements that are present inelementsbut not present in the current set.booleancontains(int el)Returnstrueif the set contains the specified element.booleanequals(Object obj)booleanisNil()Returnstrueif this set contains no elements.IntSetor(IntSet a)Return a newIntSetobject containing all elements that are present in the current set, the specified seta, or both.voidremove(int el)Removes the specified value from the current set.intsize()Return the total number of elements represented by the current set.IntSetsubtract(IntSet a)Return a newIntSetobject 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.StringtoString()
-
-
-
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 currentIntSetobject to contain all elements that are present in itself, the specifiedset, or both.- Parameters:
set- The set to add to the current set. Anullargument 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 newIntSetobject 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. Anullargument is treated as though it were an empty set.- Returns:
- A new
IntSetinstance containing the intersection of the current set anda. The valuenullmay be returned in place of an empty result set.
-
complement
IntSet complement(IntSet elements)
Return a newIntSetobject containing all elements that are present inelementsbut not present in the current set. The following expressions are equivalent for input non-nullIntSetinstancesxandy.x.complement(y)y.subtract(x)
- Parameters:
elements- The set to compare with the current set. Anullargument is treated as though it were an empty set.- Returns:
- A new
IntSetinstance containing the elements present inelementsbut not present in the current set. The valuenullmay be returned in place of an empty result set.
-
or
IntSet or(IntSet a)
Return a newIntSetobject 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 newIntSetinstance instead of modifying the current set.- Parameters:
a- The set to union with the current set. Anullargument is treated as though it were an empty set.- Returns:
- A new
IntSetinstance containing the union of the current set anda. The valuenullmay be returned in place of an empty result set.
-
subtract
IntSet subtract(IntSet a)
Return a newIntSetobject 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-nullIntSetinstancesxandy.y.subtract(x)x.complement(y)
- Parameters:
a- The set to compare with the current set. Anullargument is treated as though it were an empty set.- Returns:
- A new
IntSetinstance containing the elements present inelementsbut not present in the current set. The valuenullmay 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()
Returnstrueif this set contains no elements.- Returns:
trueif the current set contains no elements; otherwise,false.
-
contains
boolean contains(int el)
Returnstrueif the set contains the specified element.- Parameters:
el- The element to check for.- Returns:
trueif 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.
-
-