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

Public Member Functions

 Text (String str)
 
int length ()
 
Text plus (Object obj)
 
Text plus (String str)
 
Text concat (Text that)
 
Text subtext (int start)
 
Text insert (int index, Text txt)
 
Text delete (int start, int end)
 
Text replace (java.lang.CharSequence target, java.lang.CharSequence replacement)
 
Text replace (CharSet charSet, java.lang.CharSequence replacement)
 
java.lang.CharSequence subSequence (int start, int end)
 
int indexOf (java.lang.CharSequence csq)
 
int indexOf (java.lang.CharSequence csq, int fromIndex)
 
int lastIndexOf (java.lang.CharSequence csq)
 
int lastIndexOf (java.lang.CharSequence csq, int fromIndex)
 
boolean startsWith (java.lang.CharSequence prefix)
 
boolean endsWith (java.lang.CharSequence suffix)
 
boolean startsWith (java.lang.CharSequence prefix, int index)
 
Text trim ()
 
Text intern ()
 
boolean contentEquals (java.lang.CharSequence csq)
 
boolean contentEqualsIgnoreCase (java.lang.CharSequence csq)
 
boolean equals (Object obj)
 
int hashCode ()
 
int compareTo (CharSequence csq)
 
Text toText ()
 
void printStatistics (PrintStream out)
 
Text toLowerCase ()
 
Text toUpperCase ()
 
char charAt (int index)
 
int indexOf (char c)
 
int indexOf (char c, int fromIndex)
 
int lastIndexOf (char c, int fromIndex)
 
Text subtext (int start, int end)
 
void getChars (int start, int end, char dest[], int destPos)
 
String toString ()
 
Text copy ()
 
boolean isBlank ()
 
boolean isBlank (int start, int length)
 
Text trimStart ()
 
Text trimEnd ()
 
Text padLeft (int len)
 
Text padLeft (int len, char c)
 
Text padRight (int len)
 
Text padRight (int len, char c)
 
int indexOfAny (CharSet charSet)
 
int indexOfAny (CharSet charSet, int start)
 
int indexOfAny (CharSet charSet, int start, int length)
 
int lastIndexOfAny (CharSet charSet)
 
int lastIndexOfAny (CharSet charSet, int start)
 
int lastIndexOfAny (CharSet charSet, int start, int length)
 
Text value ()
 

Static Public Member Functions

static Text valueOf (Object obj)
 
static Text valueOf (char[] chars)
 
static Text valueOf (char[] chars, int offset, int length)
 
static Text valueOf (boolean b)
 
static Text valueOf (char c)
 
static Text valueOf (int i)
 
static Text valueOf (int i, int radix)
 
static Text valueOf (long l)
 
static Text valueOf (long l, int radix)
 
static Text valueOf (float f)
 
static Text valueOf (double d)
 
static Text valueOf (double d, int digits, boolean scientific, boolean showZero)
 
static Text valueOf (char c, int length)
 

Static Public Attributes

static final Text EMPTY = new Text("").intern()
 

Static Package Functions

static Text valueOf (TextBuilder tb, int start, int end)
 

Private Member Functions

 Text (boolean isPrimitive)
 
Text append (String str)
 
Text rightRotation ()
 
Text leftRotation ()
 
int getDepth ()
 
int getNbrOfBranches ()
 
int getNbrOfLeaves ()
 

Static Private Member Functions

static Text valueOf (String str)
 
static Text valueOf (String str, int start, int end)
 
static Text newPrimitive (int length)
 
static Text newComposite (Text head, Text tail)
 

Private Attributes

final char[] _data
 
int _count
 
Text _head
 
Text _tail
 

Static Private Attributes

static final long serialVersionUID = 0x600L
 
static final int BLOCK_SIZE = 1 << 5
 
static final int BLOCK_MASK = ~(BLOCK_SIZE - 1)
 
static final FastMap< Text, TextINTERN
 
static final Text TRUE = new Text("true").intern()
 
static final Text FALSE = new Text("false").intern()
 

Detailed Description

An immutable character sequence with fast concatenation, insertion and deletion capabilities (O[Log(n)]) instead of O[n] for StringBuffer/StringBuilder).

This class has the same methods as Java String and .NET String with the following benefits:

  • No need for an intermediate StringBuffer/StringBuilder in order to manipulate textual documents (insertion, deletion or concatenation).
  • Bug free. They are not plagued by the String#substring memory leak bug (when small substrings prevent memory from larger string from being garbage collected).
  • More flexible as they allows for search and comparison with any java.lang.String or CharSequence.

Text literals should be explicitly interned. Unlike strings literals and strings-value constant expressions, interning is not implicit. For example:[code] final static Text TRUE = new Text("true").intern(); final static Text FALSE = new Text("true").intern("false"); [/code]

Implementation Note: To avoid expensive copy operations , Text instances are broken down into smaller immutable sequences, they form a minimal-depth binary tree. The tree is maintained balanced automatically through tree rotations. Insertion/deletions are performed in O[Log(n)] instead of O[n] for StringBuffer/StringBuilder.

Author
Jean-Marie Dautelle
Wilfried Middleton
Version
6.0, July 21, 2013

Definition at line 61 of file Text.java.

Constructor & Destructor Documentation

◆ Text() [1/2]

javolution.text.Text.Text ( boolean  isPrimitive)
private

Creates a new text instance.

Parameters
isPrimitiveindicates if primitive or composite.

Definition at line 112 of file Text.java.

112  {
113  _data = isPrimitive ? new char[BLOCK_SIZE] : null;
114  }

References javolution.text.Text._data, and javolution.text.Text.BLOCK_SIZE.

Referenced by javolution.text.Text.equals(), javolution.text.Text.newComposite(), javolution.text.Text.newPrimitive(), and javolution.text.Text.Text().

Here is the caller graph for this function:

◆ Text() [2/2]

javolution.text.Text.Text ( String  str)

Creates a text holding the characters from the specified String .

Parameters
strthe string holding the character content.

Definition at line 122 of file Text.java.

122  {
123  this(str.length() <= BLOCK_SIZE);
124  _count = str.length();
125  if (_data != null) { // Primitive.
126  str.getChars(0, _count, _data, 0);
127  } else { // Composite, splits on a block boundary.
128  int half = ((_count + BLOCK_SIZE) >> 1) & BLOCK_MASK;
129  _head = new Text(str.substring(0, half));
130  _tail = new Text(str.substring(half, _count));
131  }
132  }

References javolution.text.Text._count, javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, javolution.text.Text.BLOCK_MASK, javolution.text.Text.BLOCK_SIZE, and javolution.text.Text.Text().

Here is the call graph for this function:

Member Function Documentation

◆ append()

Text javolution.text.Text.append ( String  str)
private

Definition at line 374 of file Text.java.

374  { // Try to append, returns null if cannot.
375  int length = str.length();
376  if (_data == null) {
377  Text merge = _tail.append(str);
378  return merge != null ? Text.newComposite(_head, merge) : null;
379  } else { // Primitive.
380  if (_count + length > BLOCK_SIZE)
381  return null; // Cannot merge.
382  Text text = Text.newPrimitive(_count + length);
383  System.arraycopy(_data, 0, text._data, 0, _count);
384  str.getChars(0, length, text._data, _count);
385  return text;
386  }
387  }

References javolution.text.Text._count, javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, javolution.text.Text.append(), javolution.text.Text.BLOCK_SIZE, javolution.text.Text.getChars(), javolution.text.Text.length(), javolution.text.Text.newComposite(), and javolution.text.Text.newPrimitive().

Referenced by javolution.text.Text.append(), and javolution.text.Text.plus().

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

◆ charAt()

char javolution.text.Text.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 897 of file Text.java.

897  {
898  if (index >= _count)
899  throw new IndexOutOfBoundsException();
900  return (_data != null) ? _data[index] : (index < _head._count) ? _head
901  .charAt(index) : _tail.charAt(index - _head._count);
902  }

References javolution.text.Text._count, javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, and javolution.text.Text.charAt().

Referenced by javolution.text.Text.charAt(), javolution.text.Text.contentEquals(), javolution.text.Text.contentEqualsIgnoreCase(), javolution.text.Text.equals(), javolution.text.Text.hashCode(), javolution.text.Text.indexOf(), javolution.text.Text.indexOfAny(), javolution.text.Text.isBlank(), javolution.text.Text.lastIndexOf(), javolution.text.Text.lastIndexOfAny(), javolution.text.Text.trim(), javolution.text.Text.trimEnd(), and javolution.text.Text.trimStart().

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

◆ compareTo()

int javolution.text.Text.compareTo ( CharSequence  csq)

Compares this text to another character sequence or string lexicographically.

Parameters
csqthe character sequence to be compared.
Returns
TypeFormat.LEXICAL_COMPARATOR.compare(this, csq)
Exceptions
ClassCastExceptionif the specifed object is not a CharSequence or a String.

Definition at line 808 of file Text.java.

808  {
809  return Equalities.LEXICAL.compare(this, csq);
810  }

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

Here is the call graph for this function:

◆ concat()

Text javolution.text.Text.concat ( Text  that)

Concatenates the specified text to the end of this text. This method is very fast (faster even than StringBuffer.append(String)) and still returns a text instance with an internal binary tree of minimal depth!

Parameters
thatthe text that is concatenated.
Returns
this + that

Definition at line 398 of file Text.java.

398  {
399  // All Text instances are maintained balanced:
400  // (head < tail * 2) & (tail < head * 2)
401 
402  final int length = this._count + that._count;
403  if (length <= BLOCK_SIZE) { // Merges to primitive.
404  Text text = Text.newPrimitive(length);
405  this.getChars(0, this._count, text._data, 0);
406  that.getChars(0, that._count, text._data, this._count);
407  return text;
408 
409  } else { // Returns a composite.
410  Text head = this;
411  Text tail = that;
412 
413  if (((head._count << 1) < tail._count) && (tail._data == null)) { // tail is composite
414  // head too small, returns (head + tail/2) + (tail/2)
415  if (tail._head._count > tail._tail._count) {
416  // Rotates to concatenate with smaller part.
417  tail = tail.rightRotation();
418  }
419  head = head.concat(tail._head);
420  tail = tail._tail;
421 
422  } else if (((tail._count << 1) < head._count)
423  && (head._data == null)) { // head is composite.
424  // tail too small, returns (head/2) + (head/2 concat tail)
425  if (head._tail._count > head._head._count) {
426  // Rotates to concatenate with smaller part.
427  head = head.leftRotation();
428  }
429  tail = head._tail.concat(tail);
430  head = head._head;
431  }
432  return Text.newComposite(head, tail);
433  }
434  }

References javolution.text.Text._count, javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, javolution.text.Text.BLOCK_SIZE, javolution.text.Text.concat(), javolution.text.Text.getChars(), javolution.text.Text.leftRotation(), javolution.text.Text.length(), javolution.text.Text.newComposite(), javolution.text.Text.newPrimitive(), and javolution.text.Text.rightRotation().

Referenced by javolution.text.Text.concat(), javolution.text.Text.delete(), javolution.text.Text.insert(), javolution.text.Text.padRight(), javolution.text.Text.plus(), javolution.text.Text.replace(), and javolution.text.Text.subtext().

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

◆ contentEquals()

boolean javolution.text.Text.contentEquals ( java.lang.CharSequence  csq)

Indicates if this text 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 720 of file Text.java.

720  {
721  if (csq.length() != _count)
722  return false;
723  for (int i = 0; i < _count;) {
724  if (this.charAt(i) != csq.charAt(i++))
725  return false;
726  }
727  return true;
728  }

References javolution.text.Text._count, and javolution.text.Text.charAt().

Here is the call graph for this function:

◆ contentEqualsIgnoreCase()

boolean javolution.text.Text.contentEqualsIgnoreCase ( java.lang.CharSequence  csq)

Indicates if this text has the same character contend as the specified character sequence ignoring case considerations.

Parameters
csqthe CharSequence to compare this text against.
Returns
true if the argument and this text are equal, ignoring case; false otherwise.

Definition at line 738 of file Text.java.

738  {
739  if (this._count != csq.length())
740  return false;
741  for (int i = 0; i < _count;) {
742  char u1 = this.charAt(i);
743  char u2 = csq.charAt(i++);
744  if (u1 != u2) {
745  u1 = Character.toUpperCase(u1);
746  u2 = Character.toUpperCase(u2);
747  if ((u1 != u2)
748  && (Character.toLowerCase(u1) != Character
749  .toLowerCase(u2)))
750  return false;
751 
752  }
753  }
754  return true;
755  }

References javolution.text.Text._count, and javolution.text.Text.charAt().

Here is the call graph for this function:

◆ copy()

Text javolution.text.Text.copy ( )

Definition at line 1056 of file Text.java.

1056  {
1057  if (_data != null) { // Primitive.
1058  Text text = Text.newPrimitive(_count);
1059  System.arraycopy(_data, 0, text._data, 0, _count);
1060  return text;
1061  } else { // Composite.
1062  return Text.newComposite((Text) _head.copy(), (Text) _tail.copy());
1063  }
1064  }

References javolution.text.Text._count, javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, javolution.text.Text.copy(), javolution.text.Text.newComposite(), and javolution.text.Text.newPrimitive().

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

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

◆ delete()

Text javolution.text.Text.delete ( int  start,
int  end 
)

Returns the text without the characters between the specified indexes.

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

Definition at line 493 of file Text.java.

493  {
494  if (start > end)
495  throw new IndexOutOfBoundsException();
496  return subtext(0, start).concat(subtext(end));
497  }

References javolution.text.Text.concat(), and javolution.text.Text.subtext().

Here is the call graph for this function:

◆ endsWith()

boolean javolution.text.Text.endsWith ( java.lang.CharSequence  suffix)

Indicates if this text ends with the specified suffix.

Parameters
suffixthe suffix.
Returns
true if the character sequence represented by the argument is a suffix of the character sequence represented by this text; false otherwise.

Definition at line 657 of file Text.java.

657  {
658  return startsWith(suffix, length() - suffix.length());
659  }

References javolution.text.Text.length(), and javolution.text.Text.startsWith().

Here is the call graph for this function:

◆ equals()

boolean javolution.text.Text.equals ( Object  obj)

Compares this text against the specified object for equality. Returns true if the specified object is a text having the same character sequence as this text. For generic comparaison with any character sequence the contentEquals(CharSequence) should be used.

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

Definition at line 769 of file Text.java.

769  {
770  if (this == obj)
771  return true;
772  if (!(obj instanceof Text))
773  return false;
774  final Text that = (Text) obj;
775  if (this._count != that._count)
776  return false;
777  for (int i = 0; i < _count;) {
778  if (this.charAt(i) != that.charAt(i++))
779  return false;
780  }
781  return true;
782  }

References javolution.text.Text._count, javolution.text.Text.charAt(), and javolution.text.Text.Text().

Here is the call graph for this function:

◆ getChars()

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

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

Parameters
startthe index of the first character to copy.
endthe index after the last character to copy.
destthe destination array.
destPosthe start offset in the destination array.
Exceptions
IndexOutOfBoundsExceptionif (start < 0) || (end < 0) || (start > end) || (end > this.length())

Definition at line 1022 of file Text.java.

1022  {
1023  if (_data != null) { // Primitive.
1024  if ((start < 0) || (end > _count) || (start > end))
1025  throw new IndexOutOfBoundsException();
1026  System.arraycopy(_data, start, dest, destPos, end - start);
1027  } else { // Composite.
1028  final int cesure = _head._count;
1029  if (end <= cesure) {
1030  _head.getChars(start, end, dest, destPos);
1031  } else if (start >= cesure) {
1032  _tail.getChars(start - cesure, end - cesure, dest, destPos);
1033  } else { // Overlaps head and tail.
1034  _head.getChars(start, cesure, dest, destPos);
1035  _tail.getChars(0, end - cesure, dest, destPos + cesure - start);
1036  }
1037  }
1038  }

References javolution.text.Text._count, javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, and javolution.text.Text.getChars().

Referenced by javolution.text.TextBuilder.append(), javolution.text.Text.append(), javolution.text.Text.concat(), javolution.text.Text.getChars(), javolution.io.CharSequenceReader.read(), and javolution.text.Text.toString().

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

◆ getDepth()

int javolution.text.Text.getDepth ( )
private

Definition at line 841 of file Text.java.

841  {
842  if (_data != null) // Primitive.
843  return 0;
844  return MathLib.max(_head.getDepth(), _tail.getDepth()) + 1;
845  }

References javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, javolution.text.Text.getDepth(), and javolution.lang.MathLib.max().

Referenced by javolution.text.Text.getDepth(), and javolution.text.Text.printStatistics().

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

◆ getNbrOfBranches()

int javolution.text.Text.getNbrOfBranches ( )
private

Definition at line 847 of file Text.java.

847  {
848  return (_data == null) ? _head.getNbrOfBranches()
849  + _tail.getNbrOfBranches() + 1 : 0;
850  }

References javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, and javolution.text.Text.getNbrOfBranches().

Referenced by javolution.text.Text.getNbrOfBranches(), and javolution.text.Text.printStatistics().

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

◆ getNbrOfLeaves()

int javolution.text.Text.getNbrOfLeaves ( )
private

Definition at line 852 of file Text.java.

852  {
853  return (_data == null) ? _head.getNbrOfLeaves()
854  + _tail.getNbrOfLeaves() : 1;
855  }

References javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, and javolution.text.Text.getNbrOfLeaves().

Referenced by javolution.text.Text.getNbrOfLeaves(), and javolution.text.Text.printStatistics().

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

◆ hashCode()

int javolution.text.Text.hashCode ( )

Returns the hash code for this text.

Returns
the hash code value.

Definition at line 790 of file Text.java.

790  {
791  int h = 0;
792  final int length = this.length();
793  for (int i = 0; i < length;) {
794  h = 31 * h + charAt(i++);
795  }
796  return h;
797  }

References javolution.text.Text.charAt(), and javolution.text.Text.length().

Here is the call graph for this function:

◆ indexOf() [1/4]

int javolution.text.Text.indexOf ( char  c)

Returns the index within this text of the first occurrence of the specified character, starting the search at the beginning.

Parameters
cthe character to search for.
Returns
the index of the first occurrence of the character in this text that is greater than or equal to 0, or -1 if the character does not occur.

Definition at line 913 of file Text.java.

913  {
914  return indexOf(c, 0);
915  }

References javolution.text.Text.indexOf().

Here is the call graph for this function:

◆ indexOf() [2/4]

int javolution.text.Text.indexOf ( char  c,
int  fromIndex 
)

Returns the index within this text of the first occurrence of the specified character, starting the search at the specified index.

Parameters
cthe character to search for.
fromIndexthe index to start the search from.
Returns
the index of the first occurrence of the character in this text that is greater than or equal to fromIndex, or -1 if the character does not occur.

Definition at line 927 of file Text.java.

927  {
928  if (_data != null) { // Primitive.
929  for (int i = MathLib.max(fromIndex, 0); i < _count; i++) {
930  if (_data[i] == c)
931  return i;
932  }
933  return -1;
934  } else { // Composite.
935  final int cesure = _head._count;
936  if (fromIndex < cesure) {
937  final int headIndex = _head.indexOf(c, fromIndex);
938  if (headIndex >= 0)
939  return headIndex; // Found in head.
940  }
941  final int tailIndex = _tail.indexOf(c, fromIndex - cesure);
942  return (tailIndex >= 0) ? tailIndex + cesure : -1;
943  }
944  }

References javolution.text.Text._count, javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, javolution.text.Text.indexOf(), and javolution.lang.MathLib.max().

Here is the call graph for this function:

◆ indexOf() [3/4]

int javolution.text.Text.indexOf ( java.lang.CharSequence  csq)

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

Parameters
csqa character sequence.
Returns
the index of the first character of the character sequence found; or -1 if the character sequence is not found.

Definition at line 552 of file Text.java.

552  {
553  return indexOf(csq, 0);
554  }

Referenced by javolution.text.Text.indexOf(), and javolution.text.Text.replace().

Here is the caller graph for this function:

◆ indexOf() [4/4]

int javolution.text.Text.indexOf ( java.lang.CharSequence  csq,
int  fromIndex 
)

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

Parameters
csqa character sequence.
fromIndexthe index to start the search from.
Returns
the index in the range [fromIndex, length() - csq.length()] or -1 if the character sequence is not found.

Definition at line 567 of file Text.java.

567  {
568 
569  // Limit cases.
570  final int csqLength = csq.length();
571  final int min = Math.max(0, fromIndex);
572  final int max = _count - csqLength;
573  if (csqLength == 0) { return (min > max) ? -1 : min; }
574 
575  // Searches for csq.
576  final char c = csq.charAt(0);
577  for (int i = indexOf(c, min); (i >= 0) && (i <= max); i = indexOf(c,
578  ++i)) {
579  boolean match = true;
580  for (int j = 1; j < csqLength; j++) {
581  if (this.charAt(i + j) != csq.charAt(j)) {
582  match = false;
583  break;
584  }
585  }
586  if (match) { return i; }
587  }
588  return -1;
589  }

References javolution.text.Text._count, javolution.text.Text.charAt(), and javolution.text.Text.indexOf().

Here is the call graph for this function:

◆ indexOfAny() [1/3]

int javolution.text.Text.indexOfAny ( CharSet  charSet)

Returns the index within this text of the first occurrence of any character in the specified character set.

Parameters
charSetthe character set.
Returns
the index of the first character that matches one of the characters in the supplied set; or -1 if none.

Definition at line 1220 of file Text.java.

1220  {
1221  return indexOfAny(charSet, 0, length());
1222  }

References javolution.text.Text.length().

Referenced by javolution.text.Text.indexOfAny(), and javolution.text.Text.replace().

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

◆ indexOfAny() [2/3]

int javolution.text.Text.indexOfAny ( CharSet  charSet,
int  start 
)

Returns the index within a region of this text of the first occurrence of any character in the specified character set.

Parameters
charSetthe character set.
startthe index of the start of the search region in this text.
Returns
the index of the first character that matches one of the characters in the supplied set; or -1 if none.

Definition at line 1233 of file Text.java.

1233  {
1234  return indexOfAny(charSet, start, length() - start);
1235  }

References javolution.text.Text.indexOfAny(), and javolution.text.Text.length().

Here is the call graph for this function:

◆ indexOfAny() [3/3]

int javolution.text.Text.indexOfAny ( CharSet  charSet,
int  start,
int  length 
)

Returns the index within a region of this text of the first occurrence of any character in the specified character set.

Parameters
charSetthe character set.
startthe index of the start of the search region in this text.
lengththe length of the region to search.
Returns
the index of the first character that matches one of the characters in the supplied array; or -1 if none.

Definition at line 1247 of file Text.java.

1247  {
1248  final int stop = start + length;
1249  for (int i = start; i < stop; i++) {
1250  if (charSet.contains(charAt(i)))
1251  return i;
1252  }
1253  return -1;
1254  }

References javolution.text.Text.charAt(), javolution.text.CharSet.contains(), and javolution.text.Text.length().

Here is the call graph for this function:

◆ insert()

Text javolution.text.Text.insert ( int  index,
Text  txt 
)

Returns the text having the specified text inserted at the specified location.

Parameters
indexthe insertion position.
txtthe text being inserted.
Returns
subtext(0, index).concat(txt).concat(subtext(index))
Exceptions
IndexOutOfBoundsExceptionif (index < 0) || (index > this.length())

Definition at line 480 of file Text.java.

480  {
481  return subtext(0, index).concat(txt).concat(subtext(index));
482  }

References javolution.text.Text.concat(), and javolution.text.Text.subtext().

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

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

◆ intern()

Text javolution.text.Text.intern ( )

Returns a text equals to this one from a pool of unique text instances.

Returns
an unique text instance allocated in permanent memory.

Definition at line 707 of file Text.java.

707  {
708  Text txt = INTERN.putIfAbsent(this, this);
709  return txt == null ? this : txt;
710  }

References javolution.text.Text.INTERN.

◆ isBlank() [1/2]

boolean javolution.text.Text.isBlank ( )

Indicates if all characters of this text are whitespaces (no characters greater than the space character).

Returns
true if this text contains only whitespace.

Definition at line 1100 of file Text.java.

1100  {
1101  return isBlank(0, length());
1102  }

References javolution.text.Text.length().

Here is the call graph for this function:

◆ isBlank() [2/2]

boolean javolution.text.Text.isBlank ( int  start,
int  length 
)

Indicates if the specified sub-range of characters of this text are whitespaces (no characters greater than the space character).

Parameters
startthe start index.
lengththe number of characters to inspect.

Definition at line 1111 of file Text.java.

1111  {
1112  for (; start < length; start++) {
1113  if (charAt(start) > ' ')
1114  return false;
1115  }
1116  return true;
1117  }

References javolution.text.Text.charAt(), and javolution.text.Text.length().

Here is the call graph for this function:

◆ lastIndexOf() [1/3]

int javolution.text.Text.lastIndexOf ( char  c,
int  fromIndex 
)

Returns the index within this text of the first occurrence of the specified character, searching backward and starting at the specified index.

Parameters
cthe character to search for.
fromIndexthe index to start the search backward from.
Returns
the index of the first occurrence of the character in this text that is less than or equal to fromIndex, or -1 if the character does not occur.

Definition at line 957 of file Text.java.

957  {
958  if (_data != null) { // Primitive.
959  for (int i = MathLib.min(fromIndex, _count - 1); i >= 0; i--) {
960  if (_data[i] == c)
961  return i;
962  }
963  return -1;
964  } else { // Composite.
965  final int cesure = _head._count;
966  if (fromIndex >= cesure) {
967  final int tailIndex = _tail.lastIndexOf(c, fromIndex - cesure);
968  if (tailIndex >= 0)
969  return tailIndex + cesure; // Found in tail.
970  }
971  return _head.lastIndexOf(c, fromIndex);
972  }
973  }

References javolution.text.Text._count, javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, javolution.text.Text.lastIndexOf(), and javolution.lang.MathLib.min().

Here is the call graph for this function:

◆ lastIndexOf() [2/3]

int javolution.text.Text.lastIndexOf ( java.lang.CharSequence  csq)

Returns the index within this text of the last occurrence of the specified characters sequence searching backward.

Parameters
csqa character sequence.
Returns
the index of the first character of the character sequence found; or -1 if the character sequence is not found.

Definition at line 599 of file Text.java.

599  {
600  return lastIndexOf(csq, _count);
601  }

References javolution.text.Text._count.

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

Here is the caller graph for this function:

◆ lastIndexOf() [3/3]

int javolution.text.Text.lastIndexOf ( java.lang.CharSequence  csq,
int  fromIndex 
)

Returns the index within this text of the last occurrence of the specified character sequence searching backward from the specified index.

Parameters
csqa character sequence.
fromIndexthe index to start the backward search from.
Returns
the index in the range [0, fromIndex] or -1 if the character sequence is not found.

Definition at line 613 of file Text.java.

613  {
614 
615  // Limit cases.
616  final int csqLength = csq.length();
617  final int min = 0;
618  final int max = Math.min(fromIndex, _count - csqLength);
619  if (csqLength == 0) { return (min > max) ? -1 : max; }
620 
621  // Searches for csq.
622  final char c = csq.charAt(0);
623  for (int i = lastIndexOf(c, max); (i >= 0); i = lastIndexOf(c, --i)) {
624  boolean match = true;
625  for (int j = 1; j < csqLength; j++) {
626  if (this.charAt(i + j) != csq.charAt(j)) {
627  match = false;
628  break;
629  }
630  }
631  if (match) { return i; }
632  }
633  return -1;
634 
635  }

References javolution.text.Text._count, javolution.text.Text.charAt(), and javolution.text.Text.lastIndexOf().

Here is the call graph for this function:

◆ lastIndexOfAny() [1/3]

int javolution.text.Text.lastIndexOfAny ( CharSet  charSet)

Returns the index within this text of the last occurrence of any character in the specified character set.

Parameters
charSetthe character set.
Returns
the index of the last character that matches one of the characters in the supplied array; or -1 if none.

Definition at line 1264 of file Text.java.

1264  {
1265  return lastIndexOfAny(charSet, 0, length());
1266  }

References javolution.text.Text.length().

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

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

◆ lastIndexOfAny() [2/3]

int javolution.text.Text.lastIndexOfAny ( CharSet  charSet,
int  start 
)

Returns the index within a region of this text of the last occurrence of any character in the specified character set.

Parameters
charSetthe character set.
startthe index of the start of the search region in this text.
Returns
the index of the last character that matches one of the characters in the supplied array; or -1 if none.

Definition at line 1277 of file Text.java.

1277  {
1278  return lastIndexOfAny(charSet, start, length() - start);
1279  }

References javolution.text.Text.lastIndexOfAny(), and javolution.text.Text.length().

Here is the call graph for this function:

◆ lastIndexOfAny() [3/3]

int javolution.text.Text.lastIndexOfAny ( CharSet  charSet,
int  start,
int  length 
)

Returns the index within a region of this text of the last occurrence of any character in the specified character set.

Parameters
charSetthe character set.
startthe index of the start of the search region in this text.
lengththe length of the region to search.
Returns
the index of the last character that matches one of the characters in the supplied array; or -1 if none.

Definition at line 1291 of file Text.java.

1291  {
1292  for (int i = start + length; --i >= start;) {
1293  if (charSet.contains(charAt(i)))
1294  return i;
1295  }
1296  return -1;
1297  }

References javolution.text.Text.charAt(), javolution.text.CharSet.contains(), and javolution.text.Text.length().

Here is the call graph for this function:

◆ leftRotation()

Text javolution.text.Text.leftRotation ( )
private

Definition at line 447 of file Text.java.

447  {
448  // See: http://en.wikipedia.org/wiki/Tree_rotation
449  Text Q = this._tail;
450  if (Q._data != null)
451  return this; // Tail not a composite, cannot rotate.
452  Text B = Q._head;
453  Text C = Q._tail;
454  Text A = this._head;
455  return Text.newComposite(Text.newComposite(A, B), C);
456  }

References javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, and javolution.text.Text.newComposite().

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

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

◆ length()

int javolution.text.Text.length ( )

◆ newComposite()

static Text javolution.text.Text.newComposite ( Text  head,
Text  tail 
)
staticprivate

Returns a context allocated composite text instance.

Parameters
headthe composite head.
tailthe composite tail.

Definition at line 1320 of file Text.java.

1320  {
1321  Text text = new Text(false);
1322  text._count = head._count + tail._count;
1323  text._head = head;
1324  text._tail = tail;
1325  return text;
1326  }

References javolution.text.Text._count, javolution.text.Text._head, javolution.text.Text._tail, and javolution.text.Text.Text().

Referenced by javolution.text.Text.append(), javolution.text.Text.concat(), javolution.text.Text.copy(), javolution.text.Text.leftRotation(), javolution.text.Text.rightRotation(), javolution.text.Text.toLowerCase(), javolution.text.Text.toUpperCase(), and javolution.text.Text.valueOf().

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

◆ newPrimitive()

static Text javolution.text.Text.newPrimitive ( int  length)
staticprivate

Returns a context allocated primitive text instance.

Parameters
lengththe primitive length.

Definition at line 1307 of file Text.java.

1307  {
1308  Text text = new Text(true);
1309  text._count = length;
1310  return text;
1311  }

References javolution.text.Text._count, javolution.text.Text.length(), and javolution.text.Text.Text().

Referenced by javolution.text.Text.append(), javolution.text.Text.concat(), javolution.text.Text.copy(), javolution.text.Text.subtext(), javolution.text.Text.toLowerCase(), javolution.text.Text.toUpperCase(), and javolution.text.Text.valueOf().

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

◆ padLeft() [1/2]

Text javolution.text.Text.padLeft ( int  len)

Pads this text on the left with spaces to make the minimum total length as specified. The new length of the new text is equal to the original length plus (length()-len) spaces.

Parameters
lenthe total number of characters to make this text equal to.
Returns
a new text or the same text if no padding required.
Exceptions
anIllegalArgumentException if the (len<0).

Definition at line 1160 of file Text.java.

1160  {
1161  return padLeft(len, ' ');
1162  }

◆ padLeft() [2/2]

Text javolution.text.Text.padLeft ( int  len,
char  c 
)

Pads this text on the left to make the minimum total length as specified. Spaces or the given Unicode character are used to pad with.
The new length of the new text is equal to the original length plus (length()-len) pad characters.

Parameters
lenthe total number of characters to make this text equal to.
cthe character to pad using.
Returns
a new text or the same text if no padding required.
Exceptions
anIllegalArgumentException if the (len<0).

Definition at line 1176 of file Text.java.

1176  {
1177  final int padSize = (len <= length()) ? 0 : len - length();
1178  return insert(0, Text.valueOf(c, padSize));
1179  }

References javolution.text.Text.insert(), javolution.text.Text.length(), and javolution.text.Text.valueOf().

Here is the call graph for this function:

◆ padRight() [1/2]

Text javolution.text.Text.padRight ( int  len)

Pads this text on the right with spaces to make the minimum total length as specified. The new length of the new text is equal to the original length plus (length()-len) spaces.

Parameters
lenthe total number of characters to make this text equal to.
Returns
a new text or the same text if no padding required.
Exceptions
anIllegalArgumentException if the (len<0).

Definition at line 1191 of file Text.java.

1191  {
1192  return padRight(len, ' ');
1193  }

◆ padRight() [2/2]

Text javolution.text.Text.padRight ( int  len,
char  c 
)

Pads this text on the right to make the minimum total length as specified. Spaces or the given Unicode character are used to pad with.
The new length of the new text is equal to the original length plus (length()-len) pad characters.

Parameters
lenthe total number of characters to make this text equal to.
cthe character to pad using.
Returns
a new text or the same text if no padding required.
Exceptions
anIllegalArgumentException if the (len<0).

Definition at line 1207 of file Text.java.

1207  {
1208  final int padSize = (len <= length()) ? 0 : len - length();
1209  return concat(Text.valueOf(c, padSize));
1210  }

References javolution.text.Text.concat(), javolution.text.Text.length(), and javolution.text.Text.valueOf().

Here is the call graph for this function:

◆ plus() [1/2]

Text javolution.text.Text.plus ( Object  obj)

Returns the concatenation of this text and the textual representation of the specified object.

Parameters
objthe object whose textual representation is concatenated.
Returns
this.concat(Text.valueOf(obj))

Definition at line 357 of file Text.java.

357  {
358  return this.concat(Text.valueOf(obj));
359  }

References javolution.text.Text.concat(), and javolution.text.Text.valueOf().

Here is the call graph for this function:

◆ plus() [2/2]

Text javolution.text.Text.plus ( String  str)

Returns the concatenation of this text and the specified String (optimization).

Parameters
strthe string whose characters are concatenated.
Returns
this.concat(Text.valueOf(obj))

Definition at line 368 of file Text.java.

368  {
369 
370  Text merge = this.append(str);
371  return merge != null ? merge : concat(Text.valueOf(str));
372  }

References javolution.text.Text.append(), javolution.text.Text.concat(), and javolution.text.Text.valueOf().

Here is the call graph for this function:

◆ printStatistics()

void javolution.text.Text.printStatistics ( PrintStream  out)

Prints the current statistics on this text tree structure.

Parameters
outthe stream to use for output (e.g. System.out)

Definition at line 827 of file Text.java.

827  {
828  int length = this.length();
829  int leaves = getNbrOfLeaves();
830  synchronized (out) {
831  out.print("LENGTH: " + length());
832  out.print(", MAX DEPTH: " + getDepth());
833  out.print(", NBR OF BRANCHES: " + getNbrOfBranches());
834  out.print(", NBR OF LEAVES: " + leaves);
835  out.print(", AVG LEAVE LENGTH: " + (length + (leaves >> 1))
836  / leaves);
837  out.println();
838  }
839  }

References javolution.text.Text.getDepth(), javolution.text.Text.getNbrOfBranches(), javolution.text.Text.getNbrOfLeaves(), and javolution.text.Text.length().

Here is the call graph for this function:

◆ replace() [1/2]

Text javolution.text.Text.replace ( CharSet  charSet,
java.lang.CharSequence  replacement 
)

Replaces the specified characters in this text with the specified replacement sequence.

Parameters
charSetthe set of characters to be replaced.
replacementthe replacement sequence.
Returns
the resulting text.

Definition at line 524 of file Text.java.

524  {
525  int i = indexOfAny(charSet);
526  return (i < 0) ? this : // No character to replace.
527  subtext(0, i).concat(Text.valueOf(replacement)).concat(
528  subtext(i + 1).replace(charSet, replacement));
529  }

References javolution.text.Text.concat(), javolution.text.Text.indexOfAny(), javolution.text.Text.replace(), javolution.text.Text.subtext(), and javolution.text.Text.valueOf().

Here is the call graph for this function:

◆ replace() [2/2]

Text javolution.text.Text.replace ( java.lang.CharSequence  target,
java.lang.CharSequence  replacement 
)

Replaces each character sequence of this text that matches the specified target sequence with the specified replacement sequence.

Parameters
targetthe character sequence to be replaced.
replacementthe replacement sequence.
Returns
the resulting text.

Definition at line 507 of file Text.java.

508  {
509  int i = indexOf(target);
510  return (i < 0) ? this : // No target sequence found.
511  subtext(0, i).concat(Text.valueOf(replacement)).concat(
512  subtext(i + target.length()).replace(target,
513  replacement));
514  }

References javolution.text.Text.concat(), javolution.text.Text.indexOf(), javolution.text.Text.replace(), javolution.text.Text.subtext(), and javolution.text.Text.valueOf().

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

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

◆ rightRotation()

Text javolution.text.Text.rightRotation ( )
private

Definition at line 436 of file Text.java.

436  {
437  // See: http://en.wikipedia.org/wiki/Tree_rotation
438  Text P = this._head;
439  if (P._data != null)
440  return this; // Head not a composite, cannot rotate.
441  Text A = P._head;
442  Text B = P._tail;
443  Text C = this._tail;
444  return Text.newComposite(A, Text.newComposite(B, C));
445  }

References javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, and javolution.text.Text.newComposite().

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

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

◆ startsWith() [1/2]

boolean javolution.text.Text.startsWith ( java.lang.CharSequence  prefix)

Indicates if this text starts with the specified prefix.

Parameters
prefixthe prefix.
Returns
true if the character sequence represented by the argument is a prefix of the character sequence represented by this text; false otherwise.

Definition at line 645 of file Text.java.

645  {
646  return startsWith(prefix, 0);
647  }

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

Here is the caller graph for this function:

◆ startsWith() [2/2]

boolean javolution.text.Text.startsWith ( java.lang.CharSequence  prefix,
int  index 
)

Indicates if this text starts with the specified prefix at the specified index.

Parameters
prefixthe prefix.
indexthe index of the prefix location in this string.
Returns
this.substring(index).startsWith(prefix)

Definition at line 669 of file Text.java.

669  {
670  final int prefixLength = prefix.length();
671  if ((index >= 0) && (index <= (this.length() - prefixLength))) {
672  for (int i = 0, j = index; i < prefixLength;) {
673  if (prefix.charAt(i++) != this.charAt(j++)) { return false; }
674  }
675  return true;
676  } else {
677  return false;
678  }
679  }

References javolution.text.Text.length().

Here is the call graph for this function:

◆ subSequence()

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

Returns subtext(start, end).

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

Definition at line 540 of file Text.java.

540  {
541  return subtext(start, end);
542  }

References javolution.text.Text.subtext().

Here is the call graph for this function:

◆ subtext() [1/2]

Text javolution.text.Text.subtext ( int  start)

Returns a portion of this text.

Parameters
startthe index of the first character inclusive.
Returns
the sub-text starting at the specified position.
Exceptions
IndexOutOfBoundsExceptionif (start < 0) || (start > this.length())

Definition at line 466 of file Text.java.

466  {
467  return subtext(start, length());
468  }

References javolution.text.Text.length().

Referenced by javolution.text.Text.delete(), javolution.text.Text.insert(), javolution.text.Text.replace(), javolution.text.Text.subSequence(), javolution.text.Text.subtext(), javolution.text.Text.trim(), javolution.text.Text.trimEnd(), and javolution.text.Text.trimStart().

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

◆ subtext() [2/2]

Text javolution.text.Text.subtext ( int  start,
int  end 
)

Returns a portion of this text.

Parameters
startthe index of the first character inclusive.
endthe index of the last character exclusive.
Returns
the sub-text starting at the specified start position and ending just before the specified end position.
Exceptions
IndexOutOfBoundsExceptionif (start < 0) || (end < 0) || (start > end) || (end > this.length())

Definition at line 985 of file Text.java.

985  {
986  if (_data != null) { // Primitive.
987  if ((start < 0) || (start > end) || (end > _count))
988  throw new IndexOutOfBoundsException();
989  if ((start == 0) && (end == _count))
990  return this;
991  if (start == end)
992  return Text.EMPTY;
993  int length = end - start;
994  Text text = Text.newPrimitive(length);
995  System.arraycopy(_data, start, text._data, 0, length);
996  return text;
997  } else { // Composite.
998  final int cesure = _head._count;
999  if (end <= cesure)
1000  return _head.subtext(start, end);
1001  if (start >= cesure)
1002  return _tail.subtext(start - cesure, end - cesure);
1003  if ((start == 0) && (end == _count))
1004  return this;
1005  // Overlaps head and tail.
1006  return _head.subtext(start, cesure).concat(
1007  _tail.subtext(0, end - cesure));
1008  }
1009  }

References javolution.text.Text._count, javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, javolution.text.Text.concat(), javolution.text.Text.EMPTY, javolution.text.Text.length(), javolution.text.Text.newPrimitive(), and javolution.text.Text.subtext().

Here is the call graph for this function:

◆ toLowerCase()

Text javolution.text.Text.toLowerCase ( )

Converts the characters of this text to lower case.

Returns
the text in lower case.
See also
Character::toLowerCase(char)

Definition at line 863 of file Text.java.

863  {
864  if (_data == null) // Composite.
865  return Text.newComposite(_head.toLowerCase(), _tail.toLowerCase());
866  Text text = Text.newPrimitive(_count);
867  for (int i = 0; i < _count;) {
868  text._data[i] = Character.toLowerCase(_data[i++]);
869  }
870  return text;
871  }

References javolution.text.Text._count, javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, javolution.text.Text.newComposite(), javolution.text.Text.newPrimitive(), and javolution.text.Text.toLowerCase().

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

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

◆ toString()

String javolution.text.Text.toString ( )

Returns the String representation of this text.

Returns
the java.lang.String for this text.

Definition at line 1045 of file Text.java.

1045  {
1046  if (_data != null) { // Primitive.
1047  return new String(_data, 0, _count);
1048  } else { // Composite.
1049  char[] data = new char[_count];
1050  this.getChars(0, _count, data, 0);
1051  return new String(data, 0, _count);
1052  }
1053  }

References javolution.text.Text._count, javolution.text.Text._data, and javolution.text.Text.getChars().

Here is the call graph for this function:

◆ toText()

Text javolution.text.Text.toText ( )

Returns this (implements Realtime interface).

Returns
this

Definition at line 818 of file Text.java.

818  {
819  return this;
820  }

◆ toUpperCase()

Text javolution.text.Text.toUpperCase ( )

Converts the characters of this text to upper case.

Returns
the text in lower case.
See also
Character::toUpperCase(char)

Definition at line 879 of file Text.java.

879  {
880  if (_data == null) // Composite.
882  Text text = Text.newPrimitive(_count);
883  for (int i = 0; i < _count;) {
884  text._data[i] = Character.toUpperCase(_data[i++]);
885  }
886  return text;
887  }

References javolution.text.Text._count, javolution.text.Text._data, javolution.text.Text._head, javolution.text.Text._tail, javolution.text.Text.newComposite(), javolution.text.Text.newPrimitive(), and javolution.text.Text.toUpperCase().

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

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

◆ trim()

Text javolution.text.Text.trim ( )

Returns a copy of this text, with leading and trailing whitespace omitted.

Returns
a copy of this text with leading and trailing white space removed, or this text if it has no leading or trailing white space.

Definition at line 689 of file Text.java.

689  {
690  int first = 0; // First character index.
691  int last = length() - 1; // Last character index.
692  while ((first <= last) && (charAt(first) <= ' ')) {
693  first++;
694  }
695  while ((last >= first) && (charAt(last) <= ' ')) {
696  last--;
697  }
698  return subtext(first, last + 1);
699  }

References javolution.text.Text.charAt(), javolution.text.Text.length(), and javolution.text.Text.subtext().

Here is the call graph for this function:

◆ trimEnd()

Text javolution.text.Text.trimEnd ( )

Returns a copy of this text, with trailing whitespace omitted.

Returns
a copy of this text with trailing white space removed, or this text if it has no trailing white space.

Definition at line 1141 of file Text.java.

1141  {
1142  int first = 0; // First character index.
1143  int last = length() - 1; // Last character index.
1144  while ((last >= first) && (charAt(last) <= ' ')) {
1145  last--;
1146  }
1147  return subtext(first, last + 1);
1148  }

References javolution.text.Text.charAt(), javolution.text.Text.length(), and javolution.text.Text.subtext().

Here is the call graph for this function:

◆ trimStart()

Text javolution.text.Text.trimStart ( )

Returns a copy of this text, with leading whitespace omitted.

Returns
a copy of this text with leading white space removed, or this text if it has no leading white space.

Definition at line 1125 of file Text.java.

1125  {
1126  int first = 0; // First character index.
1127  int last = length() - 1; // Last character index.
1128  while ((first <= last) && (charAt(first) <= ' ')) {
1129  first++;
1130  }
1131  return subtext(first, last + 1);
1132  }

References javolution.text.Text.charAt(), javolution.text.Text.length(), and javolution.text.Text.subtext().

Here is the call graph for this function:

◆ value()

Text javolution.text.Text.value ( )

Returns

this

.

Implements javolution.lang.ValueType< T >.

Definition at line 1329 of file Text.java.

1329  {
1330  return this;
1331  }

◆ valueOf() [1/16]

static Text javolution.text.Text.valueOf ( boolean  b)
static

Returns the text representation of the boolean argument.

Parameters
ba boolean.
Returns
if the argument is true, the text "true" is returned; otherwise, the text "false" is returned.

Definition at line 226 of file Text.java.

226  {
227  return b ? TRUE : FALSE;
228  }

References javolution.text.Text.FALSE, and javolution.text.Text.TRUE.

◆ valueOf() [2/16]

static Text javolution.text.Text.valueOf ( char  c)
static

Returns the text instance corresponding to the specified character.

Parameters
ca character.
Returns
a text of length 1 containing 'c'.

Definition at line 240 of file Text.java.

240  {
241  Text text = Text.newPrimitive(1);
242  text._data[0] = c;
243  return text;
244  }

References javolution.text.Text._data, and javolution.text.Text.newPrimitive().

Here is the call graph for this function:

◆ valueOf() [3/16]

static Text javolution.text.Text.valueOf ( char  c,
int  length 
)
static

Returns the text that contains a specific length sequence of the character specified.

Parameters
cthe character to fill this text with.
lengththe length of the text returned.
Returns
the corresponding instance.
Exceptions
IndexOutOfBoundsExceptionif (length < 0)

Definition at line 1078 of file Text.java.

1078  {
1079  if (length < 0)
1080  throw new IndexOutOfBoundsException();
1081  if (length <= BLOCK_SIZE) {
1082  Text text = Text.newPrimitive(length);
1083  for (int i = 0; i < length;) {
1084  text._data[i++] = c;
1085  }
1086  return text;
1087  } else {
1088  final int middle = (length >> 1);
1089  return Text.newComposite(Text.valueOf(c, middle),
1090  Text.valueOf(c, length - middle));
1091  }
1092  }

References javolution.text.Text._data, javolution.text.Text.BLOCK_SIZE, javolution.text.Text.length(), javolution.text.Text.newComposite(), javolution.text.Text.newPrimitive(), and javolution.text.Text.valueOf().

Here is the call graph for this function:

◆ valueOf() [4/16]

static Text javolution.text.Text.valueOf ( char[]  chars)
static

Returns the text that contains the characters from the specified array.

Parameters
charsthe array source of the characters.
Returns
the corresponding instance.

Definition at line 168 of file Text.java.

168  {
169  return Text.valueOf(chars, 0, chars.length);
170  }

References javolution.text.Text.valueOf().

Here is the call graph for this function:

◆ valueOf() [5/16]

static Text javolution.text.Text.valueOf ( char[]  chars,
int  offset,
int  length 
)
static

Returns the text that contains the characters from the specified subarray of characters.

Parameters
charsthe source of the characters.
offsetthe index of the first character in the data soure.
lengththe length of the text returned.
Returns
the corresponding instance.
Exceptions
IndexOutOfBoundsExceptionif (offset < 0) || (length < 0) || ((offset + length) > chars.length)

Definition at line 183 of file Text.java.

183  {
184  if ((offset < 0) || (length < 0) || ((offset + length) > chars.length))
185  throw new IndexOutOfBoundsException();
186  if (length <= BLOCK_SIZE) {
187  Text text = Text.newPrimitive(length);
188  System.arraycopy(chars, offset, text._data, 0, length);
189  return text;
190  } else { // Splits on a block boundary.
191  int half = ((length + BLOCK_SIZE) >> 1) & BLOCK_MASK;
192  return Text.newComposite(Text.valueOf(chars, offset, half),
193  Text.valueOf(chars, offset + half, length - half));
194  }
195  }

References javolution.text.Text._data, javolution.text.Text.BLOCK_MASK, javolution.text.Text.BLOCK_SIZE, javolution.text.Text.length(), javolution.text.Text.newComposite(), javolution.text.Text.newPrimitive(), and javolution.text.Text.valueOf().

Here is the call graph for this function:

◆ valueOf() [6/16]

static Text javolution.text.Text.valueOf ( double  d)
static

Returns the textual representation of the specified double argument.

Parameters
dthe double to format.
Returns
the corresponding text instance.

Definition at line 315 of file Text.java.

315  {
316  TextBuilder tb = new TextBuilder();
317  return tb.append(d).toText();
318  }

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

Here is the call graph for this function:

◆ valueOf() [7/16]

static Text javolution.text.Text.valueOf ( double  d,
int  digits,
boolean  scientific,
boolean  showZero 
)
static

Returns the textual representation of the specified double argument formatted as specified.

Parameters
dthe double to format.
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
the corresponding text instance.
Exceptions
IllegalArgumentExceptionif (digits > 19))

Definition at line 335 of file Text.java.

336  {
337  TextBuilder tb = new TextBuilder();
338  return tb.append(d, digits, scientific, showZero).toText();
339  }

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

Here is the call graph for this function:

◆ valueOf() [8/16]

static Text javolution.text.Text.valueOf ( float  f)
static

Returns the textual representation of the specified float instance.

Parameters
fthe float to format.
Returns
the corresponding text instance.

Definition at line 303 of file Text.java.

303  {
304  TextBuilder tb = new TextBuilder();
305  return tb.append(f).toText();
306  }

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

Here is the call graph for this function:

◆ valueOf() [9/16]

static Text javolution.text.Text.valueOf ( int  i)
static

Returns the decimal representation of the specified int argument.

Parameters
ithe int to format.
Returns
the corresponding text instance.

Definition at line 253 of file Text.java.

253  {
254  TextBuilder tb = new TextBuilder();
255  return tb.append(i).toText();
256  }

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

Here is the call graph for this function:

◆ valueOf() [10/16]

static Text javolution.text.Text.valueOf ( int  i,
int  radix 
)
static

Returns the radix representation of the specified int argument.

Parameters
ithe int to format.
radixthe radix (e.g. 16 for hexadecimal).
Returns
the corresponding text instance.

Definition at line 266 of file Text.java.

266  {
267  TextBuilder tb = new TextBuilder();
268  return tb.append(i, radix).toText();
269  }

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

Here is the call graph for this function:

◆ valueOf() [11/16]

static Text javolution.text.Text.valueOf ( long  l)
static

Returns the decimal representation of the specified long argument.

Parameters
lthe long to format.
Returns
the corresponding text instance.

Definition at line 278 of file Text.java.

278  {
279  TextBuilder tb = new TextBuilder();
280  return tb.append(l).toText();
281  }

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

Here is the call graph for this function:

◆ valueOf() [12/16]

static Text javolution.text.Text.valueOf ( long  l,
int  radix 
)
static

Returns the radix representation of the specified long argument.

Parameters
lthe long to format.
radixthe radix (e.g. 16 for hexadecimal).
Returns
the corresponding text instance.

Definition at line 291 of file Text.java.

291  {
292  TextBuilder tb = new TextBuilder();
293  return tb.append(l, radix).toText();
294  }

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

Here is the call graph for this function:

◆ valueOf() [13/16]

static Text javolution.text.Text.valueOf ( Object  obj)
static

Returns the text representing the specified object.

Parameters
objthe object to represent as text.
Returns
new TextBuilder().append(obj).toText()

Definition at line 140 of file Text.java.

140  {
141  return new TextBuilder().append(obj).toText();
142  }

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

Referenced by javolution.text.Text.padLeft(), javolution.text.Text.padRight(), javolution.text.Text.plus(), javolution.text.Text.replace(), javolution.text.TextBuilder.subSequence(), javolution.text.TextBuilder.toText(), javolution.text.Text.valueOf(), and javolution.io.AppendableWriter.write().

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

◆ valueOf() [14/16]

static Text javolution.text.Text.valueOf ( String  str)
staticprivate

Definition at line 144 of file Text.java.

144  {
145  return Text.valueOf(str, 0, str.length());
146  }

References javolution.text.Text.valueOf().

Here is the call graph for this function:

◆ valueOf() [15/16]

static Text javolution.text.Text.valueOf ( String  str,
int  start,
int  end 
)
staticprivate

Definition at line 148 of file Text.java.

148  {
149  int length = end - start;
150  if (length <= BLOCK_SIZE) {
151  Text text = newPrimitive(length);
152  str.getChars(start, end, text._data, 0);
153  return text;
154  } else { // Splits on a block boundary.
155  int half = ((length + BLOCK_SIZE) >> 1) & BLOCK_MASK;
156  return newComposite(Text.valueOf(str, start, start + half),
157  Text.valueOf(str, start + half, end));
158  }
159  }

References javolution.text.Text._data, javolution.text.Text.BLOCK_MASK, javolution.text.Text.BLOCK_SIZE, javolution.text.Text.length(), javolution.text.Text.newComposite(), javolution.text.Text.newPrimitive(), and javolution.text.Text.valueOf().

Here is the call graph for this function:

◆ valueOf() [16/16]

static Text javolution.text.Text.valueOf ( TextBuilder  tb,
int  start,
int  end 
)
staticpackage

Converts a text builder to a text instance (optimization for TextBuilder.toText()).

Parameters
startthe index of the first character inclusive.
endthe index of the last character exclusive.
Returns
the corresponding text instance.

Definition at line 205 of file Text.java.

205  {
206  int length = end - start;
207  if (length <= BLOCK_SIZE) {
208  Text text = Text.newPrimitive(length);
209  tb.getChars(start, end, text._data, 0);
210  return text;
211  } else { // Splits on a block boundary.
212  int half = ((length + BLOCK_SIZE) >> 1) & BLOCK_MASK;
213  return Text.newComposite(Text.valueOf(tb, start, start + half),
214  Text.valueOf(tb, start + half, end));
215  }
216  }

References javolution.text.Text._data, javolution.text.Text.BLOCK_MASK, javolution.text.Text.BLOCK_SIZE, javolution.text.TextBuilder.getChars(), javolution.text.Text.length(), javolution.text.Text.newComposite(), javolution.text.Text.newPrimitive(), and javolution.text.Text.valueOf().

Here is the call graph for this function:

Member Data Documentation

◆ _count

◆ _data

◆ _head

◆ _tail

◆ BLOCK_MASK

final int javolution.text.Text.BLOCK_MASK = ~(BLOCK_SIZE - 1)
staticprivate

Holds the mask used to ensure a block boundary cesures.

Definition at line 74 of file Text.java.

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

◆ BLOCK_SIZE

final int javolution.text.Text.BLOCK_SIZE = 1 << 5
staticprivate

Holds the default size for primitive blocks of characters.

Definition at line 69 of file Text.java.

Referenced by javolution.text.Text.append(), javolution.text.Text.concat(), javolution.text.Text.Text(), and javolution.text.Text.valueOf().

◆ EMPTY

final Text javolution.text.Text.EMPTY = new Text("").intern()
static

Holds an empty character sequence.

Definition at line 85 of file Text.java.

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

◆ FALSE

final Text javolution.text.Text.FALSE = new Text("false").intern()
staticprivate

Definition at line 232 of file Text.java.

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

◆ INTERN

final FastMap<Text, Text> javolution.text.Text.INTERN
staticprivate
Initial value:
= new FastMap<Text, Text>()
.shared()

Holds the texts interned in immortal memory.

Definition at line 79 of file Text.java.

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

◆ serialVersionUID

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

Definition at line 64 of file Text.java.

◆ TRUE

final Text javolution.text.Text.TRUE = new Text("true").intern()
staticprivate

Definition at line 230 of file Text.java.

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


The documentation for this class was generated from the following file:
javolution.text.Text.length
int length()
Definition: Text.java:346
javolution.text.Text.BLOCK_MASK
static final int BLOCK_MASK
Definition: Text.java:74
javolution.text.Text.charAt
char charAt(int index)
Definition: Text.java:897
javolution.text.Text.newComposite
static Text newComposite(Text head, Text tail)
Definition: Text.java:1320
javolution.text.Text.copy
Text copy()
Definition: Text.java:1056
javolution.text.Text.newPrimitive
static Text newPrimitive(int length)
Definition: Text.java:1307
javolution.text.Text.TRUE
static final Text TRUE
Definition: Text.java:230
javolution.text.Text._data
final char[] _data
Definition: Text.java:90
javolution.text.Text.isBlank
boolean isBlank()
Definition: Text.java:1100
javolution.text.Text.Text
Text(boolean isPrimitive)
Definition: Text.java:112
javolution.text.Text._head
Text _head
Definition: Text.java:100
javolution.text.Text._tail
Text _tail
Definition: Text.java:105
javolution.text.Text.indexOfAny
int indexOfAny(CharSet charSet)
Definition: Text.java:1220
javolution.text.Text.insert
Text insert(int index, Text txt)
Definition: Text.java:480
javolution.text.Text._count
int _count
Definition: Text.java:95
javolution.text.Text.subtext
Text subtext(int start)
Definition: Text.java:466
javolution.text.Text.padRight
Text padRight(int len)
Definition: Text.java:1191
javolution.text.Text.lastIndexOfAny
int lastIndexOfAny(CharSet charSet)
Definition: Text.java:1264
javolution.text.Text.BLOCK_SIZE
static final int BLOCK_SIZE
Definition: Text.java:69
javolution.text.Text.replace
Text replace(java.lang.CharSequence target, java.lang.CharSequence replacement)
Definition: Text.java:507
javolution.text.Text.concat
Text concat(Text that)
Definition: Text.java:398
javolution.text.Text.toUpperCase
Text toUpperCase()
Definition: Text.java:879
javolution.text.Text.getChars
void getChars(int start, int end, char dest[], int destPos)
Definition: Text.java:1022
javolution.text.Text.padLeft
Text padLeft(int len)
Definition: Text.java:1160
javolution.text.Text.toLowerCase
Text toLowerCase()
Definition: Text.java:863
javolution.text.Text.getDepth
int getDepth()
Definition: Text.java:841
javolution.text.Text.getNbrOfLeaves
int getNbrOfLeaves()
Definition: Text.java:852
javolution.text.Text.getNbrOfBranches
int getNbrOfBranches()
Definition: Text.java:847
javolution.text.Text.lastIndexOf
int lastIndexOf(java.lang.CharSequence csq)
Definition: Text.java:599
javolution.text.Text.FALSE
static final Text FALSE
Definition: Text.java:232
javolution.text.Text.startsWith
boolean startsWith(java.lang.CharSequence prefix)
Definition: Text.java:645
javolution.text.Text.INTERN
static final FastMap< Text, Text > INTERN
Definition: Text.java:79
javolution.text.Text.indexOf
int indexOf(java.lang.CharSequence csq)
Definition: Text.java:552
javolution.text.Text.append
Text append(String str)
Definition: Text.java:374