org.carrot2.text.util
Class MutableCharArray

java.lang.Object
  extended by org.carrot2.text.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 Summary
MutableCharArray()
          Creates an empty MutableCharArray.
MutableCharArray(char[] buffer)
          Resets the internal buffer to use the provided argument.
MutableCharArray(char[] buffer, int start, int length)
          Resets the internal buffer to use the provided argument.
MutableCharArray(CharSequence seq)
          Creates a MutableCharArray from another CharSequence, creates a new buffer to store characters.
 
Method Summary
 char charAt(int index)
           
 MutableCharArray clone()
           
 boolean equals(Object other)
          See comments in the header of this class.
 char[] getBuffer()
           
 int getStart()
           
 int hashCode()
          See comments in the header of this class.
static int hashCode(char[] buffer, int start, int length)
          Calculates a hash code for a given portion of the character buffer.
 int length()
           
 void reset(char[] buffer)
          Resets internal buffers in this object to point to another character buffer.
 void reset(char[] buffer, int start, int length)
          Resets internal buffers in this object to point to another character buffer.
 void reset(CharSequence seq)
          Resets internal buffers in this object to represent another character sequence.
 MutableCharArray subSequence(int start, int end)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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:
reset(char[])

MutableCharArray

public MutableCharArray(char[] buffer,
                        int start,
                        int length)
Resets the internal buffer to use the provided argument.

See Also:
reset(char[])
Method Detail

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().


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:
getBuffer(), length

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)
See comments in the header of this class.

Overrides:
equals in class Object

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


Copyright (c) Dawid Weiss, Stanislaw Osinski