Package com.mapr.utils
Class IndentingStringBuilder
- java.lang.Object
-
- com.mapr.utils.IndentingStringBuilder
-
- Direct Known Subclasses:
PlainStringBuilder,PrependingStringBuilder,PrettyStringBuilder
public abstract class IndentingStringBuilder extends java.lang.ObjectAbstract 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 thePrettyStringBuilderhonor the spacing, which thePlainStringBuilderignore it, and all requests for whitespace (such asnextLine()), 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 Modifier and Type Field Description protected java.lang.StringBuildersb
-
Constructor Summary
Constructors Constructor Description IndentingStringBuilder(java.lang.StringBuilder sb)Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract IndentingStringBuilderaddComment(java.lang.String comment)Add a c-style comment.IndentingStringBuilderappend(char v)Append a char.IndentingStringBuilderappend(long v)Append a long value, as text.IndentingStringBuilderappend(java.lang.String v)Append a String.intlength()Return the length of the String written so far.abstract IndentingStringBuildernextLine()Emit a newline, along with any necessary indentation.abstract IndentingStringBuilderpopIndent()Remove a level of indentation.abstract IndentingStringBuilderpushIndent()Add a new level of indentation.java.lang.StringtoString()
-
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
length
public int length()
Return the length of the String written so far.- Returns:
- the length of the String written so far
-
append
public IndentingStringBuilder append(java.lang.String v)
Append a String.- Parameters:
v- the string to append- Returns:
- the IndentingStringBuilder
-
append
public IndentingStringBuilder append(char v)
Append a char.- Parameters:
v- the char to append- Returns:
- the IndentingStringBuilder
-
append
public IndentingStringBuilder append(long v)
Append a long value, as text.- Parameters:
v- the long to append- Returns:
- the IndentingStringBuilder
-
nextLine
public abstract IndentingStringBuilder nextLine()
Emit a newline, along with any necessary indentation.- Returns:
- this
-
pushIndent
public abstract IndentingStringBuilder pushIndent()
Add a new level of indentation. This has no effect until the next call tonextLine().- Returns:
- this
-
popIndent
public abstract IndentingStringBuilder 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
public abstract IndentingStringBuilder addComment(java.lang.String comment)
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:
-
-