Package org.passay
Class UnicodeString
java.lang.Object
org.passay.UnicodeString
- All Implemented Interfaces:
CharSequence
Contains a list of character code points.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final char[]Stores the characters.private final int[]Stores the character code points. -
Constructor Summary
ConstructorsModifierConstructorDescriptionUnicodeString(char... chars) Creates a new unicode string.UnicodeString(int... codePoints) Creates a new unicode string.privateUnicodeString(int[] codePoints, char[] characters) Internal copy constructor.Creates a new unicode string. -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) voidclear()Writes zeros to the underlying code points array.intcodePointAt(int index) Returns the code point at the supplied index.intReturns the number of code points.booleancontains(UnicodeString other) Returns whether this unicode string contains the supplied string.static UnicodeStringcopy(UnicodeString string) Creates a copy of the supplied unicode string.intcountMatchingCodePoints(int[] input) Returns the number of code points in the supplied input that exist in this unicode string.difference(UnicodeString other) Returns the difference of this string and the other string.booleanendsWith(UnicodeString suffix) Returns whether this unicode string ends with the supplied suffix.booleaninthashCode()private intindexOf(int codePoint) Returns the array index of the supplied code point in this code points array.(package private) intindexOf(UnicodeString other) Returns code point index in this unicode string of the supplied string.intersection(UnicodeString other) Returns the intersection of this string and the other string.booleanisEmpty()Returns whether this unicode string has any code points.intlength()reverse()Returns a new unicode string with the code points reversed.reverse(boolean clear) Returns a new unicode string with the code points reversed.booleanstartsWith(UnicodeString prefix) Returns whether this unicode string starts with the supplied prefix.(package private) booleanstartsWith(UnicodeString prefix, int offset) Returns whether this unicode string starts with the supplied prefix at the supplied offset.subSequence(int beginIndex, int endIndex) substring(int beginIndex) Returns a new unicode string containing code points from the supplied begin index.substring(int beginIndex, int endIndex) Returns a new unicode string containing code points from the supplied begin index (inclusive) to the supplied end index (exclusive).char[]Returns the array of characters in this unicode string.int[]Returns the array of code points in this unicode string.Returns a new unicode string with each character lower cased.toLowerCase(boolean clear) Returns a new unicode string with each character lower cased.toString()Returns a new unicode string with each character upper-cased.toUpperCase(boolean clear) Returns a new unicode string with each character upper-cased.union(UnicodeString other) Returns the union of this string and the other string.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints
-
Field Details
-
codePoints
private final int[] codePointsStores the character code points. -
characters
private final char[] charactersStores the characters. Used to implement CharSequence API.
-
-
Constructor Details
-
UnicodeString
private UnicodeString(int[] codePoints, char[] characters) Internal copy constructor.- Parameters:
codePoints- string code pointscharacters- string characters
-
UnicodeString
public UnicodeString(char... chars) Creates a new unicode string.- Parameters:
chars- characters
-
UnicodeString
Creates a new unicode string.- Parameters:
cs- character sequence
-
UnicodeString
public UnicodeString(int... codePoints) Creates a new unicode string.- Parameters:
codePoints- character code points
-
-
Method Details
-
codePointAt
public int codePointAt(int index) Returns the code point at the supplied index.- Parameters:
index- of the code point- Returns:
- code point
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
toCodePointArray
public int[] toCodePointArray()Returns the array of code points in this unicode string.- Returns:
- code points array
-
toCharArray
public char[] toCharArray()Returns the array of characters in this unicode string.- Returns:
- character array
-
toLowerCase
Returns a new unicode string with each character lower cased. SeeCharacter.toLowerCase(int).- Returns:
- lower cased unicode string
-
toLowerCase
Returns a new unicode string with each character lower cased. SeeCharacter.toLowerCase(int).- Parameters:
clear- whether to invokeclear()at the conclusion of this method- Returns:
- lower cased unicode string
-
toUpperCase
Returns a new unicode string with each character upper-cased. SeeCharacter.toUpperCase(int).- Returns:
- upper cased unicode string
-
toUpperCase
Returns a new unicode string with each character upper-cased. SeeCharacter.toUpperCase(int).- Parameters:
clear- whether to invokeclear()at the conclusion of this method- Returns:
- upper cased unicode string
-
codePointCount
public int codePointCount()Returns the number of code points.- Returns:
- number of code points
-
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
isEmpty
public boolean isEmpty()Returns whether this unicode string has any code points.- Returns:
- whether this unicode string has any code points
-
substring
Returns a new unicode string containing code points from the supplied begin index.- Parameters:
beginIndex- of the code point that would be the first code point in the new unicode string- Returns:
- new unicode substring
-
substring
Returns a new unicode string containing code points from the supplied begin index (inclusive) to the supplied end index (exclusive).- Parameters:
beginIndex- of the code point that would be the first code point in the new unicode stringendIndex- of the code point that would be the last code point in the new unicode string- Returns:
- new unicode substring
-
reverse
Returns a new unicode string with the code points reversed.- Returns:
- reversed unicode string
-
reverse
Returns a new unicode string with the code points reversed.- Parameters:
clear- whether to invokeclear()at the conclusion of this method- Returns:
- reversed unicode string
-
intersection
Returns the intersection of this string and the other string. Intersection is defined as the unique set of code points that both strings have in common.- Parameters:
other- string to intersect- Returns:
- new unicode string
-
union
Returns the union of this string and the other string. Union is defined as the unique set of code points in either string.- Parameters:
other- string to intersect- Returns:
- new unicode string
-
difference
Returns the difference of this string and the other string. Difference is defined as the unique set of code points that are in this string but not in the other string.- Parameters:
other- string to difference- Returns:
- new unicode string
-
indexOf
private int indexOf(int codePoint) Returns the array index of the supplied code point in this code points array.- Parameters:
codePoint- to search for- Returns:
- array index
-
clear
public void clear()Writes zeros to the underlying code points array. -
countMatchingCodePoints
public int countMatchingCodePoints(int[] input) Returns the number of code points in the supplied input that exist in this unicode string.- Parameters:
input- code points to match- Returns:
- code point count
-
startsWith
Returns whether this unicode string starts with the supplied prefix.- Parameters:
prefix- to compare with this unicode string- Returns:
- whether this unicode string starts with prefix
-
startsWith
Returns whether this unicode string starts with the supplied prefix at the supplied offset.- Parameters:
prefix- to compare with this unicode stringoffset- code point index at which to compare the prefix- Returns:
- whether this unicode string starts with prefix at the offset
-
endsWith
Returns whether this unicode string ends with the supplied suffix.- Parameters:
suffix- to compare with this unicode string- Returns:
- whether this unicode string ends with suffix
-
contains
Returns whether this unicode string contains the supplied string.- Parameters:
other- to compare with this unicode string- Returns:
- whether this unicode string contains other
-
indexOf
Returns code point index in this unicode string of the supplied string.- Parameters:
other- to search this unicode string- Returns:
- the code point index of other in this unicode string
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
equals
-
hashCode
public int hashCode() -
copy
Creates a copy of the supplied unicode string.- Parameters:
string- to copy- Returns:
- new unicode string
-