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

Public Member Functions

 TextBuilder ()
 
 TextBuilder (String str)
 
 TextBuilder (int capacity)
 
final int length ()
 
final char charAt (int index)
 
final void getChars (int srcBegin, int srcEnd, char[] dst, int dstBegin)
 
final void setCharAt (int index, char c)
 
final void setLength (int newLength)
 
final void setLength (int newLength, char fillChar)
 
final java.lang.CharSequence subSequence (int start, int end)
 
final TextBuilder append (char c)
 
final TextBuilder append (Object obj)
 
final TextBuilder append (CharSequence csq)
 
final TextBuilder append (CharSequence csq, int start, int end)
 
final TextBuilder append (String str)
 
final TextBuilder append (String str, int start, int end)
 
final TextBuilder append (Text txt)
 
final TextBuilder append (Text txt, int start, int end)
 
final TextBuilder append (char chars[])
 
final TextBuilder append (char chars[], int offset, int length)
 
final TextBuilder append (boolean b)
 
final TextBuilder append (int i)
 
final TextBuilder append (int i, int radix)
 
final TextBuilder append (long l)
 
final TextBuilder append (long l, int radix)
 
final TextBuilder append (float f)
 
final TextBuilder append (double d)
 
final TextBuilder append (double d, int digits, boolean scientific, boolean showZero)
 
final TextBuilder insert (int index, java.lang.CharSequence csq)
 
final TextBuilder clear ()
 
final TextBuilder delete (int start, int end)
 
final TextBuilder reverse ()
 
final Text toText ()
 
final String toString ()
 
final CharArray toCharArray ()
 
final int hashCode ()
 
final boolean equals (Object obj)
 
final boolean contentEquals (java.lang.CharSequence csq)
 

Private Member Functions

void appendPositive (int l1, int radix)
 
void appendPositive (long l1, int radix)
 
void appendFraction (long l, int digits, boolean showZero)
 
String toLargeString ()
 
void increaseCapacity ()
 

Private Attributes

char[] _low = new char[C0]
 
char[][] _high = new char[1][]
 
int _length
 
int _capacity = C0
 

Static Private Attributes

static final long serialVersionUID = 0x600L
 
static final int B0 = 5
 
static final int C0 = 1 << B0
 
static final int B1 = 10
 
static final int C1 = 1 << B1
 
static final int M1 = C1 - 1
 
static final char[] DIGIT_TO_CHAR
 
static final long[] POW10_LONG
 

Detailed Description

An Appendable text whose capacity expands gently without incurring expensive resize/copy operations ever.

This class is not intended for large documents manipulations which should be performed with the Text class directly (O(Log(n)) insertion and deletion capabilities).

The textual format of any appended object is retrieved from the current TextContext.

Author
Jean-Marie Dautelle
Version
5.3, January 20, 2008

Definition at line 29 of file TextBuilder.java.

Constructor & Destructor Documentation

◆ TextBuilder() [1/3]

javolution.text.TextBuilder.TextBuilder ( )

Creates a text builder of small initial capacity.

Definition at line 57 of file TextBuilder.java.

57  {
58  _high[0] = _low;
59  }

References javolution.text.TextBuilder._high, and javolution.text.TextBuilder._low.

Referenced by javolution.text.TextBuilder.equals().

Here is the caller graph for this function:

◆ TextBuilder() [2/3]

javolution.text.TextBuilder.TextBuilder ( String  str)

Creates a text builder holding the specified String (convenience method).

Parameters
strthe initial string content of this text builder.

Definition at line 67 of file TextBuilder.java.

67  {
68  this();
69  append(str);
70  }

References javolution.text.TextBuilder.append().

Here is the call graph for this function:

◆ TextBuilder() [3/3]

javolution.text.TextBuilder.TextBuilder ( int  capacity)

Creates a text builder of specified initial capacity. Unless the text length exceeds the specified capacity, operations on this text builder will not allocate memory.

Parameters
capacitythe initial capacity.

Definition at line 79 of file TextBuilder.java.

79  {
80  this();
81  while (capacity > _capacity) {
83  }
84  }

References javolution.text.TextBuilder._capacity, and javolution.text.TextBuilder.increaseCapacity().

Here is the call graph for this function:

Member Function Documentation

◆ append() [1/18]

final TextBuilder javolution.text.TextBuilder.append ( boolean  b)

Appends the textual representation of the specified boolean argument.

Parameters
bthe boolean to format.
Returns
this
See also
TypeFormat

Definition at line 396 of file TextBuilder.java.

396  {
397  return b ? append("true") : append("false");
398  }

References javolution.text.TextBuilder.append().

Here is the call graph for this function:

◆ append() [2/18]

final TextBuilder javolution.text.TextBuilder.append ( char  c)

Appends the specified character.

Parameters
cthe character to append.
Returns
this

Definition at line 202 of file TextBuilder.java.

202  {
203  if (_length >= _capacity)
205  _high[_length >> B1][_length & M1] = c;
206  _length++;
207  return this;
208  }

References javolution.text.TextBuilder._capacity, javolution.text.TextBuilder._high, javolution.text.TextBuilder._length, javolution.text.TextBuilder.B1, javolution.text.TextBuilder.increaseCapacity(), and javolution.text.TextBuilder.M1.

Referenced by javolution.text.TextBuilder.append(), javolution.text.TextBuilder.appendFraction(), javolution.text.TextBuilder.appendPositive(), javolution.text.TypeFormat.format(), javolution.io.Struct.UTF8String.get(), javolution.xml.internal.stream.XMLStreamWriterImpl.getRepairedPrefix(), javolution.context.internal.LogContextImpl.log(), javolution.test.Perfometer< T >.print(), javolution.xml.XMLFormat< T >.OutputElement.setAttribute(), javolution.text.TextBuilder.setLength(), javolution.text.TextBuilder.TextBuilder(), javolution.text.CharSet.toString(), javolution.io.Struct.toString(), javolution.xml.QName.valueOf(), javolution.text.Text.valueOf(), javolution.xml.internal.stream.XMLStreamWriterImpl.writeNewElement(), and javolution.xml.XMLReferenceResolver.writeReference().

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

◆ append() [3/18]

final TextBuilder javolution.text.TextBuilder.append ( char  chars[])

Appends the characters from the char array argument.

Parameters
charsthe character array source.
Returns
this

Definition at line 353 of file TextBuilder.java.

353  {
354  append(chars, 0, chars.length);
355  return this;
356  }

References javolution.text.TextBuilder.append().

Here is the call graph for this function:

◆ append() [4/18]

final TextBuilder javolution.text.TextBuilder.append ( char  chars[],
int  offset,
int  length 
)

Appends the characters from a subarray of the char array argument.

Parameters
charsthe character array source.
offsetthe index of the first character to append.
lengththe number of character to append.
Returns
this
Exceptions
IndexOutOfBoundsExceptionif (offset < 0) || (length < 0) || ((offset + length) > chars.length)

Definition at line 368 of file TextBuilder.java.

368  {
369  final int end = offset + length;
370  if ((offset < 0) || (length < 0) || (end > chars.length))
371  throw new IndexOutOfBoundsException();
372  int newLength = _length + length;
373  while (_capacity < newLength) {
375  }
376  for (int i = offset, j = _length; i < end;) {
377  char[] dstChars = _high[j >> B1];
378  int dstBegin = j & M1;
379  int inc = MathLib.min(C1 - dstBegin, end - i);
380  System.arraycopy(chars, i, dstChars, dstBegin, inc);
381  i += inc;
382  j += inc;
383  }
384  _length = newLength;
385  return this;
386  }

References javolution.text.TextBuilder._capacity, javolution.text.TextBuilder._high, javolution.text.TextBuilder._length, javolution.text.TextBuilder.B1, javolution.text.TextBuilder.C1, javolution.text.TextBuilder.increaseCapacity(), javolution.text.TextBuilder.length(), javolution.text.TextBuilder.M1, and javolution.lang.MathLib.min().

Here is the call graph for this function:

◆ append() [5/18]

final TextBuilder javolution.text.TextBuilder.append ( CharSequence  csq)

Appends the specified character sequence. If the specified character sequence is null this method is equivalent to append("null").

Parameters
csqthe character sequence to append or null.
Returns
this

Definition at line 230 of file TextBuilder.java.

230  {
231  return (csq == null) ? append("null") : append(csq, 0, csq.length());
232  }

References javolution.text.TextBuilder.append().

Here is the call graph for this function:

◆ append() [6/18]

final TextBuilder javolution.text.TextBuilder.append ( CharSequence  csq,
int  start,
int  end 
)

Appends a subsequence of the specified character sequence. If the specified character sequence is null this method is equivalent to append("null").

Parameters
csqthe character sequence to append or null.
startthe index of the first character to append.
endthe index after the last character to append.
Returns
this
Exceptions
IndexOutOfBoundsExceptionif (start < 0) || (end < 0) || (start > end) || (end > csq.length())

Definition at line 246 of file TextBuilder.java.

247  {
248  if (csq == null)
249  return append("null");
250  if ((start < 0) || (end < 0) || (start > end) || (end > csq.length()))
251  throw new IndexOutOfBoundsException();
252  for (int i = start; i < end;) {
253  append(csq.charAt(i++));
254  }
255  return this;
256  }

References javolution.text.TextBuilder.append().

Here is the call graph for this function:

◆ append() [7/18]

final TextBuilder javolution.text.TextBuilder.append ( double  d)

Appends the textual representation of the specified double; the number of digits is 17 or 16 when the 16 digits representation can be parsed back to the same double (mimic the standard library formatting).

Parameters
dthe double to format.
Returns
append(d, -1, (MathLib.abs(d) >= 1E7) || (MathLib.abs(d) < 0.001), false)

Definition at line 572 of file TextBuilder.java.

572  {
573  return append(d, -1, (MathLib.abs(d) >= 1E7)
574  || (MathLib.abs(d) < 0.001), false);
575  }

References javolution.lang.MathLib.abs(), and javolution.text.TextBuilder.append().

Here is the call graph for this function:

◆ append() [8/18]

final TextBuilder javolution.text.TextBuilder.append ( double  d,
int  digits,
boolean  scientific,
boolean  showZero 
)

Appends the textual representation of the specified double according to the specified formatting arguments.

Parameters
dthe double value.
digitsthe number of significative digits (excludes exponent) or -1 to mimic the standard library (16 or 17 digits).
scientifictrue to forces the use of the scientific notation (e.g. 1.23E3); false otherwise.
showZerotrue if trailing fractional zeros are represented; false otherwise.
Returns
TypeFormat.format(d, digits, scientific, showZero, this)
Exceptions
IllegalArgumentExceptionif (digits > 19))

Definition at line 592 of file TextBuilder.java.

593  {
594  if (digits > 19)
595  throw new IllegalArgumentException("digits: " + digits);
596  if (d != d) // NaN
597  return append("NaN");
598  if (d == Double.POSITIVE_INFINITY)
599  return append("Infinity");
600  if (d == Double.NEGATIVE_INFINITY)
601  return append("-Infinity");
602  if (d == 0.0) { // Zero.
603  if (digits < 0)
604  return append("0.0");
605  append('0');
606  if (showZero) {
607  append('.');
608  for (int j = 1; j < digits; j++) {
609  append('0');
610  }
611  }
612  return this;
613  }
614  if (d < 0) { // Work with positive number.
615  d = -d;
616  append('-');
617  }
618 
619  // Find the exponent e such as: value == x.xxx * 10^e
620  int e = MathLib.floorLog10(d);
621 
622  long m;
623  if (digits < 0) { // Use 16 or 17 digits.
624  // Try 17 digits.
625  long m17 = MathLib.toLongPow10(d, (17 - 1) - e);
626  // Check if we can use 16 digits.
627  long m16 = m17 / 10;
628  double dd = MathLib.toDoublePow10(m16, e - 16 + 1);
629  if (dd == d) { // 16 digits is enough.
630  digits = 16;
631  m = m16;
632  } else { // We cannot remove the last digit.
633  digits = 17;
634  m = m17;
635  }
636  } else
637  // Use the specified number of digits.
638  m = MathLib.toLongPow10(d, (digits - 1) - e);
639 
640  // Formats.
641  if (scientific || (e >= digits)) {
642  // Scientific notation has to be used ("x.xxxEyy").
643  long pow10 = POW10_LONG[digits - 1];
644  int k = (int) (m / pow10); // Single digit.
645  append((char) ('0' + k));
646  m = m - pow10 * k;
647  appendFraction(m, digits - 1, showZero);
648  append('E');
649  append(e);
650  } else { // Dot within the string ("xxxx.xxxxx").
651  int exp = digits - e - 1;
652  if (exp < POW10_LONG.length) {
653  long pow10 = POW10_LONG[exp];
654  long l = m / pow10;
655  append(l);
656  m = m - pow10 * l;
657  } else
658  append('0'); // Result of the division by a power of 10 larger than any long.
659  appendFraction(m, exp, showZero);
660  }
661  return this;
662  }

References javolution.text.TextBuilder.append(), javolution.text.TextBuilder.appendFraction(), javolution.lang.MathLib.floorLog10(), javolution.text.TextBuilder.POW10_LONG, javolution.lang.MathLib.toDoublePow10(), and javolution.lang.MathLib.toLongPow10().

Here is the call graph for this function:

◆ append() [9/18]

final TextBuilder javolution.text.TextBuilder.append ( float  f)

Appends the textual representation of the specified float.

Parameters
fthe float to format.
Returns
append(f, 10, (abs(f) >= 1E7) || (abs(f) < 0.001), false)

Definition at line 557 of file TextBuilder.java.

557  {
558  return append(f, 10, (MathLib.abs(f) >= 1E7)
559  || (MathLib.abs(f) < 0.001), false);
560  }

References javolution.lang.MathLib.abs(), and javolution.text.TextBuilder.append().

Here is the call graph for this function:

◆ append() [10/18]

final TextBuilder javolution.text.TextBuilder.append ( int  i)

Appends the decimal representation of the specified int argument.

Parameters
ithe int to format.
Returns
this

Definition at line 407 of file TextBuilder.java.

407  {
408  if (i <= 0) {
409  if (i == 0)
410  return append("0");
411  if (i == Integer.MIN_VALUE) // Negation would overflow.
412  return append("-2147483648");
413  append('-');
414  i = -i;
415  }
416  int digits = MathLib.digitLength(i);
417  if (_capacity < _length + digits)
419  _length += digits;
420  for (int index = _length - 1;; index--) {
421  int j = i / 10;
422  _high[index >> B1][index & M1] = (char) ('0' + i - (j * 10));
423  if (j == 0)
424  return this;
425  i = j;
426  }
427  }

References javolution.text.TextBuilder._capacity, javolution.text.TextBuilder._high, javolution.text.TextBuilder._length, javolution.text.TextBuilder.append(), javolution.text.TextBuilder.B1, javolution.lang.MathLib.digitLength(), javolution.text.TextBuilder.increaseCapacity(), and javolution.text.TextBuilder.M1.

Here is the call graph for this function:

◆ append() [11/18]

final TextBuilder javolution.text.TextBuilder.append ( int  i,
int  radix 
)

Appends the radix representation of the specified int argument.

Parameters
ithe int to format.
radixthe radix (e.g. 16 for hexadecimal).
Returns
this

Definition at line 437 of file TextBuilder.java.

437  {
438  if (radix == 10)
439  return append(i); // Faster.
440  if (radix < 2 || radix > 36)
441  throw new IllegalArgumentException("radix: " + radix);
442  if (i < 0) {
443  append('-');
444  if (i == Integer.MIN_VALUE) { // Negative would overflow.
445  appendPositive(-(i / radix), radix);
446  return (TextBuilder) append(DIGIT_TO_CHAR[-(i % radix)]);
447  }
448  i = -i;
449  }
450  appendPositive(i, radix);
451  return this;
452  }

References javolution.text.TextBuilder.append(), javolution.text.TextBuilder.appendPositive(), and javolution.text.TextBuilder.DIGIT_TO_CHAR.

Here is the call graph for this function:

◆ append() [12/18]

final TextBuilder javolution.text.TextBuilder.append ( long  l)

Appends the decimal representation of the specified long argument.

Parameters
lthe long to format.
Returns
this

Definition at line 487 of file TextBuilder.java.

487  {
488  if (l <= 0) {
489  if (l == 0)
490  return append("0");
491  if (l == Long.MIN_VALUE) // Negation would overflow.
492  return append("-9223372036854775808");
493  append('-');
494  l = -l;
495  }
496  if (l <= Integer.MAX_VALUE)
497  return append((int) l);
498  append(l / 1000000000);
499  int i = (int) (l % 1000000000);
500  int digits = MathLib.digitLength(i);
501  append("000000000", 0, 9 - digits);
502  return append(i);
503  }

References javolution.text.TextBuilder.append(), and javolution.lang.MathLib.digitLength().

Here is the call graph for this function:

◆ append() [13/18]

final TextBuilder javolution.text.TextBuilder.append ( long  l,
int  radix 
)

Appends the radix representation of the specified long argument.

Parameters
lthe long to format.
radixthe radix (e.g. 16 for hexadecimal).
Returns
this

Definition at line 513 of file TextBuilder.java.

513  {
514  if (radix == 10)
515  return append(l); // Faster.
516  if (radix < 2 || radix > 36)
517  throw new IllegalArgumentException("radix: " + radix);
518  if (l < 0) {
519  append('-');
520  if (l == Long.MIN_VALUE) { // Negative would overflow.
521  appendPositive(-(l / radix), radix);
522  return (TextBuilder) append(DIGIT_TO_CHAR[(int) -(l % radix)]);
523  }
524  l = -l;
525  }
526  appendPositive(l, radix);
527  return this;
528  }

References javolution.text.TextBuilder.append(), javolution.text.TextBuilder.appendPositive(), and javolution.text.TextBuilder.DIGIT_TO_CHAR.

Here is the call graph for this function:

◆ append() [14/18]

final TextBuilder javolution.text.TextBuilder.append ( Object  obj)

Appends the textual representation of the specified object. This method is equivalent to

TextContext.getFormat(obj.getClass()).format(obj, this)

Definition at line 215 of file TextBuilder.java.

215  {
216  if (obj == null) return append("null");
217  TextFormat<Object> textFormat = TextContext.getFormat(obj.getClass());
218  if (textFormat == null) return append(obj.toString());
219  return textFormat.format(obj, this);
220  }

References javolution.text.TextBuilder.append(), javolution.text.TextFormat< T >.format(), and javolution.text.TextContext.getFormat().

Here is the call graph for this function:

◆ append() [15/18]

final TextBuilder javolution.text.TextBuilder.append ( String  str)

Appends the specified string to this text builder. If the specified string is null this method is equivalent to append("null").

Parameters
strthe string to append or null.
Returns
this

Definition at line 266 of file TextBuilder.java.

266  {
267  return (str == null) ? append("null") : append(str, 0, str.length());
268  }

References javolution.text.TextBuilder.append().

Here is the call graph for this function:

◆ append() [16/18]

final TextBuilder javolution.text.TextBuilder.append ( String  str,
int  start,
int  end 
)

Appends a subsequence of the specified string. If the specified character sequence is null this method is equivalent to append("null").

Parameters
strthe string to append or null.
startthe index of the first character to append.
endthe index after the last character to append.
Returns
this
Exceptions
IndexOutOfBoundsExceptionif (start < 0) || (end < 0) || (start > end) || (end > str.length())

Definition at line 282 of file TextBuilder.java.

282  {
283  if (str == null)
284  return append("null");
285  if ((start < 0) || (end < 0) || (start > end) || (end > str.length()))
286  throw new IndexOutOfBoundsException("start: " + start + ", end: "
287  + end + ", str.length(): " + str.length());
288  int newLength = _length + end - start;
289  while (_capacity < newLength) {
291  }
292  for (int i = start, j = _length; i < end;) {
293  char[] chars = _high[j >> B1];
294  int dstBegin = j & M1;
295  int inc = MathLib.min(C1 - dstBegin, end - i);
296  str.getChars(i, (i += inc), chars, dstBegin);
297  j += inc;
298  }
299  _length = newLength;
300  return this;
301  }

References javolution.text.TextBuilder._capacity, javolution.text.TextBuilder._high, javolution.text.TextBuilder._length, javolution.text.TextBuilder.append(), javolution.text.TextBuilder.B1, javolution.text.TextBuilder.C1, javolution.text.TextBuilder.increaseCapacity(), javolution.text.TextBuilder.M1, and javolution.lang.MathLib.min().

Here is the call graph for this function:

◆ append() [17/18]

final TextBuilder javolution.text.TextBuilder.append ( Text  txt)

Appends the specified text to this text builder. If the specified text is null this method is equivalent to append("null").

Parameters
txtthe text to append or null.
Returns
this

Definition at line 311 of file TextBuilder.java.

311  {
312  return (txt == null) ? append("null") : append(txt, 0, txt.length());
313  }

References javolution.text.TextBuilder.append(), and javolution.text.Text.length().

Here is the call graph for this function:

◆ append() [18/18]

final TextBuilder javolution.text.TextBuilder.append ( Text  txt,
int  start,
int  end 
)

Appends a subsequence of the specified text. If the specified character sequence is null this method is equivalent to append("null").

Parameters
txtthe text to append or null.
startthe index of the first character to append.
endthe index after the last character to append.
Returns
this
Exceptions
IndexOutOfBoundsExceptionif (start < 0) || (end < 0) || (start > end) || (end > txt.length())

Definition at line 327 of file TextBuilder.java.

327  {
328  if (txt == null)
329  return append("null");
330  if ((start < 0) || (end < 0) || (start > end) || (end > txt.length()))
331  throw new IndexOutOfBoundsException();
332  int newLength = _length + end - start;
333  while (_capacity < newLength) {
335  }
336  for (int i = start, j = _length; i < end;) {
337  char[] chars = _high[j >> B1];
338  int dstBegin = j & M1;
339  int inc = MathLib.min(C1 - dstBegin, end - i);
340  txt.getChars(i, (i += inc), chars, dstBegin);
341  j += inc;
342  }
343  _length = newLength;
344  return this;
345  }

References javolution.text.TextBuilder._capacity, javolution.text.TextBuilder._high, javolution.text.TextBuilder._length, javolution.text.TextBuilder.append(), javolution.text.TextBuilder.B1, javolution.text.TextBuilder.C1, javolution.text.Text.getChars(), javolution.text.TextBuilder.increaseCapacity(), javolution.text.Text.length(), javolution.text.TextBuilder.M1, and javolution.lang.MathLib.min().

Here is the call graph for this function:

◆ appendFraction()

void javolution.text.TextBuilder.appendFraction ( long  l,
int  digits,
boolean  showZero 
)
private

Definition at line 664 of file TextBuilder.java.

664  {
665  append('.');
666  if (l == 0)
667  if (showZero)
668  for (int i = 0; i < digits; i++) {
669  append('0');
670  }
671  else
672  append('0');
673  else { // l is different from zero.
674  int length = MathLib.digitLength(l);
675  for (int j = length; j < digits; j++) {
676  append('0'); // Add leading zeros.
677  }
678  if (!showZero)
679  while (l % 10 == 0) {
680  l /= 10; // Remove trailing zeros.
681  }
682  append(l);
683  }
684  }

References javolution.text.TextBuilder.append(), javolution.lang.MathLib.digitLength(), and javolution.text.TextBuilder.length().

Referenced by javolution.text.TextBuilder.append().

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

◆ appendPositive() [1/2]

void javolution.text.TextBuilder.appendPositive ( int  l1,
int  radix 
)
private

Definition at line 454 of file TextBuilder.java.

454  {
455  if (l1 >= radix) {
456  int l2 = l1 / radix;
457  // appendPositive(l2, radix);
458  if (l2 >= radix) {
459  int l3 = l2 / radix;
460  // appendPositive(l3, radix);
461  if (l3 >= radix) {
462  int l4 = l3 / radix;
463  appendPositive(l4, radix);
464  append(DIGIT_TO_CHAR[l3 - (l4 * radix)]);
465  } else
466  append(DIGIT_TO_CHAR[l3]);
467  append(DIGIT_TO_CHAR[l2 - (l3 * radix)]);
468  } else
469  append(DIGIT_TO_CHAR[l2]);
470  append(DIGIT_TO_CHAR[l1 - (l2 * radix)]);
471  } else
472  append(DIGIT_TO_CHAR[l1]);
473  }

References javolution.text.TextBuilder.append(), and javolution.text.TextBuilder.DIGIT_TO_CHAR.

Referenced by javolution.text.TextBuilder.append(), and javolution.text.TextBuilder.appendPositive().

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

◆ appendPositive() [2/2]

void javolution.text.TextBuilder.appendPositive ( long  l1,
int  radix 
)
private

Definition at line 530 of file TextBuilder.java.

530  {
531  if (l1 >= radix) {
532  long l2 = l1 / radix;
533  // appendPositive(l2, radix);
534  if (l2 >= radix) {
535  long l3 = l2 / radix;
536  // appendPositive(l3, radix);
537  if (l3 >= radix) {
538  long l4 = l3 / radix;
539  appendPositive(l4, radix);
540  append(DIGIT_TO_CHAR[(int) (l3 - (l4 * radix))]);
541  } else
542  append(DIGIT_TO_CHAR[(int) l3]);
543  append(DIGIT_TO_CHAR[(int) (l2 - (l3 * radix))]);
544  } else
545  append(DIGIT_TO_CHAR[(int) l2]);
546  append(DIGIT_TO_CHAR[(int) (l1 - (l2 * radix))]);
547  } else
548  append(DIGIT_TO_CHAR[(int) l1]);
549  }

References javolution.text.TextBuilder.append(), javolution.text.TextBuilder.appendPositive(), and javolution.text.TextBuilder.DIGIT_TO_CHAR.

Here is the call graph for this function:

◆ charAt()

final char javolution.text.TextBuilder.charAt ( int  index)

Returns the character at the specified index.

Parameters
indexthe index of the character.
Returns
the character at the specified index.
Exceptions
IndexOutOfBoundsExceptionif (index < 0) || (index >= this.length()).

Definition at line 103 of file TextBuilder.java.

103  {
104  if (index >= _length)
105  throw new IndexOutOfBoundsException();
106  return index < C1 ? _low[index] : _high[index >> B1][index & M1];
107  }

References javolution.text.TextBuilder._length, javolution.text.TextBuilder.B1, and javolution.text.TextBuilder.M1.

Referenced by javolution.text.TextBuilder.delete(), javolution.text.TextBuilder.equals(), javolution.text.TextBuilder.hashCode(), javolution.text.TextBuilder.insert(), and javolution.text.TextBuilder.reverse().

Here is the caller graph for this function:

◆ clear()

final TextBuilder javolution.text.TextBuilder.clear ( )

Removes all the characters of this text builder (equivalent to this.delete(start, this.length())).

Returns
this.delete(0, this.length())

Definition at line 725 of file TextBuilder.java.

725  {
726  _length = 0;
727  return this;
728  }

References javolution.text.TextBuilder._length.

Referenced by javolution.xml.internal.stream.XMLStreamWriterImpl.getRepairedPrefix(), javolution.xml.ws.WebServiceClient.invoke(), javolution.xml.XMLFormat< T >.OutputElement.setAttribute(), javolution.xml.internal.stream.XMLStreamWriterImpl.writeNewElement(), and javolution.xml.XMLReferenceResolver.writeReference().

Here is the caller graph for this function:

◆ contentEquals()

final boolean javolution.text.TextBuilder.contentEquals ( java.lang.CharSequence  csq)

Indicates if this text builder has the same character content as the specified character sequence.

Parameters
csqthe character sequence to compare with.
Returns
true if the specified character sequence has the same character content as this text; false otherwise.

Definition at line 856 of file TextBuilder.java.

856  {
857  if (csq.length() != _length)
858  return false;
859  for (int i = 0; i < _length;) {
860  char c = _high[i >> B1][i & M1];
861  if (csq.charAt(i++) != c)
862  return false;
863  }
864  return true;
865  }

References javolution.text.TextBuilder._high, javolution.text.TextBuilder._length, javolution.text.TextBuilder.B1, and javolution.text.TextBuilder.M1.

◆ delete()

final TextBuilder javolution.text.TextBuilder.delete ( int  start,
int  end 
)

Removes the characters between the specified indices.

Parameters
startthe beginning index, inclusive.
endthe ending index, exclusive.
Returns
this
Exceptions
IndexOutOfBoundsExceptionif (start < 0) || (end < 0) || (start > end) || (end > this.length())

Definition at line 739 of file TextBuilder.java.

739  {
740  if ((start < 0) || (end < 0) || (start > end) || (end > this.length()))
741  throw new IndexOutOfBoundsException();
742  for (int i = end, j = start; i < _length;) {
743  this.setCharAt(j++, this.charAt(i++));
744  }
745  _length -= end - start;
746  return this;
747  }

References javolution.text.TextBuilder._length, javolution.text.TextBuilder.charAt(), javolution.text.TextBuilder.length(), and javolution.text.TextBuilder.setCharAt().

Here is the call graph for this function:

◆ equals()

final boolean javolution.text.TextBuilder.equals ( Object  obj)

Compares this text builder against the specified object for equality. Returns true if the specified object is a text builder having the same character content.

Parameters
objthe object to compare with or null.
Returns
true if that is a text builder with the same character content as this text; false otherwise.

Definition at line 833 of file TextBuilder.java.

833  {
834  if (this == obj)
835  return true;
836  if (!(obj instanceof TextBuilder))
837  return false;
838  TextBuilder that = (TextBuilder) obj;
839  if (this._length != that._length)
840  return false;
841  for (int i = 0; i < _length;) {
842  if (this.charAt(i) != that.charAt(i++))
843  return false;
844  }
845  return true;
846  }

References javolution.text.TextBuilder._length, javolution.text.TextBuilder.charAt(), and javolution.text.TextBuilder.TextBuilder().

Here is the call graph for this function:

◆ getChars()

final void javolution.text.TextBuilder.getChars ( int  srcBegin,
int  srcEnd,
char[]  dst,
int  dstBegin 
)

Copies the character from this text builder into the destination character array.

Parameters
srcBeginthis text start index.
srcEndthis text end index (not included).
dstthe destination array to copy the data into.
dstBeginthe offset into the destination array.
Exceptions
IndexOutOfBoundsExceptionif (srcBegin < 0) || (dstBegin < 0) || (srcBegin > srcEnd) || (srcEnd > this.length()) || ((dstBegin + srcEnd - srcBegin) > dst.length)

Definition at line 121 of file TextBuilder.java.

122  {
123  if ((srcBegin < 0) || (srcBegin > srcEnd) || (srcEnd > this._length))
124  throw new IndexOutOfBoundsException();
125  for (int i = srcBegin, j = dstBegin; i < srcEnd;) {
126  char[] chars0 = _high[i >> B1];
127  int i0 = i & M1;
128  int length = MathLib.min(C1 - i0, srcEnd - i);
129  System.arraycopy(chars0, i0, dst, j, length);
130  i += length;
131  j += length;
132  }
133  }

References javolution.text.TextBuilder._high, javolution.text.TextBuilder.B1, javolution.text.TextBuilder.C1, javolution.text.TextBuilder.length(), javolution.text.TextBuilder.M1, and javolution.lang.MathLib.min().

Referenced by javolution.io.CharSequenceReader.read(), javolution.text.TextBuilder.toCharArray(), javolution.text.TextBuilder.toLargeString(), and javolution.text.Text.valueOf().

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

◆ hashCode()

final int javolution.text.TextBuilder.hashCode ( )

Returns the hash code for this text builder.

Returns
the hash code value.

Definition at line 815 of file TextBuilder.java.

815  {
816  int h = 0;
817  for (int i = 0; i < _length;) {
818  h = 31 * h + charAt(i++);
819  }
820  return h;
821  }

References javolution.text.TextBuilder._length, and javolution.text.TextBuilder.charAt().

Here is the call graph for this function:

◆ increaseCapacity()

void javolution.text.TextBuilder.increaseCapacity ( )
private

Increases this text builder capacity.

Definition at line 870 of file TextBuilder.java.

870  {
871  if (_capacity < C1) { // For small capacity, resize.
872  _capacity <<= 1;
873  char[] tmp = new char[_capacity];
874  System.arraycopy(_low, 0, tmp, 0, _length);
875  _low = tmp;
876  _high[0] = tmp;
877  } else { // Add a new low block of 1024 elements.
878  int j = _capacity >> B1;
879  if (j >= _high.length) { // Resizes _high.
880  char[][] tmp = new char[_high.length * 2][];
881  System.arraycopy(_high, 0, tmp, 0, _high.length);
882  _high = tmp;
883  }
884  _high[j] = new char[C1];
885  _capacity += C1;
886  }
887  }

References javolution.text.TextBuilder._capacity, javolution.text.TextBuilder._high, javolution.text.TextBuilder._length, javolution.text.TextBuilder._low, javolution.text.TextBuilder.B1, and javolution.text.TextBuilder.C1.

Referenced by javolution.text.TextBuilder.append(), javolution.text.TextBuilder.insert(), and javolution.text.TextBuilder.TextBuilder().

Here is the caller graph for this function:

◆ insert()

final TextBuilder javolution.text.TextBuilder.insert ( int  index,
java.lang.CharSequence  csq 
)

Inserts the specified character sequence at the specified location.

Parameters
indexthe insertion position.
csqthe character sequence being inserted.
Returns
this
Exceptions
IndexOutOfBoundsExceptionif (index < 0) || (index > this.length())

Definition at line 701 of file TextBuilder.java.

701  {
702  if ((index < 0) || (index > _length))
703  throw new IndexOutOfBoundsException("index: " + index);
704  final int shift = csq.length();
705  int newLength = _length + shift;
706  while (newLength >= _capacity) {
708  }
709  _length = newLength;
710  for (int i = _length - shift; --i >= index;) {
711  this.setCharAt(i + shift, this.charAt(i));
712  }
713  for (int i = csq.length(); --i >= 0;) {
714  this.setCharAt(index + i, csq.charAt(i));
715  }
716  return this;
717  }

References javolution.text.TextBuilder._capacity, javolution.text.TextBuilder._length, javolution.text.TextBuilder.charAt(), javolution.text.TextBuilder.increaseCapacity(), and javolution.text.TextBuilder.setCharAt().

Here is the call graph for this function:

◆ length()

final int javolution.text.TextBuilder.length ( )

Returns the length (character count) of this text builder.

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

Definition at line 91 of file TextBuilder.java.

91  {
92  return _length;
93  }

References javolution.text.TextBuilder._length.

Referenced by javolution.text.TextBuilder.append(), javolution.text.TextBuilder.appendFraction(), javolution.text.TextBuilder.delete(), javolution.text.TextBuilder.getChars(), javolution.xml.ws.WebServiceClient.invoke(), javolution.test.Perfometer< T >.print(), javolution.xml.internal.stream.XMLStreamWriterImpl.resizeElemStack(), javolution.text.CharSet.toString(), javolution.xml.internal.stream.XMLStreamWriterImpl.writeNewElement(), and javolution.xml.internal.stream.XMLStreamWriterImpl.XMLStreamWriterImpl().

Here is the caller graph for this function:

◆ reverse()

final TextBuilder javolution.text.TextBuilder.reverse ( )

Reverses this character sequence.

Returns
this

Definition at line 754 of file TextBuilder.java.

754  {
755  final int n = _length - 1;
756  for (int j = (n - 1) >> 1; j >= 0;) {
757  char c = charAt(j);
758  setCharAt(j, charAt(n - j));
759  setCharAt(n - j--, c);
760  }
761  return this;
762  }

References javolution.text.TextBuilder._length, javolution.text.TextBuilder.charAt(), and javolution.text.TextBuilder.setCharAt().

Here is the call graph for this function:

◆ setCharAt()

final void javolution.text.TextBuilder.setCharAt ( int  index,
char  c 
)

Sets the character at the specified position.

Parameters
indexthe index of the character to modify.
cthe new character.
Exceptions
IndexOutOfBoundsExceptionif (index < 0) || (index >= this.length())

Definition at line 143 of file TextBuilder.java.

143  {
144  if ((index < 0) || (index >= _length))
145  throw new IndexOutOfBoundsException();
146  _high[index >> B1][index & M1] = c;
147  }

References javolution.text.TextBuilder._high, javolution.text.TextBuilder._length, javolution.text.TextBuilder.B1, and javolution.text.TextBuilder.M1.

Referenced by javolution.text.TextBuilder.delete(), javolution.text.TextBuilder.insert(), and javolution.text.TextBuilder.reverse().

Here is the caller graph for this function:

◆ setLength() [1/2]

final void javolution.text.TextBuilder.setLength ( int  newLength)

Convenience method equivalent to setLength(newLength, '').

Parameters
newLengththe new length of this builder.
Exceptions
IndexOutOfBoundsExceptionif (newLength < 0)

Definition at line 156 of file TextBuilder.java.

156  {
157  setLength(newLength, '\u0000');
158  }

◆ setLength() [2/2]

final void javolution.text.TextBuilder.setLength ( int  newLength,
char  fillChar 
)

Sets the length of this character builder. If the length is greater than the current length; the specified character is inserted.

Parameters
newLengththe new length of this builder.
fillCharthe character to be appended if required.
Exceptions
IndexOutOfBoundsExceptionif (newLength < 0)

Definition at line 169 of file TextBuilder.java.

169  {
170  if (newLength < 0)
171  throw new IndexOutOfBoundsException();
172  if (newLength <= _length)
173  _length = newLength;
174  else
175  for (int i = _length; i++ < newLength;) {
176  append(fillChar);
177  }
178  }

References javolution.text.TextBuilder._length, and javolution.text.TextBuilder.append().

Here is the call graph for this function:

◆ subSequence()

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

Returns a java.lang.CharSequence corresponding to the character sequence between the specified indexes.

Parameters
startthe index of the first character inclusive.
endthe index of the last character exclusive.
Returns
a character sequence.
Exceptions
IndexOutOfBoundsExceptionif (start < 0) || (end < 0) || (start > end) || (end > this.length())

Definition at line 190 of file TextBuilder.java.

190  {
191  if ((start < 0) || (end < 0) || (start > end) || (end > _length))
192  throw new IndexOutOfBoundsException();
193  return Text.valueOf(this, start, end);
194  }

References javolution.text.TextBuilder._length, and javolution.text.Text.valueOf().

Here is the call graph for this function:

◆ toCharArray()

final CharArray javolution.text.TextBuilder.toCharArray ( )

Returns the CharArray representation of this TextBuilder.

Returns
the corresponding CharArray instance.

Definition at line 796 of file TextBuilder.java.

796  {
797  CharArray cArray = new CharArray();
798  char[] data;
799  if (_length < C1) {
800  data = _low;
801  } else {
802  data = new char[_length];
803  this.getChars(0, _length, data, 0);
804  }
805  cArray.setArray(data, 0, _length);
806  return cArray;
807  }

References javolution.text.TextBuilder._length, javolution.text.TextBuilder._low, javolution.text.TextBuilder.C1, javolution.text.TextBuilder.getChars(), and javolution.text.CharArray.setArray().

Here is the call graph for this function:

◆ toLargeString()

String javolution.text.TextBuilder.toLargeString ( )
private

Definition at line 784 of file TextBuilder.java.

784  {
785  char[] data = new char[_length];
786  this.getChars(0, _length, data, 0);
787  return new String(data, 0, _length);
788  }

References javolution.text.TextBuilder._length, and javolution.text.TextBuilder.getChars().

Referenced by javolution.text.TextBuilder.toString().

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

◆ toString()

final String javolution.text.TextBuilder.toString ( )

Returns the String representation of this TextBuilder.

Returns
the java.lang.String for this text builder.

Definition at line 780 of file TextBuilder.java.

780  {
781  return (_length < C1) ? new String(_low, 0, _length) : toLargeString();
782  }

References javolution.text.TextBuilder._length, javolution.text.TextBuilder._low, javolution.text.TextBuilder.C1, and javolution.text.TextBuilder.toLargeString().

Referenced by javolution.io.Struct.UTF8String.get(), javolution.context.internal.LogContextImpl.log(), javolution.text.CharSet.toString(), and javolution.io.Struct.toString().

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

◆ toText()

final Text javolution.text.TextBuilder.toText ( )

Returns the Text corresponding to this TextBuilder.

Returns
the corresponding Text instance.

Definition at line 769 of file TextBuilder.java.

769  {
770  return Text.valueOf(this, 0, _length);
771  }

References javolution.text.TextBuilder._length, and javolution.text.Text.valueOf().

Referenced by javolution.text.Text.valueOf().

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

Member Data Documentation

◆ _capacity

int javolution.text.TextBuilder._capacity = C0
private

◆ _high

◆ _length

◆ _low

◆ B0

final int javolution.text.TextBuilder.B0 = 5
staticprivate

Definition at line 34 of file TextBuilder.java.

◆ B1

◆ C0

final int javolution.text.TextBuilder.C0 = 1 << B0
staticprivate

Definition at line 35 of file TextBuilder.java.

◆ C1

◆ DIGIT_TO_CHAR

final char [] javolution.text.TextBuilder.DIGIT_TO_CHAR
staticprivate
Initial value:
= { '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z' }

Definition at line 475 of file TextBuilder.java.

Referenced by javolution.text.TextBuilder.append(), and javolution.text.TextBuilder.appendPositive().

◆ M1

◆ POW10_LONG

final long [] javolution.text.TextBuilder.POW10_LONG
staticprivate
Initial value:
= new long[] { 1L, 10L, 100L, 1000L,
10000L, 100000L, 1000000L, 10000000L, 100000000L, 1000000000L,
10000000000L, 100000000000L, 1000000000000L, 10000000000000L,
100000000000000L, 1000000000000000L, 10000000000000000L,
100000000000000000L, 1000000000000000000L }

Definition at line 686 of file TextBuilder.java.

Referenced by javolution.text.TextBuilder.append().

◆ serialVersionUID

final long javolution.text.TextBuilder.serialVersionUID = 0x600L
staticprivate

Definition at line 31 of file TextBuilder.java.


The documentation for this class was generated from the following file:
javolution.text.TextBuilder._capacity
int _capacity
Definition: TextBuilder.java:52
javolution.text.TextBuilder.B1
static final int B1
Definition: TextBuilder.java:36
javolution.text.TextBuilder.TextBuilder
TextBuilder()
Definition: TextBuilder.java:57
javolution.text.TextBuilder.append
final TextBuilder append(char c)
Definition: TextBuilder.java:202
javolution.text.TextBuilder.toLargeString
String toLargeString()
Definition: TextBuilder.java:784
javolution.text.TextBuilder.appendPositive
void appendPositive(int l1, int radix)
Definition: TextBuilder.java:454
javolution.text.TextBuilder.POW10_LONG
static final long[] POW10_LONG
Definition: TextBuilder.java:686
javolution.text.TextBuilder.DIGIT_TO_CHAR
static final char[] DIGIT_TO_CHAR
Definition: TextBuilder.java:475
javolution.text.TextBuilder.length
final int length()
Definition: TextBuilder.java:91
javolution.text.TextBuilder._high
char[][] _high
Definition: TextBuilder.java:42
javolution.text.TextBuilder.increaseCapacity
void increaseCapacity()
Definition: TextBuilder.java:870
javolution.text.TextBuilder.getChars
final void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
Definition: TextBuilder.java:121
javolution.text.TextBuilder.appendFraction
void appendFraction(long l, int digits, boolean showZero)
Definition: TextBuilder.java:664
javolution.text.TextBuilder.C1
static final int C1
Definition: TextBuilder.java:37
javolution.text.TextBuilder.setCharAt
final void setCharAt(int index, char c)
Definition: TextBuilder.java:143
javolution.text.TextBuilder.charAt
final char charAt(int index)
Definition: TextBuilder.java:103
javolution.text.TextBuilder._low
char[] _low
Definition: TextBuilder.java:40
javolution.text.TextBuilder._length
int _length
Definition: TextBuilder.java:47
javolution.text.TextBuilder.setLength
final void setLength(int newLength)
Definition: TextBuilder.java:156
javolution.text.TextBuilder.M1
static final int M1
Definition: TextBuilder.java:38