Class FormattedStringBuilder
java.lang.Object
org.graalvm.shadowed.com.ibm.icu.impl.FormattedStringBuilder
- All Implemented Interfaces:
Appendable, CharSequence
A StringBuilder optimized for formatting. It implements the following key features beyond a
normal JDK StringBuilder:
- Efficient prepend as well as append.
- Keeps tracks of Fields in an efficient manner.
- String operations are fast-pathed to code point operations when possible.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FormattedStringBuilderA constant, empty FormattedStringBuilder. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend(char c) This method is provided for Java Appendable compatibility.intAppends the chars in the specified char array to the end of the string, and associates them with the fields in the specified field array, which must have the same length as chars.append(CharSequence csq) This method is provided for Java Appendable compatibility.append(CharSequence csq, int start, int end) This method is provided for Java Appendable compatibility.intappend(CharSequence sequence, Object field) Appends the specified CharSequence to the end of the string.intappend(FormattedStringBuilder other) Appends the contents of anotherFormattedStringBuilderto the end of this instance.intappendChar16(char codeUnit, Object field) intappendCodePoint(int codePoint, Object field) Appends the specified codePoint to the end of the string.charcharAt(int index) clear()intcodePointAt(int index) intcodePointBefore(int index) intbooleancontentEquals(char[] chars, Object[] fields) booleanvoidcopyFrom(FormattedStringBuilder source) booleanfieldAt(int index) intintinthashCode()intInserts the chars in the specified char array at the specified index in the string, and associates them with the fields in the specified field array, which must have the same length as chars.intinsert(int index, CharSequence sequence, int start, int end, Object field) Inserts the specified CharSequence at the specified index in the string, reading from the CharSequence from start (inclusive) to end (exclusive).intinsert(int index, CharSequence sequence, Object field) Inserts the specified CharSequence at the specified index in the string.intinsert(int index, FormattedStringBuilder other) Inserts the contents of anotherFormattedStringBuilderinto this instance at the given index.intinsertChar16(int index, char codeUnit, Object field) intinsertCodePoint(int index, int codePoint, Object field) Inserts the specified codePoint at the specified index in the string.intlength()voidsetAppendableField(Object field) Call this method before using any of the Appendable overrides.voidsetAppendIndex(int index) Sets the index at which append operations insert.intsplice(int startThis, int endThis, CharSequence sequence, int startOther, int endOther, Object field) Replaces the chars between startThis and endThis with the chars between startOther and endOther of the given CharSequence.subSequence(int start, int end) Deprecated.subString(int start, int end) Use this instead of subSequence if returning publicly.char[]Returns a string that includes field information, for debugging purposes.Object[]toString()Returns the string represented by the characters in this string builder.static Format.FieldunwrapField(Object field) Methods inherited from interface CharSequence
chars, codePoints, getChars, isEmpty
-
Field Details
-
EMPTY
A constant, empty FormattedStringBuilder. Do NOT call mutative operations on this.
-
-
Constructor Details
-
FormattedStringBuilder
public FormattedStringBuilder() -
FormattedStringBuilder
public FormattedStringBuilder(int capacity) -
FormattedStringBuilder
-
-
Method Details
-
unwrapField
-
copyFrom
-
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
codePointCount
public int codePointCount() -
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
fieldAt
-
getFirstCodePoint
public int getFirstCodePoint() -
getLastCodePoint
public int getLastCodePoint() -
codePointAt
public int codePointAt(int index) -
codePointBefore
public int codePointBefore(int index) -
clear
-
setAppendIndex
public void setAppendIndex(int index) Sets the index at which append operations insert. Defaults to the end.- Parameters:
index- The index at which append operations should insert.
-
appendChar16
-
insertChar16
-
appendCodePoint
Appends the specified codePoint to the end of the string.- Returns:
- The number of chars added: 1 if the code point is in the BMP, or 2 otherwise.
-
insertCodePoint
Inserts the specified codePoint at the specified index in the string.- Returns:
- The number of chars added: 1 if the code point is in the BMP, or 2 otherwise.
-
append
Appends the specified CharSequence to the end of the string.- Returns:
- The number of chars added, which is the length of CharSequence.
-
insert
Inserts the specified CharSequence at the specified index in the string.- Returns:
- The number of chars added, which is the length of CharSequence.
-
insert
Inserts the specified CharSequence at the specified index in the string, reading from the CharSequence from start (inclusive) to end (exclusive).- Returns:
- The number of chars added, which is the length of CharSequence.
-
splice
public int splice(int startThis, int endThis, CharSequence sequence, int startOther, int endOther, Object field) Replaces the chars between startThis and endThis with the chars between startOther and endOther of the given CharSequence. Calling this method with startThis == endThis is equivalent to calling insert.- Returns:
- The number of chars added, which may be negative if the removed segment is longer than the length of the CharSequence segment that was inserted.
-
append
Appends the chars in the specified char array to the end of the string, and associates them with the fields in the specified field array, which must have the same length as chars.- Returns:
- The number of chars added, which is the length of the char array.
-
insert
Inserts the chars in the specified char array at the specified index in the string, and associates them with the fields in the specified field array, which must have the same length as chars.- Returns:
- The number of chars added, which is the length of the char array.
-
append
Appends the contents of anotherFormattedStringBuilderto the end of this instance.- Returns:
- The number of chars added, which is the length of the other
FormattedStringBuilder.
-
insert
Inserts the contents of anotherFormattedStringBuilderinto this instance at the given index.- Returns:
- The number of chars added, which is the length of the other
FormattedStringBuilder.
-
subSequence
Deprecated.Note: this returns a FormattedStringBuilder. Do not return publicly.- Specified by:
subSequencein interfaceCharSequence
-
subString
Use this instead of subSequence if returning publicly. -
toString
Returns the string represented by the characters in this string builder.For a string intended be used for debugging, use
toDebugString().- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
toDebugString
Returns a string that includes field information, for debugging purposes.For example, if the string is "-12.345", the debug string will be something like "<FormattedStringBuilder [-123.45] [-iii.ff]>"
- Returns:
- A string for debugging purposes.
-
toCharArray
public char[] toCharArray()- Returns:
- A new array containing the contents of this string builder.
-
toFieldArray
- Returns:
- A new array containing the field values of this string builder.
-
setAppendableField
Call this method before using any of the Appendable overrides.- Parameters:
field- The field used when inserting strings.
-
append
This method is provided for Java Appendable compatibility. In most cases, please use the append methods that take a Field parameter. If you do use this method, you must callsetAppendableField(Object)first.- Specified by:
appendin interfaceAppendable
-
append
This method is provided for Java Appendable compatibility. In most cases, please use the append methods that take a Field parameter. If you do use this method, you must callsetAppendableField(Object)first.- Specified by:
appendin interfaceAppendable
-
append
This method is provided for Java Appendable compatibility. In most cases, please use the append methods that take a Field parameter. If you do use this method, you must callsetAppendableField(Object)first.- Specified by:
appendin interfaceAppendable
-
contentEquals
- Returns:
- Whether the contents and field values of this string builder are equal to the given chars and fields.
- See Also:
-
contentEquals
- Parameters:
other- The instance to compare.- Returns:
- Whether the contents of this instance is currently equal to the given instance.
-
hashCode
-
equals
-