Class CodePointSet
Backed by a BitSet keyed directly by code point, so contains(int) is a
single array-word read with no boxing, hashing, or branching beyond a range check. Memory is
bounded by the largest member code point (the whole of Unicode would cost about 136 KiB,
and the standard whitespace and dash sets are entirely or almost entirely in the Basic
Multilingual Plane, so a few kilobytes in practice).
This type carries no opinion about what the code points mean. It is the explicit,
standards-sourced data layer that CharClass and the reference tables
(UnicodeWhitespace, UnicodeDash) are built from, and that users extend or
override through fromFile(Path, String).
-
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(int codePoint) Tests membership.booleanstatic CodePointSetLoads the code points declared under one section of a user definitions file.inthashCode()booleanisEmpty()Returns whether this set is empty.static CodePointSetof(int... codePoints) Creates a set from explicit code points.static CodePointSetofRange(int firstInclusive, int lastInclusive) Creates a set covering an inclusive code point range.intsize()Returns the number of code points in this set.int[]toArray()Returns the member code points, in ascending order.union(CodePointSet other) Returns a new set containing every code point in this set orother.
-
Method Details
-
of
Creates a set from explicit code points.- Parameters:
codePoints- The code points to include.- Returns:
- The set.
- Throws:
IllegalArgumentException- Thrown if any value is not a valid Unicode code point (outside[0, U+10FFFF]).
-
ofRange
Creates a set covering an inclusive code point range.- Parameters:
firstInclusive- The first code point in the range.lastInclusive- The last code point in the range.- Returns:
- The set.
- Throws:
IllegalArgumentException- Thrown if either bound is invalid orfirstInclusiveis greater thanlastInclusive.
-
fromFile
Loads the code points declared under one section of a user definitions file.The format is line oriented and parsed with simple cursor scanning, not a regular expression: a
[name]line opens a section; a#begins a comment that runs to end of line; each remaining line is a single hex code point (U+00A0,0x00A0, or00A0) or an inclusive range (U+2000-U+200A). Section names match case insensitively. Only entries under the requested section are returned, so one file can carry, for example, both[whitespace]and[dash]sections.- Parameters:
definitions- The file to read (UTF-8).section- The section whose entries should be loaded.- Returns:
- The code points declared under
section, or an empty set if the section is absent. - Throws:
IOException- Thrown if the file cannot be read.IllegalArgumentException- Thrown if a line is malformed, naming the offending line.
-
contains
public boolean contains(int codePoint) Tests membership.- Parameters:
codePoint- The code point to test. Out-of-range values returnfalse.- Returns:
trueif the code point is in this set.
-
union
Returns a new set containing every code point in this set orother.- Parameters:
other- The set to union with.- Returns:
- The union, a new set; neither input is modified.
-
size
public int size()Returns the number of code points in this set.- Returns:
- the number of code points in this set
-
isEmpty
public boolean isEmpty()Returns whether this set is empty.- Returns:
- whether this set is empty
-
toArray
public int[] toArray()Returns the member code points, in ascending order.- Returns:
- the member code points, in ascending order
-
equals
-
hashCode
public int hashCode()
-