Package jflex.core.unicode
Class IntCharSet
- java.lang.Object
-
- jflex.core.unicode.IntCharSet
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.Integer>
public final class IntCharSet extends java.lang.Object implements java.lang.Iterable<java.lang.Integer>
Mutable Char Set implemented with intervals.- Version:
- JFlex 1.9.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IntCharSet.IntCharSetIterator
Iterator for enumerating the elements of this IntCharSet
-
Constructor Summary
Constructors Constructor Description IntCharSet()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int c)
Adds a single character.void
add(Interval interval)
Adds a single interval to this IntCharSet.void
add(IntCharSet set)
Merges the given set into this one.static IntCharSet
allChars()
Creates the set of all characters.IntCharSet
and(IntCharSet set)
Intersects two sets.static IntCharSet
complementOf(IntCharSet x)
Returns the complement of the specified set x, that is, the set of all elements that are not contained in x.boolean
contains(int singleChar)
Returns whether this set contains a given character.boolean
contains(IntCharSet other)
Check whether this set contains a another set.boolean
containsElements()
Returns whether the set contains elements.static IntCharSet
copyOf(IntCharSet intCharSet)
Creates a IntCharSet from an existing IntCharSet.boolean
equals(java.lang.Object o)
IntCharSet
getCaseless(UnicodeProperties unicodeProperties)
Create a caseless version of this charset.(package private) Interval
getFirstInterval()
java.util.List<Interval>
getIntervals()
Returns the intervals.int
hashCode()
private int
indexOf(int c)
Returns the index of the interval that contains the characterc
.java.util.Iterator<Interval>
intervalIterator()
(package private) boolean
invariants()
Checks the invariants of this object.(package private) static boolean
isSubSet(IntCharSet s1, IntCharSet s2)
Very slow but elementary method to determine whether s1 is a subset of s2.IntCharSet.IntCharSetIterator
iterator()
static IntCharSet
nlChars()
The set of new-line characters.int
numIntervals()
Returns the number of intervals.static IntCharSet
of(Interval interval)
Creates a charset that contains only one interval.static IntCharSet
of(Interval... intervals)
Creates a charset that contains the given intervals.static IntCharSet
ofCharacter(int singleChar)
Creates a char set that contains only the given character.static IntCharSet
ofCharacterRange(int start, int end)
Creates a charset that contains only one interval, given by itsstart
andend
values.int
size()
Computes the size of this set.void
sub(IntCharSet set)
Returns the relative complement of this set relative to the provided set.java.lang.String
toString()
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
-
intervals
private final java.util.List<Interval> intervals
-
-
Method Detail
-
of
public static IntCharSet of(Interval interval)
Creates a charset that contains only one interval.
-
of
public static IntCharSet of(Interval... intervals)
Creates a charset that contains the given intervals.- Parameters:
intervals
- the intervals the new set should contains.- Returns:
- a new IntCharSet with the given intervals.
-
ofCharacterRange
public static IntCharSet ofCharacterRange(int start, int end)
Creates a charset that contains only one interval, given by itsstart
andend
values.
-
ofCharacter
public static IntCharSet ofCharacter(int singleChar)
Creates a char set that contains only the given character.
-
allChars
public static IntCharSet allChars()
Creates the set of all characters.- Returns:
- a new IntCharSet that contains all characters.
-
nlChars
public static IntCharSet nlChars()
The set of new-line characters.- Returns:
- a new IntCharSet that contains all characters that are considered a new-line char in Java.
-
indexOf
private int indexOf(int c)
Returns the index of the interval that contains the characterc
.Binary search which interval contains the given character.
- Parameters:
c
- the character to search for- Returns:
- the index of the enclosing interval, or -1 if no such interval
-
add
public void add(IntCharSet set)
Merges the given set into this one.
-
add
public void add(Interval interval)
Adds a single interval to this IntCharSet.- Parameters:
interval
- aInterval
object.
-
add
public void add(int c)
Adds a single character.- Parameters:
c
- Character to add.
-
contains
public boolean contains(int singleChar)
Returns whether this set contains a given character.- Parameters:
singleChar
- a single character (int).- Returns:
- true iff singleChar is contained in the set.
-
contains
public boolean contains(IntCharSet other)
Check whether this set contains a another set.- Parameters:
other
- an IntCharSet.- Returns:
- true iff all characters of
other
are contained in this set.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
and
public IntCharSet and(IntCharSet set)
Intersects two sets.- Parameters:
set
- aIntCharSet
object.- Returns:
- the
IntCharSet
common to the two sets.
-
sub
public void sub(IntCharSet set)
Returns the relative complement of this set relative to the provided set.Assumes that
set
is non-null, and contained in this IntCharSet.- Parameters:
set
- aIntCharSet
to substract from this set.
-
complementOf
public static IntCharSet complementOf(IntCharSet x)
Returns the complement of the specified set x, that is, the set of all elements that are not contained in x.- Parameters:
x
- theIntCharSet
to take the complement of.- Returns:
- the complement of x
-
containsElements
public boolean containsElements()
Returns whether the set contains elements.- Returns:
- Whether the set is non-empty.
-
numIntervals
public int numIntervals()
Returns the number of intervals.- Returns:
- number of intervals.
-
getIntervals
public java.util.List<Interval> getIntervals()
Returns the intervals.- Returns:
- a
List
object.
-
intervalIterator
public java.util.Iterator<Interval> intervalIterator()
- Returns:
- an iterator over the intervals in this set
-
getCaseless
public IntCharSet getCaseless(UnicodeProperties unicodeProperties)
Create a caseless version of this charset.The caseless version contains all characters of this char set, and additionally all lower/upper/title case variants of the characters in this set.
- Parameters:
unicodeProperties
- The Unicode Properties to use when generating caseless equivalence classes.- Returns:
- a caseless copy of this set
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
copyOf
public static IntCharSet copyOf(IntCharSet intCharSet)
Creates a IntCharSet from an existing IntCharSet.- Returns:
- a (deep) copy of the char set.
-
size
public int size()
Computes the size of this set.- Returns:
- how many elements are contained in this set
-
invariants
boolean invariants()
Checks the invariants of this object.- Returns:
- true when the invariants of this objects hold.
-
isSubSet
static boolean isSubSet(IntCharSet s1, IntCharSet s2)
Very slow but elementary method to determine whether s1 is a subset of s2. For assertions in debugging/testing only.- Parameters:
s1
- the first IntCharSets2
- the second IntCharSet- Returns:
- true iff s1 is a subset of s2
-
iterator
public IntCharSet.IntCharSetIterator iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.Integer>
-
getFirstInterval
Interval getFirstInterval()
-
-