Package com.mapr.utils
Class IndentingStringBuilder
java.lang.Object
com.mapr.utils.IndentingStringBuilder
- Direct Known Subclasses:
PlainStringBuilder,PrependingStringBuilder,PrettyStringBuilder
Abstract class for building wrappers around StringBuilder that can be used to
pre-format pretty-printed output for debugging purposes.
The IndentingStringBuilder class is defined in such a way as to support writing indented
output to a StringBuilder, providing primitives to indent and outdent. Derived classes such
as the
PrettyStringBuilder honor the spacing, which the PlainStringBuilder
ignore it, and all requests for whitespace (such as nextLine()), result in
just a single space begin appended to the String.
The IndentingStringBuilder interface has a fluent-style definition, allowing it to be
used repeatedly in expressions.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract IndentingStringBuilderaddComment(String comment) Add a c-style comment.append(char v) Append a char.append(long v) Append a long value, as text.Append a String.intlength()Return the length of the String written so far.abstract IndentingStringBuildernextLine()Emit a newline, along with any necessary indentation.abstract IndentingStringBuilderRemove a level of indentation.abstract IndentingStringBuilderAdd a new level of indentation.toString()
-
Field Details
-
sb
-
-
Constructor Details
-
IndentingStringBuilder
Constructor.- Parameters:
sb- the StringBuilder to write to
-
-
Method Details
-
toString
-
length
public int length()Return the length of the String written so far.- Returns:
- the length of the String written so far
-
append
Append a String.- Parameters:
v- the string to append- Returns:
- the IndentingStringBuilder
-
append
Append a char.- Parameters:
v- the char to append- Returns:
- the IndentingStringBuilder
-
append
Append a long value, as text.- Parameters:
v- the long to append- Returns:
- the IndentingStringBuilder
-
nextLine
Emit a newline, along with any necessary indentation.- Returns:
- this
-
pushIndent
Add a new level of indentation. This has no effect until the next call tonextLine().- Returns:
- this
-
popIndent
Remove a level of indentation. This has no effect until the next call tonextLine(). It is an error to unindent when there are no levels of indentation active; this is indicated with a call toaddComment(String)with a warning that the caller has unindented too much.- Returns:
- this
-
addComment
Add a c-style comment. The provided text is emitted surrounded by "/o " and " o/" (where the o's are asterisks). The comment will only appear in "pretty text." For plain text, this emits a single blank.- Parameters:
comment- the comment- Returns:
-