Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javolution.text
Class CharArray

    java.lang.Object
      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 character sequence backed up by a `char` array. Instances of this class are mutable and are typically used/reused to hold temporary text (unlike `String` they do not forces object creation).

Instances of this classes have the following properties:

- They support equality or lexical comparison with any `CharSequence` (e.g. `String`).
- They have the same hashcode than `String` and can be used to retrieve data from maps for which the keys are `String` instances.
- They support fast conversions to primitive types (e.g. `Boolean`, `int`).

Version:
  4.0, June 16, 2006
Author:
  Jean-Marie Dautelle

Constructor Summary
`CharArray()` Default constructor.
`CharArray(java.lang.CharSequence csq)` Creates a character array from the specified character sequence.
`CharArray(java.lang.String string)` Creates a character array from the specified String.

Method Summary
`char[]` | `array()` Returns the underlying array (read-only).
`char` | `charAt(int index)` Returns the character at the specified 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.
`int` | `hashCode()` Returns the hash code for this `CharArray`.
`int` | `length()` Returns the length of this character sequence.
`int` | `offset()` Returns the offset of the first character in the underlying array.
`int` | `offsetOf(char c)` Returns the offset within this character array of the first occurrence of the specified character searching forward from this character array `offset()` to `offset() + length()`.
`int` | `offsetOf(java.lang.CharSequence csq)` Returns the offset within this character array of the first occurrence of the specified characters sequence searching forward from this character array `offset()` to `offset() + length()`.
`CharArray` | `setArray(char[] array, int offset, int length)` Sets the underlying array of this CharArray.
`java.lang.CharSequence` | `subSequence(int start, int end)` Returns a new character sequence that is a subsequence of this sequence.
`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.

### CharArray

    public CharArray(java.lang.String string)

  Creates a character array from the specified String.

  Parameters:
    `string` - the string source.

### CharArray

    public CharArray(java.lang.CharSequence csq)

  Creates a character array from the specified character sequence.

  Parameters:
    `csq` - the character sequence source.

Method Detail

### array

    public char[] array()

  Returns the underlying array (read-only). The array returned should not be modified (unfortunately there is no way to make an array immutable in Java).

  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) composing this character sequence.

### 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`

### charAt

    public char charAt(int index)

  Returns the character at the specified index.

  Specified by:
    `charAt` in interface `java.lang.CharSequence`
  Parameters:
    `index` - the index of the character starting at `0`.
  Returns:
    the character at the specified index of this character sequence.
  Throws:
    `java.lang.IndexOutOfBoundsException` - if `((index < 0) || (index >= length))`

### subSequence

    public java.lang.CharSequence subSequence(int start,
                                              int end)

  Returns a new character sequence that is a subsequence of this sequence.

  Specified by:
    `subSequence` in interface `java.lang.CharSequence`
  Parameters:
    `start` - the index of the first character inclusive.
    `end` - the index of the last character exclusive.
  Returns:
    the character sequence starting at the specified `start` position and ending just before the specified `end` position.
  Throws:
    `java.lang.IndexOutOfBoundsException` - if `(start < 0) || (end < 0) || (start > end) || (end > this.length())`

### offsetOf

    public final int offsetOf(java.lang.CharSequence csq)

  Returns the offset within this character array of the first occurrence of the specified characters sequence searching forward from this character array `offset()` to `offset() + length()`.

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

### offsetOf

    public final int offsetOf(char c)

  Returns the offset within this character array of the first occurrence of the specified character searching forward from this character array `offset()` to `offset() + length()`.

  Parameters:
    `c` - the character to search for.
  Returns:
    the offset of the specified character in the range `[offset(), offset() + 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`. /

Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 - 2007 Javolution.