Top Description Fields Constructors Methods
org.antlr.misc

public Class IntervalSet

extends Object
implements IntSet
Class Inheritance
All Implemented Interfaces
org.antlr.misc.IntSet
Imports
org.antlr.analysis.Label, org.antlr.tool.Grammar, java.util.ArrayList, .Iterator, .List, .ListIterator

A set of integers that relies on ranges being common to do "run-length-encoded" like compression (if you view an IntSet like a BitSet with runs of 0s and 1s). Only ranges are recorded so that a few ints up near value 1000 don't cause massive bitsets, just two integer intervals. element values may be negative. Useful for sets of EPSILON and EOF. 0..9 char range is index pair ['0','9']. Multiple ranges are encoded with multiple index pairs. Isolated elements are encoded with an index pair where both intervals are the same. The ranges are ordered and disjoint so that 2..6 appears before 101..103.

Field Summary

Modifier and TypeField and Description
public static final IntervalSet
protected List<Interval>
intervals

The list of sorted, disjoint intervals.

Constructor Summary

AccessConstructor and Description
public
IntervalSet()

Create a set with no elements

public

Method Summary

Modifier and TypeMethod and Description
public void
add(int el)

Implements org.antlr.misc.IntSet.add.

Add a single element to the set.
public void
add(int a, int b)

Add interval; i.e., add all integers from a to b to set.

protected void
add(Interval addition)

public void
addAll(IntSet set)

Implements org.antlr.misc.IntSet.addAll.

Add all elements from incoming set to this set.
public IntervalSet
and(IntSet other)

Implements org.antlr.misc.IntSet.and.

Return a new set with the intersection of this set with other.
public IntervalSet
complement(int minElement, int maxElement)

public IntervalSet
complement(IntSet vocabulary)

Implements org.antlr.misc.IntSet.complement.

Given the set of possible values (rather than, say UNICODE or MAXINT), return a new set containing all elements in vocabulary, but not in this.
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Implements org.antlr.misc.IntSet.equals.

Are two IntervalSets equal?
public int
get(int i)

Get the ith element of ordered set.

public List<Interval>
getIntervals()

Return a list of Interval objects.

public int
public int
getMinElement()

Return minimum element >= 0

public int
getSingleElement()

Implements org.antlr.misc.IntSet.getSingleElement.

If this set is a single integer, return it otherwise Label.INVALID
public boolean
isNil()

Implements org.antlr.misc.IntSet.isNil.

return true if this set has no members
public boolean
member(int el)

Implements org.antlr.misc.IntSet.member.

Is el in any range of this set?
public static IntervalSet
of(int a)

Create a set with a single element, el.

public static IntervalSet
of(int a, int b)

Create a set with all ints within range [a..b] (inclusive)

public IntSet
or(IntSet a)

Implements org.antlr.misc.IntSet.or.

Todo

implement this!

public void
remove(int el)

Implements org.antlr.misc.IntSet.remove.

remove this element from this set
public int
size()

Implements org.antlr.misc.IntSet.size.

Return the size of this set (not the underlying implementation's allocated memory size, for example).
public IntervalSet
subtract(IntSet other)

Implements org.antlr.misc.IntSet.subtract.

Compute this-other via this&~other.
public int[]
public List<Integer>
public BitSet
public String
toString()

Overrides java.lang.Object.toString.

Implements org.antlr.misc.IntSet.toString.

Returns a string representation of the object.
public String
Inherited from java.lang.Object:
clonefinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

COMPLETE_SETback to summary
public static final IntervalSet COMPLETE_SET
intervalsback to summary
protected List<Interval> intervals

The list of sorted, disjoint intervals.

Constructor Detail

IntervalSetback to summary
public IntervalSet()

Create a set with no elements

IntervalSetback to summary
public IntervalSet(List<Interval> intervals)

Method Detail

addback to summary
public void add(int el)

Implements org.antlr.misc.IntSet.add.

Add a single element to the set. An isolated element is stored as a range el..el.

Annotations
@Override
addback 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}.

addback to summary
protected void add(Interval addition)
addAllback to summary
public void addAll(IntSet set)

Implements org.antlr.misc.IntSet.addAll.

Doc from org.antlr.misc.IntSet.addAll.

Add all elements from incoming set to this set. Can limit to set of its own type.

Annotations
@Override
andback to summary
public IntervalSet and(IntSet other)

Implements org.antlr.misc.IntSet.and.

Return a new set with the intersection of this set with other. Because the intervals are sorted, we can use an iterator for each list and just walk them together. This is roughly O(min(n,m)) for interval list lengths n and m.

Annotations
@Override
complementback to summary
public IntervalSet complement(int minElement, int maxElement)
complementback to summary
public IntervalSet complement(IntSet vocabulary)

Implements org.antlr.misc.IntSet.complement.

Given the set of possible values (rather than, say UNICODE or MAXINT), return a new set containing all elements in vocabulary, but not in this. The computation is (vocabulary - this). 'this' is assumed to be either a subset or equal to vocabulary.

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Implements org.antlr.misc.IntSet.equals.

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.

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getback to summary
public int get(int i)

Get the ith element of ordered set. Used only by RandomPhrase so don't bother to implement if you're not doing that for a new ANTLR code gen target.

getIntervalsback to summary
public List<Interval> getIntervals()

Return a list of Interval objects.

getMaxElementback to summary
public int getMaxElement()
getMinElementback to summary
public int getMinElement()

Return minimum element >= 0

getSingleElementback to summary
public int getSingleElement()

Implements org.antlr.misc.IntSet.getSingleElement.

If this set is a single integer, return it otherwise Label.INVALID

Annotations
@Override
isNilback to summary
public boolean isNil()

Implements org.antlr.misc.IntSet.isNil.

return true if this set has no members

Annotations
@Override
memberback to summary
public boolean member(int el)

Implements org.antlr.misc.IntSet.member.

Is el in any range of this set?

Annotations
@Override
ofback to summary
public static IntervalSet of(int a)

Create a set with a single element, el.

ofback to summary
public static IntervalSet of(int a, int b)

Create a set with all ints within range [a..b] (inclusive)

orback to summary
public IntSet or(IntSet a)

Implements org.antlr.misc.IntSet.or.

Todo

implement this!

Annotations
@Override
removeback to summary
public void remove(int el)

Implements org.antlr.misc.IntSet.remove.

Doc from org.antlr.misc.IntSet.remove.

remove this element from this set

Annotations
@Override
sizeback to summary
public int size()

Implements org.antlr.misc.IntSet.size.

Doc from org.antlr.misc.IntSet.size.

Return the size of this set (not the underlying implementation's allocated memory size, for example).

Annotations
@Override
subtractback to summary
public IntervalSet subtract(IntSet other)

Implements org.antlr.misc.IntSet.subtract.

Compute this-other via this&~other. Return a new set containing all elements in this but not in other. other is assumed to be a subset of this; anything that is in other but not in this will be ignored.

Annotations
@Override
toArrayback to summary
public int[] toArray()
toListback to summary
public List<Integer> toList()

Implements org.antlr.misc.IntSet.toList.

Annotations
@Override
toRuntimeBitSetback to summary
public BitSet toRuntimeBitSet()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements org.antlr.misc.IntSet.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
toStringback to summary
public String toString(Grammar g)

Implements org.antlr.misc.IntSet.toString.

Annotations
@Override