J avolution v5.4 (J2SE 1.6+)

javolution.text
Class CharArray

java.lang.Object
  extended by javolution.text.CharArray
All Implemented Interfaces:
java.lang.CharSequence, java.lang.Comparable

public final class CharArray
extends java.lang.Object
implements java.lang.CharSequence, java.lang.Comparable

This class represents a CharSequence backed up by a char array. Instances of this class are typically used/reused to provide CharSequence views over existing character buffers.

Instances of this classes have the following properties:

Version:
5.3, January 10, 2007
Author:
Jean-Marie Dautelle

Constructor Summary
CharArray()
          Default constructor (empty character array).
CharArray(int capacity)
          Creates a character array of specified default capacity.
CharArray(java.lang.String string)
          Creates a character array from the specified String.
 
Method Summary
 char[] array()
          Returns the underlying array.
 char charAt(int index)
           
 int compareTo(java.lang.Object seq)
          Compares this character array with the specified character sequence lexicographically.
 boolean equals(CharArray that)
          Compares this character array against the specified CharArray.
 boolean equals(java.lang.Object that)
          Compares this character sequence against the specified object (String or CharSequence).
 boolean equals(java.lang.String str)
          Compares this character array against the specified String.
 void getChars(int start, int end, char[] dest, int destPos)
           
 int hashCode()
          Returns the hash code for this CharArray.
 int indexOf(char c)
          Returns the index within this character sequence of the first occurrence of the specified character searching forward.
 int indexOf(java.lang.CharSequence csq)
          Returns the index within this character sequence of the first occurrence of the specified characters sequence searching forward.
 int length()
          Returns the length of this character sequence.
 int offset()
          Returns the offset of the first character in the underlying array.
 CharArray setArray(char[] array, int offset, int length)
          Sets the underlying array of this CharArray.
 java.lang.CharSequence subSequence(int start, int end)
           
 boolean toBoolean()
          Returns the boolean represented by this character array.
 double toDouble()
          Returns the double represented by this character array.
 float toFloat()
          Returns the float represented by this character array.
 int toInt()
          Returns the decimal int represented by this character array.
 int toInt(int radix)
          Returns the int represented by this character array in the specified radix.
 long toLong()
          Returns the decimal long represented by this character array.
 long toLong(int radix)
          Returns the decimal long represented by this character array in the specified radix.
 java.lang.String toString()
          Returns the String corresponding to this character sequence.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CharArray

public CharArray()
Default constructor (empty character array).


CharArray

public CharArray(int capacity)
Creates a character array of specified default capacity.

Parameters:
capacity - the backing array default capacity.

CharArray

public CharArray(java.lang.String string)
Creates a character array from the specified String.

Parameters:
string - the string source.
Method Detail

array

public char[] array()
Returns the underlying array.

Returns:
the underlying array.

length

public int length()
Returns the length of this character sequence.

Specified by:
length in interface java.lang.CharSequence
Returns:
the number of characters (16-bits Unicode).

offset

public int offset()
Returns the offset of the first character in the underlying array.

Returns:
the offset of the first character.

setArray

public CharArray setArray(char[] array,
                          int offset,
                          int length)
Sets the underlying array of this CharArray.

Parameters:
offset - the new offset.
array - the new underlying array.
length - the new length.
Returns:
this

indexOf

public final int indexOf(java.lang.CharSequence csq)
Returns the index within this character sequence of the first occurrence of the specified characters sequence searching forward.

Parameters:
csq - a character sequence searched for.
Returns:
the index of the specified character sequence in the range [0, length()[ or -1 if the character sequence is not found.

indexOf

public final int indexOf(char c)
Returns the index within this character sequence of the first occurrence of the specified character searching forward.

Parameters:
c - the character to search for.
Returns:
the indext of the specified character in the range [0, length()[ or -1 if the character is not found.

toString

public java.lang.String toString()
Returns the String corresponding to this character sequence. The String returned is always allocated on the heap and can safely be referenced elsewhere.

Specified by:
toString in interface java.lang.CharSequence
Overrides:
toString in class java.lang.Object
Returns:
the java.lang.String for this character sequence.

hashCode

public int hashCode()
Returns the hash code for this CharArray.

Note: Returns the same hashCode as java.lang.String (consistent with equals(java.lang.Object))

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value.

equals

public boolean equals(java.lang.Object that)
Compares this character sequence against the specified object (String or CharSequence).

Overrides:
equals in class java.lang.Object
Parameters:
that - the object to compare with.
Returns:
true if both objects represent the same sequence; false otherwise.

equals

public boolean equals(CharArray that)
Compares this character array against the specified CharArray.

Parameters:
that - the character array to compare with.
Returns:
true if both objects represent the same sequence; false otherwise.

equals

public boolean equals(java.lang.String str)
Compares this character array against the specified String. In case of equality, the CharArray keeps a reference to the String for future comparisons.

Parameters:
str - the string to compare with.
Returns:
true if both objects represent the same sequence; false otherwise.

compareTo

public int compareTo(java.lang.Object seq)
Compares this character array with the specified character sequence lexicographically.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
seq - the character sequence to be compared.
Returns:
FastComparator.LEXICAL.compare(this, seq)
Throws:
java.lang.ClassCastException - if the specifed object is not a CharSequence.

toBoolean

public boolean toBoolean()
Returns the boolean represented by this character array.

Returns:
the corresponding boolean value.
Throws:
java.lang.NumberFormatException - if this character sequence does not contain a parsable boolean.

toInt

public int toInt()
Returns the decimal int represented by this character array.

Returns:
toInt(10)
Throws:
java.lang.NumberFormatException - if this character sequence does not contain a parsable int.

toInt

public int toInt(int radix)
Returns the int represented by this character array in the specified radix.

Parameters:
radix - the radix (e.g. 16 for hexadecimal).
Returns:
the corresponding int value.
Throws:
java.lang.NumberFormatException - if this character sequence does not contain a parsable int.

toLong

public long toLong()
Returns the decimal long represented by this character array.

Returns:
the corresponding long value.
Throws:
java.lang.NumberFormatException - if this character sequence does not contain a parsable long.

toLong

public long toLong(int radix)
Returns the decimal long represented by this character array in the specified radix.

Parameters:
radix - the radix (e.g. 16 for hexadecimal).
Returns:
the corresponding long value.
Throws:
java.lang.NumberFormatException - if this character sequence does not contain a parsable long.

toFloat

public float toFloat()
Returns the float represented by this character array.

Returns:
the corresponding float value.
Throws:
java.lang.NumberFormatException - if this character sequence does not contain a parsable float.

toDouble

public double toDouble()
Returns the double represented by this character array.

Returns:
the corresponding double value.
Throws:
java.lang.NumberFormatException - if this character sequence does not contain a parsable double.

charAt

public char charAt(int index)
Specified by:
charAt in interface java.lang.CharSequence

subSequence

public java.lang.CharSequence subSequence(int start,
                                          int end)
Specified by:
subSequence in interface java.lang.CharSequence

getChars

public void getChars(int start,
                     int end,
                     char[] dest,
                     int destPos)

J avolution v5.4 (J2SE 1.6+)

Copyright © 2005 - 2009 Javolution.