Class MutableCharArray

java.lang.Object
org.carrot2.util.MutableCharArray
All Implemented Interfaces:
CharSequence, Cloneable

public final class MutableCharArray extends Object implements CharSequence, Cloneable
Implements CharSequence over a mutable char[] buffer.

This class implements proper content-based hashCode() and equals(Object) against other MutableCharArray objects, assuming the underlying character buffers does not change. In case the buffers is changed, the resulting behavior is unpredictable.

  • Constructor Details

    • MutableCharArray

      public MutableCharArray()
      Creates an empty MutableCharArray.
    • MutableCharArray

      public MutableCharArray(CharSequence seq)
      Creates a MutableCharArray from another CharSequence, creates a new buffer to store characters.
    • MutableCharArray

      public MutableCharArray(char[] buffer)
      Resets the internal buffer to use the provided argument.
      See Also:
    • MutableCharArray

      public MutableCharArray(char[] buffer, int start, int length)
      Resets the internal buffer to use the provided argument.
      See Also:
  • Method Details

    • reset

      public void reset(CharSequence seq)
      Resets internal buffers in this object to represent another character sequence. See class header notes for side-effects on equals(Object) and hashCode().
    • reset

      public void reset(char[] buffer)
      Resets internal buffers in this object to point to another character buffer. See class header notes for side-effects on equals(Object) and hashCode().
    • reset

      public void reset(char[] buffer, int start, int length)
      Resets internal buffers in this object to point to another character buffer. See class header notes for side-effects on equals(Object) and hashCode().
    • reset

      public void reset()
      Resets internal buffers to an empty string.
    • getBuffer

      public char[] getBuffer()
      Returns:
      Returns the internal buffer currently used to store the content of this char sequence.
    • getStart

      public int getStart()
      Returns:
      the offset at which the data currently starts in the buffer.
      See Also:
    • charAt

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

      public int length()
      Specified by:
      length in interface CharSequence
    • subSequence

      public MutableCharArray subSequence(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • toString

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

      public int hashCode()
      See comments in the header of this class.
      Overrides:
      hashCode in class Object
    • equals

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

      public final boolean equals(MutableCharArray other)
    • hashCode

      public static final int hashCode(char[] buffer, int start, int length)
      Calculates a hash code for a given portion of the character buffer. The returned value is identical to what be returned from hashCode() if a wrapper MutableCharArray were created.
    • clone

      public MutableCharArray clone()
      Overrides:
      clone in class Object
    • toArray

      public char[] toArray()