Record Class StringView

java.lang.Object
java.lang.Record
icyllis.modernui.util.StringView
All Implemented Interfaces:
GetChars, CharSequence, Comparable<CharSequence>

@Experimental public record StringView(String string, int offset, int length) extends Record implements Comparable<CharSequence>, CharSequence, GetChars
Special class that represents a region of a String, used for fast HashMap lookup and memory comparison.
  • Constructor Details

    • StringView

      public StringView(@NonNull String string, int offset, int length)
      Creates an instance of a StringView record class.
      Parameters:
      string - the value for the string record component
      offset - the value for the offset record component
      length - the value for the length record component
  • Method Details

    • charAt

      public char charAt(int index)
      Specified by:
      charAt in interface CharSequence
    • subSequence

      @NonNull public CharSequence subSequence(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • getChars

      public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
      Specified by:
      getChars in interface GetChars
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • toString

      @NonNull public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in interface CharSequence
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • compareTo

      public int compareTo(@NonNull CharSequence o)
      Specified by:
      compareTo in interface Comparable<CharSequence>
    • string

      @NonNull public String string()
      Returns the value of the string record component.
      Returns:
      the value of the string record component
    • offset

      public int offset()
      Returns the value of the offset record component.
      Returns:
      the value of the offset record component
    • length

      public int length()
      Returns the value of the length record component.
      Specified by:
      length in interface CharSequence
      Returns:
      the value of the length record component