Package org.passay

Class UnicodeString

java.lang.Object
org.passay.UnicodeString
All Implemented Interfaces:
CharSequence

public final class UnicodeString extends Object implements CharSequence
Contains a list of character code points.
  • Field Details

    • codePoints

      private final int[] codePoints
      Stores the character code points.
    • characters

      private final char[] characters
      Stores the characters. Used to implement CharSequence API.
  • Constructor Details

    • UnicodeString

      private UnicodeString(int[] codePoints, char[] characters)
      Internal copy constructor.
      Parameters:
      codePoints - string code points
      characters - string characters
    • UnicodeString

      public UnicodeString(char... chars)
      Creates a new unicode string.
      Parameters:
      chars - characters
    • UnicodeString

      public UnicodeString(CharSequence cs)
      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:
      charAt in interface CharSequence
    • 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

      public UnicodeString toLowerCase()
      Returns a new unicode string with each character lower cased. See Character.toLowerCase(int).
      Returns:
      lower cased unicode string
    • toLowerCase

      public UnicodeString toLowerCase(boolean clear)
      Returns a new unicode string with each character lower cased. See Character.toLowerCase(int).
      Parameters:
      clear - whether to invoke clear() at the conclusion of this method
      Returns:
      lower cased unicode string
    • toUpperCase

      public UnicodeString toUpperCase()
      Returns a new unicode string with each character upper-cased. See Character.toUpperCase(int).
      Returns:
      upper cased unicode string
    • toUpperCase

      public UnicodeString toUpperCase(boolean clear)
      Returns a new unicode string with each character upper-cased. See Character.toUpperCase(int).
      Parameters:
      clear - whether to invoke clear() 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:
      length in interface CharSequence
    • subSequence

      public UnicodeString subSequence(int beginIndex, int endIndex)
      Specified by:
      subSequence in interface CharSequence
    • isEmpty

      public boolean isEmpty()
      Returns whether this unicode string has any code points.
      Returns:
      whether this unicode string has any code points
    • substring

      public UnicodeString substring(int beginIndex)
      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

      public UnicodeString 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).
      Parameters:
      beginIndex - of the code point that would be the first code point in the new unicode string
      endIndex - of the code point that would be the last code point in the new unicode string
      Returns:
      new unicode substring
    • reverse

      public UnicodeString reverse()
      Returns a new unicode string with the code points reversed.
      Returns:
      reversed unicode string
    • reverse

      public UnicodeString reverse(boolean clear)
      Returns a new unicode string with the code points reversed.
      Parameters:
      clear - whether to invoke clear() at the conclusion of this method
      Returns:
      reversed unicode string
    • intersection

      public UnicodeString intersection(UnicodeString other)
      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

      public UnicodeString union(UnicodeString other)
      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

      public UnicodeString difference(UnicodeString other)
      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

      public boolean startsWith(UnicodeString prefix)
      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

      boolean startsWith(UnicodeString prefix, int offset)
      Returns whether this unicode string starts with the supplied prefix at the supplied offset.
      Parameters:
      prefix - to compare with this unicode string
      offset - code point index at which to compare the prefix
      Returns:
      whether this unicode string starts with prefix at the offset
    • endsWith

      public boolean endsWith(UnicodeString suffix)
      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

      public boolean contains(UnicodeString other)
      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

      int indexOf(UnicodeString other)
      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

      public String toString()
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • copy

      public static UnicodeString copy(UnicodeString string)
      Creates a copy of the supplied unicode string.
      Parameters:
      string - to copy
      Returns:
      new unicode string