A StringConcatenation allows for efficient, indentation aware concatenation of character sequences.
In addition to the methods that are specified by the implemented interface CharSequence, there are some other
public operations that allow to modify the contents of this sequence. The string representation of arbitrary objects
can be appended to an instance of StringConcatenation. There are overloaded variants of
append(Object, String) that allow to pass an indentation that should be applied to each line of the appended
content. Each line break that is part of the new content will be replaced by the line delimiter that was configured
for this StringConcatenation.
The append-operation ignores null arguments. This is different to what
StringBuffer or StringBuilder do and that's the reason why the Appendable interface is not
fulfilled by a StringConcatenation.
The object uses an internal List of Strings that is concatenated on demand to a complete
sequence. Use toString() to get the joined version of a StringConcatenation.
equals(Object) and hashCode() are not specialized for a StringConcatenation, that is, the
semantics are based on identity similar to what StringBuffer and StringBuilder do.
| Modifier and Type | Class and Description |
|---|---|
| private static class | StringConcatenation.
Decorates an existing |
| private static class | StringConcatenation.
Decorates an existing |
| Modifier and Type | Field and Description |
|---|---|
| private String | cachedToString
A cached string representation. |
| public static final String | DEFAULT_LINE_DELIMITER
The default line delimiter that is used by instances of |
| private int | lastSegmentsSize
Internal hint for the size of segments. |
| private final String | lineDelimiter
The configured delimiter. |
| private final ArrayList | segments
The complete content of this sequence. |
| private static final int | SEGMENTS_INITIAL_SIZE
Initial allocation size of the |
| private static final int | SEGMENTS_SIZE_INCREMENT
Number of elements to add to |
| Access | Constructor and Description |
|---|---|
| public | |
| public | StringConcatenation(String
the used delimiter. lineDelimiter)Create a new concatenation with the specified delimiter. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public void | append(StringConcatenation
the to-be-appended StringConcatenation. concat)Append the contents of a given StringConcatenation to this sequence. |
| public void | append(StringConcatenationClient
the to-be-appended StringConcatenationClient. client)Append the contents of a given StringConcatenationClient to this sequence. |
| protected void | |
| private void | |
| public void | |
| public void | |
| public void | append(StringConcatenation
the to-be-appended StringConcatenation. concat, String the indentation string that should be prepended. May not be indentation)null.Append the contents of a given StringConcatenation to this sequence. |
| public void | append(StringConcatenationClient
the to-be-appended StringConcatenationClient. client, String the indentation string that should be prepended. May not be indentation)null.Append the contents of a given StringConcatenationClient to this sequence. |
| protected void | |
| private void | |
| public void | appendImmediate(Object
the to-be-appended object. object, String the indentation string that should be prepended. May not be indentation)null.Add the string representation of the given object to this sequence immediately. |
| private void | |
| protected void | appendSegments(String
the indentation string that should be prepended. May not be indentation, int null.the index in this instance's list of segments. index, List<String> the to-be-appended segments. May not be otherSegments, String null.the line delimiter that was used in the otherSegments list. otherDelimiter)Add the list of segments to this sequence at the given index. |
| protected void | appendSegments(int
the index in this instance's list of segments. index, List<String> the to-be-appended segments. May not be otherSegments, String null.the line delimiter that was used in the otherSegments list. otherDelimiter)Add the list of segments to this sequence at the given index. |
| protected void | appendSegments(int
the index in this instance's list of segments. index, List<String> the to-be-appended segments. May not be otherSegments)null.Add the list of segments to this sequence at the given index. |
| public char | charAt(int index)
Implements java. Returns the |
| private List | |
| protected final List | Returns: the actual content of this instance. Nevernull.Return the actual content of this sequence, including all trailing whitespace. |
| protected String | Returns: the line delimiterAllows subtypes to access the configured line delimiter. |
| protected List | Returns: the significant content of this instance. Nevernull.Compute the significant content of this sequence. |
| protected String | Returns: the string representation. May not benull.the object that shall be appended. Never object)null.Computes the string representation of the given object. |
| private void | |
| private static int | |
| public int | |
| public void | |
| public void | newLineIfNotEmpty()
Add a newline to this sequence according to the configured lineDelimiter if the last line contains something besides whitespace. |
| protected List | Returns: a list of segments. Is nevernull.the to-be-splitted text. May be text)null.Return a list of segments where each segment is either the content of a line in the given text or a line-break according to the configured delimiter. |
| public CharSequence | subSequence(int start, int end)
Implements java. Returns a |
| public String | toString()
Overrides java. Implements java. Returns a string containing the characters in this sequence in the same order as this sequence. |
| cachedToString | back to summary |
|---|---|
| private String cachedToString A cached string representation. | |
| DEFAULT_LINE_DELIMITER | back to summary |
|---|---|
| public static final String DEFAULT_LINE_DELIMITER The default line delimiter that is used by instances of
| |
| lastSegmentsSize | back to summary |
|---|---|
| private int lastSegmentsSize Internal hint for the size of segments. We cache this value so we do not have to perform costly calculations. | |
| lineDelimiter | back to summary |
|---|---|
| private final String lineDelimiter The configured delimiter. It will be used to replace possibly existing delimiters of to-be-appended content. | |
| segments | back to summary |
|---|---|
| private final ArrayList<String> segments The complete content of this sequence. It may contain insignificant trailing parts that are not part of the final
string representation that can be obtained by | |
| SEGMENTS_INITIAL_SIZE | back to summary |
|---|---|
| private static final int SEGMENTS_INITIAL_SIZE Initial allocation size of the | |
| SEGMENTS_SIZE_INCREMENT | back to summary |
|---|---|
| private static final int SEGMENTS_SIZE_INCREMENT Number of elements to add to | |
| StringConcatenation | back to summary |
|---|---|
| public StringConcatenation() Create a new concatenation that uses the system line delimiter. | |
| StringConcatenation | back to summary |
|---|---|
| public StringConcatenation(String lineDelimiter) Create a new concatenation with the specified delimiter.
| |
| append | back to summary |
|---|---|
| public void append(Object object) Append the string representation of the given object to this sequence. Does nothing if the object is
| |
| append | back to summary |
|---|---|
| public void append(String str) Append the given string to this sequence. Does nothing if the string is
| |
| append | back to summary |
|---|---|
| public void append(StringConcatenation concat) Append the contents of a given StringConcatenation to this sequence. Does nothing
if the concatenation is
| |
| append | back to summary |
|---|---|
| public void append(StringConcatenationClient client) Append the contents of a given StringConcatenationClient to this sequence. Does nothing
if the argument is
| |
| append | back to summary |
|---|---|
| protected void append(Object object, int index) | |
| append | back to summary |
|---|---|
| private void append(String text, int index) | |
| append | back to summary |
|---|---|
| public void append(Object object, String indentation) Add the string representation of the given object to this sequence. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation. | |
| append | back to summary |
|---|---|
| public void append(String str, String indentation) Add the given string to this sequence. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation. | |
| append | back to summary |
|---|---|
| public void append(StringConcatenation concat, String indentation) Append the contents of a given StringConcatenation to this sequence. Does nothing
if the concatenation is
| |
| append | back to summary |
|---|---|
| public void append(StringConcatenationClient client, String indentation) Append the contents of a given StringConcatenationClient to this sequence. Does nothing
if that argument is
| |
| append | back to summary |
|---|---|
| protected void append(Object object, String indentation, int index) Add the string representation of the given object to this sequence at the given index. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation. | |
| append | back to summary |
|---|---|
| private void append(String indentation, String text, int index) | |
| appendImmediate | back to summary |
|---|---|
| public void appendImmediate(Object object, String indentation) Add the string representation of the given object to this sequence immediately. That is, all the trailing whitespace of this sequence will be ignored and the string is appended directly after the last segment that contains something besides whitespace. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation. | |
| appendSegment | back to summary |
|---|---|
| private void appendSegment(int index, String segment) | |
| appendSegments | back to summary |
|---|---|
| protected void appendSegments(String indentation, int index, List<String> otherSegments, String otherDelimiter) Add the list of segments to this sequence at the given index. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation.
| |
| appendSegments | back to summary |
|---|---|
| protected void appendSegments(int index, List<String> otherSegments, String otherDelimiter) Add the list of segments to this sequence at the given index. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation. | |
| appendSegments | back to summary |
|---|---|
| protected void appendSegments(int index, List<String> otherSegments) Add the list of segments to this sequence at the given index. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation. | |
| charAt | back to summary |
|---|---|
| public char charAt(int index) Implements java. Doc from java. Returns the If the Only the significant content of this sequence is considered.
| |
| continueSplitting | back to summary |
|---|---|
| private List | |
| getContent | back to summary |
|---|---|
| protected final List Return the actual content of this sequence, including all trailing whitespace. The return value is unsafe,
that is modification to this | |
| getLineDelimiter | back to summary |
|---|---|
| protected String getLineDelimiter() Allows subtypes to access the configured line delimiter.
| |
| getSignificantContent | back to summary |
|---|---|
| protected List Compute the significant content of this sequence. That is, trailing whitespace after the last line-break will be
ignored if the last line contains only whitespace. The return value is unsafe, that is modification to this
| |
| getStringRepresentation | back to summary |
|---|---|
| protected String getStringRepresentation(Object object) Computes the string representation of the given object. The default implementation
will just invoke | |
| growSegments | back to summary |
|---|---|
| private void growSegments(int increment) | |
| initialSegmentSize | back to summary |
|---|---|
| private static int initialSegmentSize(String text) | |
| length | back to summary |
|---|---|
| public int length() Implements java. Doc from java. Returns the length of this character sequence. The length is the number
of 16-bit Only the significant content of this sequence is considered.
| |
| newLine | back to summary |
|---|---|
| public void newLine() Add a newline to this sequence according to the configured lineDelimiter. | |
| newLineIfNotEmpty | back to summary |
|---|---|
| public void newLineIfNotEmpty() Add a newline to this sequence according to the configured lineDelimiter if the last line contains something besides whitespace. | |
| splitLinesAndNewLines | back to summary |
|---|---|
| protected List Return a list of segments where each segment is either the content of a line in the given text or a line-break according to the configured delimiter. Existing line-breaks in the text will be replaced by this's instances delimiter. | |
| subSequence | back to summary |
|---|---|
| public CharSequence subSequence(int start, int end) Implements java. Doc from java. Returns a Only the significant content of this sequence is considered.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Implements java. Doc from java. Returns a string containing the characters in this sequence in the same order as this sequence. The length of the string will be the length of this sequence.
| |
StringConcatenation as a TargetStringConcatenation.
This implementation keeps track of the current indentation at the position where
the clients should write into the decorated StringConcatenation.
| Modifier and Type | Field and Description |
|---|---|
| private final String |
| Access | Constructor and Description |
|---|---|
| private |
| indentation | back to summary |
|---|---|
| private final String indentation | |
| IndentedTarget | back to summary |
|---|---|
| private IndentedTarget(StringConcatenation target, String indentation, int index) | |
| append | back to summary |
|---|---|
| public void append(Object object, String indentation) Overrides org. Implements org. Doc from org. Add the string representation of the given object to this sequence. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation.
| |
| append | back to summary |
|---|---|
| public void append(Object object) Overrides org. Implements org. Doc from org. Append the string representation of the given object to this sequence. Does nothing if the object is
| |
| appendImmediate | back to summary |
|---|---|
| public void appendImmediate(Object object, String indentation) Overrides org. Implements org. Doc from org. Add the string representation of the given object to this sequence immediately. That is, all the trailing whitespace of this sequence will be ignored and the string is appended directly after the last segment that contains something besides whitespace. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation.
| |
| newLine | back to summary |
|---|---|
| public void newLine() Overrides org. Implements org. Doc from org. Add a newline to this sequence according to the configured lineDelimiter.
| |
| newLineIfNotEmpty | back to summary |
|---|---|
| public void newLineIfNotEmpty() Overrides org. Implements org. Doc from org. Add a newline to this sequence according to the configured lineDelimiter if the last line contains something besides whitespace.
| |
StringConcatenation as a TargetStringConcatenation.
It maintains the index at which new elements should inserted into the existing concatenation.
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| private final StringConcatenation |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | append(Object object, String indentation)
Implements org. Add the string representation of the given object to this sequence. |
| public void | append(Object object)
Implements org. Append the string representation of the given object to this sequence. |
| public void | appendImmediate(Object object, String indentation)
Implements org. Add the string representation of the given object to this sequence immediately. |
| public char | charAt(int index)
Implements java. Returns the |
| public int | |
| public void | newLine()
Implements org. Add a newline to this sequence according to the configured lineDelimiter. |
| public void | newLineIfNotEmpty()
Implements org. Add a newline to this sequence according to the configured lineDelimiter if the last line contains something besides whitespace. |
| public CharSequence | subSequence(int start, int end)
Implements java. Returns a |
| offsetFixup | back to summary |
|---|---|
| private final int offsetFixup | |
| target | back to summary |
|---|---|
| private final StringConcatenation target | |
| SimpleTarget | back to summary |
|---|---|
| private SimpleTarget(StringConcatenation target, int index) | |
| append | back to summary |
|---|---|
| public void append(Object object, String indentation) Implements org. Doc from org. Add the string representation of the given object to this sequence. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation.
| |
| append | back to summary |
|---|---|
| public void append(Object object) Implements org. Doc from org. Append the string representation of the given object to this sequence. Does nothing if the object is
| |
| appendImmediate | back to summary |
|---|---|
| public void appendImmediate(Object object, String indentation) Implements org. Doc from org. Add the string representation of the given object to this sequence immediately. That is, all the trailing whitespace of this sequence will be ignored and the string is appended directly after the last segment that contains something besides whitespace. The given indentation will be prepended to each line except the first one if the object has a multi-line string representation.
| |
| charAt | back to summary |
|---|---|
| public char charAt(int index) Implements java. Doc from java. Returns the If the
| |
| length | back to summary |
|---|---|
| public int length() Implements java. Doc from java. Returns the length of this character sequence. The length is the number
of 16-bit
| |
| newLine | back to summary |
|---|---|
| public void newLine() Implements org. Doc from org. Add a newline to this sequence according to the configured lineDelimiter.
| |
| newLineIfNotEmpty | back to summary |
|---|---|
| public void newLineIfNotEmpty() Implements org. Doc from org. Add a newline to this sequence according to the configured lineDelimiter if the last line contains something besides whitespace.
| |
| subSequence | back to summary |
|---|---|
| public CharSequence subSequence(int start, int end) Implements java. Doc from java. Returns a
| |