public interface FormattingAppendable extends Appendable
consecutive \n in the data are going go be collapsed to a single \n and which will only be output when text is appended after the \n, or on flush() call to output any pending \n's
tab is converted to a space
spaces before and after \n are removed since indentation is controlled by this class through
the indent() and unIndent() members.
optionally will collapse multiple spaces to one space
Indent is only output after a \n and before text. Blank lines and other \n's do not output an indent
use line(), lineIf(boolean), blankLine(), blankLineIf(boolean)
and blankLine(int) for getting these in the appended result
Also adds conditional new line and indent capability, allowing compact form if there is no "child" element data output, and fully unfolded, indented form if there is "child" element text output.
For example output of HTML list items in compact form as <li>item text</li> if it has no children and as split over several lines, with child content indented, if it has children: <li>item text child text </li>
| Modifier and Type | Field and Description |
|---|---|
static int |
ALLOW_LEADING_WHITESPACE |
static int |
COLLAPSE_WHITESPACE |
static int |
CONVERT_TABS |
static int |
FORMAT_ALL |
static int |
PASS_THROUGH |
static int |
PREFIX_AFTER_PENDING_EOL |
static int |
SUPPRESS_TRAILING_WHITESPACE |
| Modifier and Type | Method and Description |
|---|---|
FormattingAppendable |
addAfterEolRunnable(int atPendingEOL,
Runnable runnable)
Add runnable to run after the given pending EOL is output to the stream.
|
FormattingAppendable |
addLine()
Add a new line or blank lines as needed.
|
FormattingAppendable |
addPrefix(CharSequence prefix)
Set prefix to append after a new line character for every line before the indent prefix in normal
and after a new line in pre-formatted sections
This appends the sequence to current prefix
|
FormattingAppendable |
append(char c) |
FormattingAppendable |
append(CharSequence csq) |
FormattingAppendable |
append(CharSequence csq,
int start,
int end) |
FormattingAppendable |
blankLine()
Add a blank line, if there is not one already appended.
|
FormattingAppendable |
blankLine(int count)
Add a blank lines, if there isn't already given number of blank lines appended.
|
FormattingAppendable |
blankLineIf(boolean predicate)
Add a blank line, if predicate is true and there isn't already blank lines appended.
|
FormattingAppendable |
closeConditional(ConditionalFormatter closeFormatter)
Close a conditional formatting region.
|
FormattingAppendable |
closePreFormatted()
Close a pre-formatted section.
|
int |
column()
Get column offset after last append, does not include any pending: EOLs, spaces nor indents
|
int |
columnWith(CharSequence csq,
int start,
int end)
Get column offset after last append, does not include any pending: EOLs, spaces nor indents
|
FormattingAppendable |
flush()
Flush all pending new lines, no blank lines will be output, if these are desired at the end of the output.
|
FormattingAppendable |
flush(int maxBlankLines)
Flush all pending new lines and blank lines, if these are desired at the end of the output.
|
FormattingAppendable |
flushWhitespaces()
Flush all pending whitespaces
|
Appendable |
getAppendable()
Get the underlying appendable
|
int |
getIndent()
Get the current indent level + indent offset
|
CharSequence |
getIndentPrefix()
Get prefix appended after a new line character for every indent level
|
IOException |
getIOException() |
int |
getLineCount()
Get the number of lines appended, does not include pending: EOLs
|
int |
getModCount()
Get the modification count.
|
int |
getOptions()
Get current options
|
int |
getPendingEOL()
see if there is a pending space
|
int |
getPendingSpace() |
CharSequence |
getPrefix()
Get prefix being applied to all lines, even in pre-formatted sections
|
int |
getPushedPrefixCount()
Pop a prefix from the stack and set the current prefix
|
String |
getText()
get the resulting text from appendable
|
String |
getText(int maxBlankLines)
get the resulting text from appendable
|
CharSequence |
getTotalIndentPrefix()
Get the total indent prefix appended after a new line character,
getIndentPrefix() repeated getIndent() times. |
FormattingAppendable |
indent()
Increase the indent level, will terminate the current line if there is unterminated text
|
boolean |
isPendingEOL()
see if there is a pending space
|
boolean |
isPendingSpace()
see if there is a pending space
|
boolean |
isPreFormatted() |
int |
lastOffset()
Get offset before the last append, but right after pending: EOLs, spaces or indents were added
|
FormattingAppendable |
lastOffset(Ref<Integer> refOffset)
Get offset before the next append, but right after pending: EOLs, spaces or indents were added
Next append of text (non EOL/spaces) will set the reference, following appends will have not effect
Unlike
lastOffset() flush() does not change the value of the reference, only actual character appending. |
FormattingAppendable |
line()
Add a new line, if there was any unterminated text appended
|
FormattingAppendable |
line(Ref<Boolean> lineRef)
Add a new line, if there was any unterminated text appended
|
FormattingAppendable |
lineIf(boolean predicate)
Add a new line, if predicate is true and there was any unterminated text appended
|
FormattingAppendable |
lineIf(Ref<Boolean> lineRef)
Add a new line, if lineRef is true, if false means that the new line in
line(Ref) was suppressed
by conditionalFormatter and this new line will be suppressed too. |
int |
offset()
Get offset after last append, does not include any pending: EOLs, spaces nor indents
|
int |
offsetWithPending()
Get offset after last append, include any pending: EOLs, and indents
|
FormattingAppendable |
openConditional(ConditionalFormatter openFormatter)
Open a conditional formatting region.
|
FormattingAppendable |
openPreFormatted(boolean keepIndent)
Open a pre-formatted section.
|
FormattingAppendable |
popPrefix()
Pop a prefix from the stack and set the current prefix
|
FormattingAppendable |
pushPrefix()
Save the current prefix on the stack
|
FormattingAppendable |
repeat(char c,
int count) |
FormattingAppendable |
repeat(CharSequence csq,
int count) |
FormattingAppendable |
repeat(CharSequence csq,
int start,
int end,
int count) |
FormattingAppendable |
setIndentOffset(int indentOffset)
Set the current indent level.
|
FormattingAppendable |
setIndentPrefix(CharSequence prefix)
Set prefix to append after a new line character for every indent level
|
FormattingAppendable |
setOptions(int options)
Set options on processing text
|
void |
setPendingEOL(int pendingEOL)
Kludge to allow inserting spaces before the already pending EOL in HTML parser
|
FormattingAppendable |
setPrefix(CharSequence prefix)
Set prefix to append after a new line character for every line before the indent prefix in normal
and after a new line in pre-formatted sections
if PREFIX_AFTER_PENDING_EOL is enabled then prefix will take effect after pending EOLs are output
|
FormattingAppendable |
unIndent()
Decrease the indent level, min level is 0, will terminate the current line if there is unterminated text
|
FormattingAppendable |
willIndent()
Notify of the fact that after some appending some text, there will be an indent() call so that
conditional formatting can kick in before the text is appended
|
static final int CONVERT_TABS
static final int COLLAPSE_WHITESPACE
static final int SUPPRESS_TRAILING_WHITESPACE
static final int PREFIX_AFTER_PENDING_EOL
static final int PASS_THROUGH
static final int ALLOW_LEADING_WHITESPACE
static final int FORMAT_ALL
IOException getIOException()
FormattingAppendable append(CharSequence csq)
append in interface AppendableFormattingAppendable append(CharSequence csq, int start, int end)
append in interface AppendableFormattingAppendable append(char c)
append in interface AppendableFormattingAppendable repeat(char c, int count)
FormattingAppendable repeat(CharSequence csq, int count)
FormattingAppendable repeat(CharSequence csq, int start, int end, int count)
Appendable getAppendable()
String getText()
String getText(int maxBlankLines)
maxBlankLines - maximum blank lines to allow at end, -1 will suppress the last EOLint getOptions()
FormattingAppendable setOptions(int options)
options - option flagsFormattingAppendable flush()
All preFormatted and conditional regions should be exited prior to this call
FormattingAppendable flushWhitespaces()
All preFormatted and conditional regions should be exited prior to this call
FormattingAppendable flush(int maxBlankLines)
All preFormatted and conditional regions should be exited prior to this call
maxBlankLines - maximum blank lines to allow at end, -1 will suppress the last EOLCharSequence getIndentPrefix()
CharSequence getTotalIndentPrefix()
getIndentPrefix() repeated getIndent() times.FormattingAppendable setIndentPrefix(CharSequence prefix)
prefix - prefix characters for new lines appended after this is setCharSequence getPrefix()
FormattingAppendable setPrefix(CharSequence prefix)
prefix - prefix characters for new lines appended after this is setFormattingAppendable addPrefix(CharSequence prefix)
prefix - prefix characters to add to current prefix for new lines appended after this is setFormattingAppendable pushPrefix()
FormattingAppendable popPrefix()
void setPendingEOL(int pendingEOL)
pendingEOL - how many pending EOLs to setFormattingAppendable addAfterEolRunnable(int atPendingEOL, Runnable runnable)
atPendingEOL - pending EOL levelrunnable - runnable to run once this EOL is outputint getPushedPrefixCount()
FormattingAppendable line()
Actual new line character is only appended if there is real data appended and it did not contain a new line as the last character
FormattingAppendable addLine()
Actual new line character is only appended if there is real data appended and it did not contain a new line as the last character
FormattingAppendable lineIf(boolean predicate)
Actual new line character is only appended if and when text is appended appended and it did not contain a new line as the last character
predicate - if true then new line will be startedFormattingAppendable line(Ref<Boolean> lineRef)
Actual new line character is only appended if there is real data appended and it did not contain a new line as the last character
lineRef - predicate storage will be set to false if conditionalFormatter suppressed a new lineFormattingAppendable lineIf(Ref<Boolean> lineRef)
line(Ref) was suppressed
by conditionalFormatter and this new line will be suppressed too.
Actual new line character is only appended if and when text is appended appended and it did not contain a new line as the last character
lineRef - predicate storage for conditionalFormatter suppressed new line conditionFormattingAppendable blankLine()
Actual blank line characters are only appended if there is real data appended and it did not contain a blank line as the last part of its text
FormattingAppendable blankLineIf(boolean predicate)
Actual blank line characters are only appended if and when there text is appended appended and it did not contain a blank line as the last part of its text
predicate - when true append blank lineFormattingAppendable blankLine(int count)
On real data being appended, will append enough new lines to ensure that there are given number of blank lines between previous append and the next one.
Actual blank line characters are only appended if there is real data appended and it did not contain a blank line as the last part of its text
count - number of blank lines to appendint getIndent()
FormattingAppendable setIndentOffset(int indentOffset)
indentOffset - minimum indent that will be usedFormattingAppendable indent()
FormattingAppendable willIndent()
FormattingAppendable unIndent()
int getModCount()
int getLineCount()
FormattingAppendable lastOffset(Ref<Integer> refOffset)
lastOffset() flush() does not change the value of the reference, only actual character appending.refOffset - reference where to store offset, if no appending was done then value is not changedint lastOffset()
int offset()
int offsetWithPending()
int column()
int columnWith(CharSequence csq, int start, int end)
csq - sequence to use for computationstart - start offset in csqend - end offset in csqFormattingAppendable openPreFormatted(boolean keepIndent)
keepIndent - if true, if there is pending indent it will be appended before entering pre-format modeFormattingAppendable closePreFormatted()
boolean isPreFormatted()
FormattingAppendable openConditional(ConditionalFormatter openFormatter)
After opening if and when text is appended the ConditionalFormatter.apply(boolean, boolean, boolean, boolean)
will be invoked before appending the text with parameters specifying whether indent or line were
invoked before appending text. The onText is always true for opening conditional formatter or the apply() method
would not be called
the firstAppend will be set if this is the first call, if onIndent is false on first call then the apply() method will be invoked again if any indent() is performed before the conditional is closed.
openFormatter - to invoke before text is appendedFormattingAppendable closeConditional(ConditionalFormatter closeFormatter)
ConditionalFormatter.apply(boolean, boolean, boolean, boolean)
will be invoked with parameters specifying whether indent, line or text was appended when openConditional(ConditionalFormatter)
invoked before appending text. If onText is false then openFormatter passed to openConditional(ConditionalFormatter) was
not invoked.
closeFormatter - to invoke with parameters informing with what parameters the openFormatter was invoked, if at allboolean isPendingSpace()
int getPendingSpace()
boolean isPendingEOL()
int getPendingEOL()
Copyright © 2019. All rights reserved.