CharsRef (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.util, class: CharsRef

Package org.apache.lucene.util

# Class CharsRef

java.lang.Object
org.apache.lucene.util.CharsRef

All Implemented Interfaces:
  `CharSequence`, `Cloneable`, `Comparable<CharsRef>`

public final class CharsRef extends Object implements Comparable<CharsRef>, CharSequence, Cloneable
Represents char[], as a slice (offset + length) into an existing char[]. The `chars` member should never be null; use `EMPTY_CHARS` if necessary.

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `char[]`
  `chars`
  The contents of the CharsRef.
  `static final char[]`
  `EMPTY_CHARS`
  An empty character array for convenience
  `int`
  `length`
  Length of used characters.
  `int`
  `offset`
  Offset of first valid character.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CharsRef()`
  Creates a new `CharsRef` initialized an empty array zero-length
  `CharsRef(char[] chars, int offset, int length)`
  Creates a new `CharsRef` initialized with the given array, offset and length
  `CharsRef(int capacity)`
  Creates a new `CharsRef` initialized with an array of the given capacity
  `CharsRef(String string)`
  Creates a new `CharsRef` initialized with the given Strings character array

- ## Method Summary

  Modifier and Type
  Method
  Description
  `char`
  `charAt(int index)`
  `boolean`
  `charsEquals(CharsRef other)`
  `CharsRef`
  `clone()`
  Returns a shallow clone of this instance (the underlying characters are not copied and will be shared by both the returned object and this object.
  `int`
  `compareTo(CharsRef other)`
  Signed int order comparison
  `static CharsRef`
  `deepCopyOf(CharsRef other)`
  Creates a new CharsRef that points to a copy of the chars from `other`
  `boolean`
  `equals(Object other)`
  `static Comparator<CharsRef>`
  `getUTF16SortedAsUTF8Comparator()`
  Deprecated.
  This comparator is only a transition mechanism
  `int`
  `hashCode()`
  `boolean`
  `isValid()`
  Performs internal consistency checks.
  `int`
  `length()`
  `static int`
  `stringHashCode(char[] chars, int offset, int length)`
  `CharSequence`
  `subSequence(int start, int end)`
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface java.lang.CharSequence

  `chars, codePoints, isEmpty`

- ## Field Details

  - ### EMPTY_CHARS

    public static final char[] EMPTY_CHARS
    An empty character array for convenience

  - ### chars

    public char[] chars
    The contents of the CharsRef. Should never be `null`.

  - ### offset

    public int offset
    Offset of first valid character.

  - ### length

    public int length
    Length of used characters.

- ## Constructor Details

  - ### CharsRef

    public CharsRef()
    Creates a new `CharsRef` initialized an empty array zero-length

  - ### CharsRef

    public CharsRef(int capacity)
    Creates a new `CharsRef` initialized with an array of the given capacity

  - ### CharsRef

    public CharsRef(char[] chars, int offset, int length)
    Creates a new `CharsRef` initialized with the given array, offset and length

  - ### CharsRef

    public CharsRef(String string)
    Creates a new `CharsRef` initialized with the given Strings character array

- ## Method Details

  - ### clone

    public CharsRef clone()
    Returns a shallow clone of this instance (the underlying characters are not copied and will be shared by both the returned object and this object.
    Overrides:
      `clone` in class `Object`
    See Also:
      - `deepCopyOf(org.apache.lucene.util.CharsRef)`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### stringHashCode

    public static int stringHashCode(char[] chars, int offset, int length)
    Returns:
      the hash code of the given char sub-array, calculated by `String.hashCode()` specification

  - ### equals

    public boolean equals(Object other)
    Overrides:
      `equals` in class `Object`

  - ### charsEquals

    public boolean charsEquals(CharsRef other)

  - ### compareTo

    public int compareTo(CharsRef other)
    Signed int order comparison
    Specified by:
      `compareTo` in interface `Comparable<CharsRef>`

  - ### toString

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

  - ### length

    public int length()
    Specified by:
      `length` in interface `CharSequence`

  - ### charAt

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

  - ### subSequence

    public CharSequence subSequence(int start, int end)
    Specified by:
      `subSequence` in interface `CharSequence`

  - ### getUTF16SortedAsUTF8Comparator

    @Deprecated public static Comparator<CharsRef> getUTF16SortedAsUTF8Comparator()
    Deprecated.
    This comparator is only a transition mechanism

  - ### deepCopyOf

    public static CharsRef deepCopyOf(CharsRef other)
    Creates a new CharsRef that points to a copy of the chars from `other`

    The returned CharsRef will have a length of other.length and an offset of zero.

  - ### isValid

    public boolean isValid()
    Performs internal consistency checks. Always returns true (or throws IllegalStateException)