Javolution 6.0.0 java
javolution.text.CharArray Class Reference
Inheritance diagram for javolution.text.CharArray:
[legend]
Collaboration diagram for javolution.text.CharArray:
[legend]

Public Member Functions

 CharArray ()
 
 CharArray (int capacity)
 
 CharArray (String string)
 
char[] array ()
 
int length ()
 
int offset ()
 
CharArray setArray (char[] array, int offset, int length)
 
final int indexOf (java.lang.CharSequence csq)
 
final int indexOf (char c)
 
String toString ()
 
int hashCode ()
 
boolean equals (Object that)
 
boolean equals (CharArray that)
 
boolean equals (String str)
 
int compareTo (CharSequence seq)
 
boolean toBoolean ()
 
int toInt ()
 
int toInt (int radix)
 
long toLong ()
 
long toLong (int radix)
 
float toFloat ()
 
double toDouble ()
 
char charAt (int index)
 
java.lang.CharSequence subSequence (int start, int end)
 
void getChars (int start, int end, char dest[], int destPos)
 

Private Member Functions

boolean equals (java.lang.CharSequence chars)
 

Private Attributes

char[] _array
 
int _offset
 
int _length
 

Static Private Attributes

static final char[] NO_CHAR = new char[0]
 

Detailed Description

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:

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

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

Definition at line 36 of file CharArray.java.

Constructor & Destructor Documentation

◆ CharArray() [1/3]

javolution.text.CharArray.CharArray ( )

Default constructor (empty character array).

Definition at line 56 of file CharArray.java.

56  {
57  _array = NO_CHAR;
58  }

References javolution.text.CharArray._array, and javolution.text.CharArray.NO_CHAR.

Referenced by javolution.text.CharArray.subSequence().

Here is the caller graph for this function:

◆ CharArray() [2/3]

javolution.text.CharArray.CharArray ( int  capacity)

Creates a character array of specified default capacity.

Parameters
capacitythe backing array default capacity.

Definition at line 67 of file CharArray.java.

67  {
68  _array = new char[capacity];
69  }

References javolution.text.CharArray._array.

◆ CharArray() [3/3]

javolution.text.CharArray.CharArray ( String  string)

Creates a character array from the specified String.

Parameters
stringthe string source.

Definition at line 76 of file CharArray.java.

76  {
77  _array = string.toCharArray();
78  _length = string.length();
79  }

References javolution.text.CharArray._array, and javolution.text.CharArray._length.

Member Function Documentation

◆ array()

char [] javolution.text.CharArray.array ( )

Returns the underlying array.

Returns
the underlying array.

Definition at line 86 of file CharArray.java.

86  {
87  return _array;
88  }

References javolution.text.CharArray._array.

Referenced by javolution.xml.internal.stream.XMLStreamReaderImpl.getTextCharacters(), javolution.xml.internal.stream.XMLStreamReaderImpl.isWhiteSpace(), javolution.xml.sax.XMLReaderImpl.parseAll(), javolution.io.CharSequenceReader.read(), javolution.xml.internal.stream.XMLStreamReaderImpl.readPrologAttribute(), javolution.text.CharArray.setArray(), and javolution.xml.internal.stream.NamespacesImpl.setPrefix().

Here is the caller graph for this function:

◆ charAt()

char javolution.text.CharArray.charAt ( int  index)

Definition at line 369 of file CharArray.java.

369  {
370  if ((index < 0) || (index >= _length))
371  throw new IndexOutOfBoundsException("index: " + index);
372  return _array[_offset + index];
373  }

References javolution.text.CharArray._array, javolution.text.CharArray._length, and javolution.text.CharArray._offset.

Referenced by javolution.xml.XMLFormat< T >.InputElement.getAttribute(), and javolution.xml.internal.stream.XMLStreamReaderImpl.isXMLNS().

Here is the caller graph for this function:

◆ compareTo()

int javolution.text.CharArray.compareTo ( CharSequence  seq)

Compares this character array with the specified character sequence lexicographically.

Parameters
seqthe character sequence to be compared.
Returns
Equalities#LEXICAL.compare(this, seq)
Exceptions
ClassCastExceptionif the specifed object is not a CharSequence.

Definition at line 281 of file CharArray.java.

281  {
282  return Equalities.LEXICAL.compare(this, seq);
283  }

References javolution.util.function.Equality< T >.compare(), and javolution.util.function.Equalities.LEXICAL.

Here is the call graph for this function:

◆ equals() [1/4]

boolean javolution.text.CharArray.equals ( CharArray  that)

Compares this character array against the specified CharArray.

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

Definition at line 236 of file CharArray.java.

236  {
237  if (this == that)
238  return true;
239  if (that == null)
240  return false;
241  if (this._length != that._length)
242  return false;
243  final char[] thatArray = that._array;
244  for (int i = that._offset + _length, j = _offset + _length; --j >= _offset;) {
245  if (_array[j] != thatArray[--i])
246  return false;
247  }
248  return true;
249  }

References javolution.text.CharArray._array, javolution.text.CharArray._length, and javolution.text.CharArray._offset.

◆ equals() [2/4]

boolean javolution.text.CharArray.equals ( java.lang.CharSequence  chars)
private

Definition at line 217 of file CharArray.java.

217  {
218  if (chars == null)
219  return false;
220  if (this._length != chars.length())
221  return false;
222  for (int i = _length, j = _offset + _length; --i >= 0;) {
223  if (_array[--j] != chars.charAt(i))
224  return false;
225  }
226  return true;
227  }

References javolution.text.CharArray._array, javolution.text.CharArray._length, and javolution.text.CharArray._offset.

◆ equals() [3/4]

boolean javolution.text.CharArray.equals ( Object  that)

Compares this character sequence against the specified object (String or CharSequence).

Parameters
thatthe object to compare with.
Returns
true if both objects represent the same sequence; false otherwise.

Definition at line 204 of file CharArray.java.

204  {
205  if (that instanceof String) {
206  return equals((String) that);
207  } else if (that instanceof CharArray) {
208  return equals((CharArray) that);
209  } else if (that instanceof java.lang.CharSequence) {
210  return equals((java.lang.CharSequence) that);
211  } else {
212  return false;
213  }
214  }

Referenced by javolution.xml.XMLFormat< T >.InputElement.get(), javolution.xml.XMLFormat< T >.InputElement.getNext(), javolution.xml.internal.stream.NamespacesImpl.getPrefix(), javolution.xml.internal.stream.XMLStreamWriterImpl.getRepairedPrefix(), javolution.xml.ws.WebServiceClient.invoke(), javolution.xml.internal.stream.XMLStreamReaderImpl.isStandalone(), javolution.xml.internal.stream.XMLStreamReaderImpl.processEndTag(), javolution.xml.ws.WebServiceClient.readResponse(), javolution.xml.internal.stream.XMLStreamReaderImpl.setInput(), javolution.xml.internal.stream.XMLStreamWriterImpl.writeAttributeOrNamespace(), javolution.xml.internal.stream.XMLStreamWriterImpl.writeNamespace(), javolution.xml.internal.stream.XMLStreamWriterImpl.writeNamespaces(), and javolution.xml.internal.stream.XMLStreamWriterImpl.writeNewElement().

Here is the caller graph for this function:

◆ equals() [4/4]

boolean javolution.text.CharArray.equals ( 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
strthe string to compare with.
Returns
true if both objects represent the same sequence; false otherwise.

Definition at line 260 of file CharArray.java.

260  {
261  if (str == null)
262  return false;
263  if (_length != str.length())
264  return false;
265  for (int i = _length, j = _offset + _length; --i >= 0;) {
266  if (_array[--j] != str.charAt(i))
267  return false;
268  }
269  return true;
270  }

References javolution.text.CharArray._array, javolution.text.CharArray._length, and javolution.text.CharArray._offset.

◆ getChars()

void javolution.text.CharArray.getChars ( int  start,
int  end,
char  dest[],
int  destPos 
)

Definition at line 387 of file CharArray.java.

387  {
388  if ((start < 0) || (end < 0) || (start > end) || (end > _length))
389  throw new IndexOutOfBoundsException();
390  System.arraycopy(_array, start + _offset, dest, destPos, end - start);
391  }

References javolution.text.CharArray._array, javolution.text.CharArray._length, and javolution.text.CharArray._offset.

◆ hashCode()

int javolution.text.CharArray.hashCode ( )

Returns the hash code for this CharArray.

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

Returns
the hash code value.

Definition at line 187 of file CharArray.java.

187  {
188  int h = 0;
189  for (int i = 0, j = _offset; i < _length; i++) {
190  h = 31 * h + _array[j++];
191  }
192  return h;
193  }

References javolution.text.CharArray._array, javolution.text.CharArray._length, and javolution.text.CharArray._offset.

◆ indexOf() [1/2]

final int javolution.text.CharArray.indexOf ( char  c)

Returns the index within this character sequence of the first occurrence of the specified character searching forward.

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

Definition at line 159 of file CharArray.java.

159  {
160  for (int i = _offset, end = _offset + _length; i < end; i++) {
161  if (_array[i] == c)
162  return i - _offset;
163  }
164  return -1;
165  }

References javolution.text.CharArray._array, javolution.text.CharArray._length, and javolution.text.CharArray._offset.

◆ indexOf() [2/2]

final int javolution.text.CharArray.indexOf ( java.lang.CharSequence  csq)

Returns the index within this character sequence of the first occurrence of the specified characters sequence searching forward.

Parameters
csqa 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.

Definition at line 132 of file CharArray.java.

132  {
133  final char c = csq.charAt(0);
134  final int csqLength = csq.length();
135  for (int i = _offset, end = _offset + _length - csqLength + 1; i < end; i++) {
136  if (_array[i] == c) { // Potential match.
137  boolean match = true;
138  for (int j = 1; j < csqLength; j++) {
139  if (_array[i + j] != csq.charAt(j)) {
140  match = false;
141  break;
142  }
143  }
144  if (match) { return i - _offset; }
145  }
146  }
147  return -1;
148  }

References javolution.text.CharArray._array, javolution.text.CharArray._length, and javolution.text.CharArray._offset.

Referenced by javolution.xml.internal.stream.XMLStreamReaderImpl.getPIData(), javolution.xml.internal.stream.XMLStreamReaderImpl.getPITarget(), and javolution.xml.internal.stream.XMLStreamReaderImpl.readPrologAttribute().

Here is the caller graph for this function:

◆ length()

int javolution.text.CharArray.length ( )

Returns the length of this character sequence.

Returns
the number of characters (16-bits Unicode).

Definition at line 95 of file CharArray.java.

95  {
96  return _length;
97  }

References javolution.text.CharArray._length.

Referenced by javolution.xml.XMLFormat< T >.InputElement.getAttribute(), javolution.xml.internal.stream.XMLStreamReaderImpl.getElementText(), javolution.xml.internal.stream.XMLStreamReaderImpl.getLocalName(), javolution.xml.internal.stream.XMLStreamReaderImpl.getPIData(), javolution.xml.internal.stream.XMLStreamReaderImpl.getTextCharacters(), javolution.xml.internal.stream.XMLStreamReaderImpl.getTextLength(), javolution.xml.internal.stream.XMLStreamReaderImpl.hasText(), javolution.xml.internal.stream.XMLStreamReaderImpl.increaseStack(), javolution.xml.internal.stream.XMLStreamReaderImpl.isEndOfStream(), javolution.xml.internal.stream.XMLStreamReaderImpl.isWhiteSpace(), javolution.xml.internal.stream.XMLStreamReaderImpl.isXMLNS(), javolution.xml.internal.stream.XMLStreamReaderImpl.next(), javolution.xml.sax.XMLReaderImpl.parseAll(), javolution.xml.internal.stream.XMLStreamReaderImpl.processAttribute(), javolution.xml.internal.stream.XMLStreamReaderImpl.processStartTag(), javolution.xml.internal.stream.XMLStreamReaderImpl.readPrologAttribute(), javolution.xml.internal.stream.NamespacesImpl.resizePrefixStack(), javolution.text.CharArray.setArray(), javolution.xml.internal.stream.XMLStreamReaderImpl.setInput(), javolution.xml.internal.stream.NamespacesImpl.setPrefix(), javolution.text.CharArray.subSequence(), and javolution.xml.internal.stream.XMLStreamWriterImpl.writeNamespaces().

Here is the caller graph for this function:

◆ offset()

◆ setArray()

CharArray javolution.text.CharArray.setArray ( char[]  array,
int  offset,
int  length 
)

Sets the underlying array of this CharArray.

Parameters
offsetthe new offset.
arraythe new underlying array.
lengththe new length.
Returns
this

Definition at line 116 of file CharArray.java.

116  {
117  _array = array;
118  _offset = offset;
119  _length = length;
120  return this;
121  }

References javolution.text.CharArray._array, javolution.text.CharArray._length, javolution.text.CharArray._offset, javolution.text.CharArray.array(), javolution.text.CharArray.length(), and javolution.text.CharArray.offset().

Referenced by javolution.xml.internal.stream.XMLStreamReaderImpl.getElementText(), javolution.xml.internal.stream.XMLStreamReaderImpl.isEndOfStream(), javolution.xml.internal.stream.XMLStreamReaderImpl.newSeq(), javolution.xml.internal.stream.XMLStreamReaderImpl.next(), javolution.xml.internal.stream.EntitiesImpl.replaceEntity(), javolution.xml.internal.stream.NamespacesImpl.setPrefix(), javolution.text.TextBuilder.toCharArray(), and javolution.xml.internal.stream.XMLStreamWriterImpl.writeCharacters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subSequence()

java.lang.CharSequence javolution.text.CharArray.subSequence ( int  start,
int  end 
)

Definition at line 376 of file CharArray.java.

376  {
377  if ((start < 0) || (end < 0) || (start > end) || (end > this.length()))
378  throw new IndexOutOfBoundsException();
379  CharArray chars = new CharArray();
380  chars._array = _array;
381  chars._offset = _offset + start;
382  chars._length = end - start;
383  return chars;
384  }

References javolution.text.CharArray._array, javolution.text.CharArray._length, javolution.text.CharArray._offset, javolution.text.CharArray.CharArray(), and javolution.text.CharArray.length().

Here is the call graph for this function:

◆ toBoolean()

boolean javolution.text.CharArray.toBoolean ( )

Returns the boolean represented by this character array.

Returns
the corresponding boolean value.
Exceptions
NumberFormatExceptionif this character sequence does not contain a parsable boolean.

Definition at line 292 of file CharArray.java.

292  {
293  return TypeFormat.parseBoolean(this);
294  }

References javolution.text.TypeFormat.parseBoolean().

Referenced by javolution.xml.XMLFormat< T >.InputElement.getAttribute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toDouble()

double javolution.text.CharArray.toDouble ( )

Returns the double represented by this character array.

Returns
the corresponding double value.
Exceptions
NumberFormatExceptionif this character sequence does not contain a parsable double.

Definition at line 364 of file CharArray.java.

364  {
365  return TypeFormat.parseDouble(this);
366  }

References javolution.text.TypeFormat.parseDouble().

Referenced by javolution.xml.XMLFormat< T >.InputElement.getAttribute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toFloat()

float javolution.text.CharArray.toFloat ( )

Returns the float represented by this character array.

Returns
the corresponding float value.
TypeFormat.parseFloat(this)
Exceptions
NumberFormatExceptionif this character sequence does not contain a parsable float.

Definition at line 353 of file CharArray.java.

353  {
354  return TypeFormat.parseFloat(this);
355  }

References javolution.text.TypeFormat.parseFloat().

Referenced by javolution.xml.XMLFormat< T >.InputElement.getAttribute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toInt() [1/2]

int javolution.text.CharArray.toInt ( )

Returns the decimal int represented by this character array.

Returns
toInt(10)
Exceptions
NumberFormatExceptionif this character sequence does not contain a parsable int.

Definition at line 303 of file CharArray.java.

303  {
304  return TypeFormat.parseInt(this);
305  }

References javolution.text.TypeFormat.parseInt().

Referenced by javolution.xml.XMLReferenceResolver.createReference(), javolution.xml.XMLFormat< T >.InputElement.getAttribute(), and javolution.xml.XMLReferenceResolver.readReference().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toInt() [2/2]

int javolution.text.CharArray.toInt ( int  radix)

Returns the int represented by this character array in the specified radix.

Parameters
radixthe radix (e.g. 16 for hexadecimal).
Returns
the corresponding int value.
Exceptions
NumberFormatExceptionif this character sequence does not contain a parsable int.

Definition at line 316 of file CharArray.java.

316  {
317  return TypeFormat.parseInt(this, radix);
318  }

References javolution.text.TypeFormat.parseInt().

Here is the call graph for this function:

◆ toLong() [1/2]

long javolution.text.CharArray.toLong ( )

Returns the decimal long represented by this character array.

Returns
the corresponding long value.
Exceptions
NumberFormatExceptionif this character sequence does not contain a parsable long.

Definition at line 328 of file CharArray.java.

328  {
329  return TypeFormat.parseLong(this);
330  }

References javolution.text.TypeFormat.parseLong().

Referenced by javolution.xml.XMLFormat< T >.InputElement.getAttribute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toLong() [2/2]

long javolution.text.CharArray.toLong ( int  radix)

Returns the decimal long represented by this character array in the specified radix.

Parameters
radixthe radix (e.g. 16 for hexadecimal).
Returns
the corresponding long value.
Exceptions
NumberFormatExceptionif this character sequence does not contain a parsable long.

Definition at line 341 of file CharArray.java.

341  {
342  return TypeFormat.parseLong(this, radix);
343  }

References javolution.text.TypeFormat.parseLong().

Here is the call graph for this function:

◆ toString()

String javolution.text.CharArray.toString ( )

Returns the String corresponding to this character sequence. The String returned is always allocated on the heap and can safely be referenced elsewhere.

Returns
the java.lang.String for this character sequence.

Definition at line 175 of file CharArray.java.

175  {
176  return new String(_array, _offset, _length);
177  }

References javolution.text.CharArray._array, javolution.text.CharArray._length, and javolution.text.CharArray._offset.

Referenced by javolution.xml.XMLFormat< T >.InputElement.getAttribute(), javolution.xml.sax.SAX2ReaderImpl.Proxy.getType(), and javolution.xml.internal.stream.XMLStreamReaderImpl.setInput().

Here is the caller graph for this function:

Member Data Documentation

◆ _array

◆ _length

◆ _offset

◆ NO_CHAR

final char [] javolution.text.CharArray.NO_CHAR = new char[0]
staticprivate

Definition at line 60 of file CharArray.java.

Referenced by javolution.text.CharArray.CharArray().


The documentation for this class was generated from the following file:
javolution.text.CharArray.equals
boolean equals(Object that)
Definition: CharArray.java:204
javolution.text.CharArray.CharArray
CharArray()
Definition: CharArray.java:56
javolution.text.CharArray.offset
int offset()
Definition: CharArray.java:104
javolution.text.CharArray._array
char[] _array
Definition: CharArray.java:41
javolution.text.CharArray.length
int length()
Definition: CharArray.java:95
javolution.text.CharArray.NO_CHAR
static final char[] NO_CHAR
Definition: CharArray.java:60
javolution.text.CharArray.array
char[] array()
Definition: CharArray.java:86
javolution.text.CharArray._offset
int _offset
Definition: CharArray.java:46
javolution.text.CharArray._length
int _length
Definition: CharArray.java:51