Class LineAppendableImpl
- java.lang.Object
-
- com.vladsch.flexmark.util.sequence.LineAppendableImpl
-
- All Implemented Interfaces:
LineAppendable
,java.lang.Appendable
,java.lang.Iterable<LineInfo>
public class LineAppendableImpl extends java.lang.Object implements LineAppendable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
LineAppendableImpl.IndexedLineInfoProxy
(package private) static class
LineAppendableImpl.IndexedLineProxy
-
Nested classes/interfaces inherited from interface com.vladsch.flexmark.util.sequence.LineAppendable
LineAppendable.Options
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
allWhitespace
private ISequenceBuilder<?,?>
appendable
private static char
EOL
private int
eolOnFirstText
private java.lang.CharSequence
indentPrefix
private java.util.Stack<java.lang.Boolean>
indentPrefixStack
private java.util.ArrayList<java.lang.Runnable>
indentsOnFirstEol
private boolean
lastWasWhitespace
(package private) java.util.ArrayList<LineInfo>
lines
(package private) int
modificationCount
private BitFieldSet<LineAppendable.Options>
options
private java.util.Stack<java.lang.Integer>
optionStack
private boolean
passThrough
private java.lang.CharSequence
prefix
private java.lang.CharSequence
prefixAfterEol
private java.util.Stack<java.lang.CharSequence>
prefixStack
private int
preFormattedFirstLine
private int
preFormattedFirstLineOffset
private int
preFormattedLastLine
private int
preFormattedLastLineOffset
private int
preFormattedNesting
-
Fields inherited from interface com.vladsch.flexmark.util.sequence.LineAppendable
ALLOW_LEADING_EOL, ALLOW_LEADING_WHITESPACE, COLLAPSE_WHITESPACE, CONVERT_TABS, F_COLLAPSE_WHITESPACE, F_CONVERT_TABS, F_FORMAT_ALL, F_PASS_THROUGH, F_PREFIX_PRE_FORMATTED, F_TRIM_LEADING_EOL, F_TRIM_LEADING_WHITESPACE, F_TRIM_TRAILING_WHITESPACE, F_WHITESPACE_REMOVAL, FORMAT_ALL, O_COLLAPSE_WHITESPACE, O_CONVERT_TABS, O_FORMAT_ALL, O_PASS_THROUGH, O_PREFIX_PRE_FORMATTED, O_TRIM_LEADING_EOL, O_TRIM_LEADING_WHITESPACE, O_TRIM_TRAILING_WHITESPACE, PASS_THROUGH, PREFIX_PRE_FORMATTED, TRIM_LEADING_WHITESPACE, TRIM_TRAILING_WHITESPACE
-
-
Constructor Summary
Constructors Constructor Description LineAppendableImpl(int formatOptions)
LineAppendableImpl(@Nullable java.lang.Appendable builder, int formatOptions)
LineAppendableImpl(@Nullable java.lang.Appendable appendable, BitFieldSet<LineAppendable.Options> formatOptions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull LineAppendable
addIndentOnFirstEOL(@NotNull java.lang.Runnable listener)
Add an indent on first EOL appended and run runnableprivate void
addLineRange(int start, int end, java.lang.CharSequence prefix)
@NotNull LineAppendable
addPrefix(@NotNull java.lang.CharSequence prefix, boolean afterEol)
Add to prefix appended after a new line character for every line and after a new line in pre-formatted sectionsprivate boolean
any(int flags)
@NotNull LineAppendable
append(char c)
@NotNull LineAppendable
append(char c, int count)
@NotNull LineAppendable
append(@NotNull LineAppendable lineAppendable, int startLine, int endLine, boolean withPrefixes)
Append lines from another line formatting appendable.@NotNull LineAppendable
append(@NotNull java.lang.CharSequence csq)
@NotNull LineAppendable
append(@NotNull java.lang.CharSequence csq, int start, int end)
private void
appendEol(int count)
private void
appendEol(@NotNull java.lang.CharSequence eol)
private void
appendImpl(java.lang.CharSequence s, int index)
private void
appendImpl(java.lang.CharSequence csq, int start, int end)
<T extends java.lang.Appendable>
TappendTo(T out, boolean withPrefixes, int maxBlankLines, int maxTrailingBlankLines, int startLine, int endLine)
append lines to appendable with given maximum trailing blank lines and given prefix to add to all lines<T extends java.lang.Appendable>
TappendToNoLine(T out, boolean withPrefixes, int maxBlankLines, int maxTrailingBlankLines, int startLine, int endLine)
@NotNull LineAppendable
blankLine()
Add a blank line, if there is not one already appended.@NotNull LineAppendable
blankLine(int count)
Add a blank lines, if there isn't already given number of blank lines appended.@NotNull LineAppendable
blankLineIf(boolean predicate)
Add a blank line, if predicate is true and there isn't already blank lines appended.@NotNull LineAppendable
changeOptions(int addFlags, int removeFlags)
@NotNull LineAppendable
closePreFormatted()
Close preformatted section and suspend content modificationint
column()
Get column offset after last appendprivate LineInfo
createLineInfo(int lineIndex, @NotNull java.lang.CharSequence prefix, @NotNull java.lang.CharSequence content)
private void
doEolOnFirstTest()
boolean
endsWithEOL()
int
getAfterEolPrefixDelta()
Get pending prefix after EOL@NotNull BasedSequence
getBeforeEolPrefix()
Get prefix used before EOL@NotNull ISequenceBuilder<?,?>
getBuilder()
Get builder used for accumulation@NotNull LineAppendable
getEmptyAppendable()
@NotNull BasedSequence
getIndentPrefix()
Get prefix appended after a new line character for every indent level(package private) @NotNull LineAppendableImpl.IndexedLineInfoProxy
getIndexedLineInfoProxy(int maxTrailingBlankLines, int startLine, int endLine)
(package private) @NotNull LineAppendableImpl.IndexedLineProxy
getIndexedLineProxy(int maxTrailingBlankLines, int startLine, int endLine, boolean withPrefixes)
(package private) @NotNull LineInfo
getLastLineInfo()
@NotNull BasedSequence
getLine(int lineIndex)
Get Line at given line indexint
getLineCount()
Get the number of lines appended, not including any unterminated onesint
getLineCountWithPending()
Get the number of lines appended, including any unterminated ones@NotNull LineInfo
getLineInfo(int lineIndex)
Get Line information at given line indexprivate LineInfo
getLineRange(int start, int end, java.lang.CharSequence prefix)
@NotNull java.lang.Iterable<BasedSequence>
getLines(int maxTrailingBlankLines, int startLine, int endLine, boolean withPrefixes)
Full line iterator over some lines@NotNull java.lang.Iterable<LineInfo>
getLinesInfo(int maxTrailingBlankLines, int startLine, int endLine)
Full line iterator with line info@NotNull BitFieldSet<LineAppendable.Options>
getOptionSet()
Get current options as set which can be used to modify optionsint
getPendingEOL()
Get number of EOLs at end of appendable, this is actually number of tail blank linesint
getPendingSpace()
Get number of spaces at end of pending text@NotNull BasedSequence
getPrefix()
Get prefix being applied to all lines, even in pre-formatted sections This is the prefix that will be set after EOLprivate Pair<Range,java.lang.CharSequence>
getRangePrefixAfterEol()
Returns text range if EOL was appendedint
getTrailingBlankLines(int endLine)
Get trailing blank line count ending on given line@NotNull LineAppendable
indent()
Increase the indent level, will terminate the current line if there is unterminated textvoid
insertLine(int lineIndex, @NotNull java.lang.CharSequence prefix, @NotNull java.lang.CharSequence content)
Insert a line at the index with given content and prefix for a lineprivate boolean
isCollapseWhitespace()
private boolean
isConvertingTabs()
boolean
isPendingSpace()
Test if trailing text ends in space or tabprivate boolean
isPrefixed(int currentLine)
boolean
isPreFormatted()
private boolean
isTrailingBlankLine()
private boolean
isTrimLeadingWhitespace()
private boolean
isTrimTrailingWhitespace()
@NotNull java.util.Iterator<LineInfo>
iterator()
Full line iterator NOTE: will not issue line() to terminate any unterminated lines before iteration and will not include unterminated lines in iteration(package private) int
lastNonBlankLine(int endLine)
@NotNull LineAppendable
line()
Add a new line if there was any unterminated text appended or if this is a preformatted region@NotNull LineAppendable
lineIf(boolean predicate)
Add a new line, if predicate is true and line() would add an EOL.@NotNull LineAppendable
lineOnFirstText(boolean value)
@NotNull LineAppendable
lineWithTrailingSpaces(int count)
Add a new line, keep trailing spaces if there was any unterminated text appendedint
offset()
Get text offset of all output lines, excluding any text for the last line being accumulatedprivate int
offsetAfterEol()
Returns text offset before EOL if EOL was issuedint
offsetWithPending()
Get offset after last append as if EOL was added but without the EOL itself@NotNull LineAppendable
openPreFormatted(boolean addPrefixToFirstLine)
Open preformatted section and suspend content modification@NotNull LineAppendable
popOptions()
@NotNull LineAppendable
popPrefix(boolean afterEol)
Pop a prefix from the stack and set the current prefix@NotNull LineAppendable
pushOptions()
@NotNull LineAppendable
pushPrefix()
Save the current prefix on the stackprivate void
rawIndent()
private void
rawIndentsOnFirstEol()
private void
rawUnIndent()
(package private) void
recomputeLineInfo(int startLine)
LineAppendable
removeExtraBlankLines(int maxBlankLines, int maxTrailingBlankLines, int startLine, int endLine)
Normalize the appendable by removing extra blank lines in the body or at the end of given line range@NotNull LineAppendable
removeIndentOnFirstEOL(@NotNull java.lang.Runnable listener)
Remove runnable, has no effect if EOL was already appended and runnable was run@NotNull LineAppendable
removeLines(int startLine, int endLine)
private int
removeLinesRaw(int startLine, int endLine)
Remove lines and return index from which line info must be recomputed@NotNull LineAppendable
repeat(@NotNull java.lang.CharSequence csq, int count)
@NotNull LineAppendable
repeat(@NotNull java.lang.CharSequence csq, int start, int end, int count)
private void
resetBuilder()
@NotNull LineAppendable
setIndentPrefix(@Nullable java.lang.CharSequence prefix)
Set prefix to append after a new line character for every indent levelvoid
setLine(int lineIndex, @NotNull java.lang.CharSequence prefix, @NotNull java.lang.CharSequence content)
Set content and prefix for a line@NotNull LineAppendable
setOptions(int flags)
Set options on processing text@NotNull LineAppendable
setPrefix(@Nullable java.lang.CharSequence prefix, boolean afterEol)
Set prefix appended after a new line character for every line and after a new line in pre-formatted sectionsvoid
setPrefixLength(int lineIndex, int prefixLength)
Change prefix length for a given line without changing the line content(package private) int
tailBlankLinesToRemove(int endLine, int maxTrailingBlankLines)
@NotNull java.lang.CharSequence
toSequence(int maxBlankLines, int maxTrailingBlankLines, boolean withPrefixes)
get the resulting text for all linesjava.lang.String
toString()
@NotNull java.lang.String
toString(int maxBlankLines, int maxTrailingBlankLines, boolean withPrefixes)
get the resulting text for all lines@NotNull LineAppendable
unIndent()
Decrease the indent level, min level is 0, will terminate the current line if there is unterminated text@NotNull LineAppendable
unIndentNoEol()
Decrease the indent level, if there is unterminated text then unindented prefix is to be applied after the next EOL.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.vladsch.flexmark.util.sequence.LineAppendable
addOptions, addPrefix, append, append, appendAll, appendTo, appendTo, appendTo, appendTo, appendToSilently, appendToSilently, appendToSilently, appendToSilently, clearLineOnFirstText, copyAppendable, copyAppendable, copyAppendable, copyAppendable, copyAppendable, get, getLineContent, getLinePrefix, getLines, getLines, getLines, getLines, getLinesInfo, getLinesInfo, getOptions, getTrailingBlankLines, isEmpty, isNotEmpty, noPreserveSpaces, noTrimLeading, popPrefix, preserveSpaces, removeExtraBlankLines, removeOptions, setLineOnFirstText, setOptions, setOptions, setPrefix, toSequence, toSequence, toSequence, toSequence, toString, toString, toString, toString, trimLeading
-
-
-
-
Field Detail
-
EOL
private static final char EOL
- See Also:
- Constant Field Values
-
passThrough
private final boolean passThrough
-
options
private final BitFieldSet<LineAppendable.Options> options
-
preFormattedNesting
private int preFormattedNesting
-
preFormattedFirstLine
private int preFormattedFirstLine
-
preFormattedFirstLineOffset
private int preFormattedFirstLineOffset
-
preFormattedLastLine
private int preFormattedLastLine
-
preFormattedLastLineOffset
private int preFormattedLastLineOffset
-
appendable
private ISequenceBuilder<?,?> appendable
-
lines
final java.util.ArrayList<LineInfo> lines
-
prefix
private java.lang.CharSequence prefix
-
prefixAfterEol
private java.lang.CharSequence prefixAfterEol
-
indentPrefix
private java.lang.CharSequence indentPrefix
-
prefixStack
private final java.util.Stack<java.lang.CharSequence> prefixStack
-
indentPrefixStack
private final java.util.Stack<java.lang.Boolean> indentPrefixStack
-
allWhitespace
private boolean allWhitespace
-
lastWasWhitespace
private boolean lastWasWhitespace
-
eolOnFirstText
private int eolOnFirstText
-
indentsOnFirstEol
private final java.util.ArrayList<java.lang.Runnable> indentsOnFirstEol
-
optionStack
private final java.util.Stack<java.lang.Integer> optionStack
-
modificationCount
int modificationCount
-
-
Constructor Detail
-
LineAppendableImpl
public LineAppendableImpl(int formatOptions)
-
LineAppendableImpl
public LineAppendableImpl(@Nullable @Nullable java.lang.Appendable builder, int formatOptions)
-
LineAppendableImpl
public LineAppendableImpl(@Nullable @Nullable java.lang.Appendable appendable, BitFieldSet<LineAppendable.Options> formatOptions)
-
-
Method Detail
-
getEmptyAppendable
@NotNull public @NotNull LineAppendable getEmptyAppendable()
- Specified by:
getEmptyAppendable
in interfaceLineAppendable
-
getOptionSet
@NotNull public @NotNull BitFieldSet<LineAppendable.Options> getOptionSet()
Description copied from interface:LineAppendable
Get current options as set which can be used to modify options- Specified by:
getOptionSet
in interfaceLineAppendable
- Returns:
- mutable option set
-
setOptions
@NotNull public @NotNull LineAppendable setOptions(int flags)
Description copied from interface:LineAppendable
Set options on processing text- Specified by:
setOptions
in interfaceLineAppendable
- Parameters:
flags
- option flags- Returns:
- this
-
pushOptions
@NotNull public @NotNull LineAppendable pushOptions()
- Specified by:
pushOptions
in interfaceLineAppendable
-
popOptions
@NotNull public @NotNull LineAppendable popOptions()
- Specified by:
popOptions
in interfaceLineAppendable
-
changeOptions
@NotNull public @NotNull LineAppendable changeOptions(int addFlags, int removeFlags)
- Specified by:
changeOptions
in interfaceLineAppendable
-
any
private boolean any(int flags)
-
isConvertingTabs
private boolean isConvertingTabs()
-
isTrimTrailingWhitespace
private boolean isTrimTrailingWhitespace()
-
isTrimLeadingWhitespace
private boolean isTrimLeadingWhitespace()
-
isCollapseWhitespace
private boolean isCollapseWhitespace()
-
getIndentPrefix
@NotNull public @NotNull BasedSequence getIndentPrefix()
Description copied from interface:LineAppendable
Get prefix appended after a new line character for every indent level- Specified by:
getIndentPrefix
in interfaceLineAppendable
- Returns:
- char sequence of the current indent prefix used for each indent level
-
setIndentPrefix
@NotNull public @NotNull LineAppendable setIndentPrefix(@Nullable @Nullable java.lang.CharSequence prefix)
Description copied from interface:LineAppendable
Set prefix to append after a new line character for every indent level- Specified by:
setIndentPrefix
in interfaceLineAppendable
- Parameters:
prefix
- prefix characters for new lines appended after this is set- Returns:
- this
-
getPrefix
@NotNull public @NotNull BasedSequence getPrefix()
Description copied from interface:LineAppendable
Get prefix being applied to all lines, even in pre-formatted sections This is the prefix that will be set after EOL- Specified by:
getPrefix
in interfaceLineAppendable
- Returns:
- char sequence of the current prefix
-
getBeforeEolPrefix
@NotNull public @NotNull BasedSequence getBeforeEolPrefix()
Description copied from interface:LineAppendable
Get prefix used before EOL- Specified by:
getBeforeEolPrefix
in interfaceLineAppendable
- Returns:
- char sequence of the current prefix
-
addPrefix
@NotNull public @NotNull LineAppendable addPrefix(@NotNull @NotNull java.lang.CharSequence prefix, boolean afterEol)
Description copied from interface:LineAppendable
Add to prefix appended after a new line character for every line and after a new line in pre-formatted sectionsThis appends the sequence to current prefix
- Specified by:
addPrefix
in interfaceLineAppendable
- Parameters:
prefix
- prefix characters to add to current prefix for new lines appended after this is setafterEol
- if true prefix will take effect after EOL- Returns:
- this
-
getAfterEolPrefixDelta
public int getAfterEolPrefixDelta()
Description copied from interface:LineAppendable
Get pending prefix after EOL- Specified by:
getAfterEolPrefixDelta
in interfaceLineAppendable
- Returns:
- change in prefix length after next eol
-
setPrefix
@NotNull public @NotNull LineAppendable setPrefix(@Nullable @Nullable java.lang.CharSequence prefix, boolean afterEol)
Description copied from interface:LineAppendable
Set prefix appended after a new line character for every line and after a new line in pre-formatted sectionsThis appends the sequence to current prefix
- Specified by:
setPrefix
in interfaceLineAppendable
- Parameters:
prefix
- prefix characters to add to current prefix for new lines appended after this is setafterEol
- if true prefix will take effect after EOL- Returns:
- this
-
indent
@NotNull public @NotNull LineAppendable indent()
Description copied from interface:LineAppendable
Increase the indent level, will terminate the current line if there is unterminated textNOTE: this is equivalent to pushPrefix(), addPrefix(getIndentPrefix()) but adds a flag to validate that
LineAppendable.unIndent()
is called only on prefixes added by this method- Specified by:
indent
in interfaceLineAppendable
- Returns:
- this
-
rawIndent
private void rawIndent()
-
rawUnIndent
private void rawUnIndent()
-
unIndent
@NotNull public @NotNull LineAppendable unIndent()
Description copied from interface:LineAppendable
Decrease the indent level, min level is 0, will terminate the current line if there is unterminated textNOTE: this is equivalent to popPrefix() but with validation that it is called only on prefixes added by
LineAppendable.indent()
- Specified by:
unIndent
in interfaceLineAppendable
- Returns:
- this
-
unIndentNoEol
@NotNull public @NotNull LineAppendable unIndentNoEol()
Description copied from interface:LineAppendable
Decrease the indent level, if there is unterminated text then unindented prefix is to be applied after the next EOL.Will NOT terminate the current line if there is unterminated text
NOTE: should be used with
LineAppendable.addIndentOnFirstEOL(Runnable)
if callback is invoked- Specified by:
unIndentNoEol
in interfaceLineAppendable
- Returns:
- this
-
pushPrefix
@NotNull public @NotNull LineAppendable pushPrefix()
Description copied from interface:LineAppendable
Save the current prefix on the stack- Specified by:
pushPrefix
in interfaceLineAppendable
- Returns:
- this
-
popPrefix
@NotNull public @NotNull LineAppendable popPrefix(boolean afterEol)
Description copied from interface:LineAppendable
Pop a prefix from the stack and set the current prefix- Specified by:
popPrefix
in interfaceLineAppendable
- Parameters:
afterEol
- if true prefix will take effect after EOL- Returns:
- this
-
getLastLineInfo
@NotNull @NotNull LineInfo getLastLineInfo()
-
isTrailingBlankLine
private boolean isTrailingBlankLine()
-
lastNonBlankLine
int lastNonBlankLine(int endLine)
-
getTrailingBlankLines
public int getTrailingBlankLines(int endLine)
Description copied from interface:LineAppendable
Get trailing blank line count ending on given line- Specified by:
getTrailingBlankLines
in interfaceLineAppendable
- Parameters:
endLine
- end line- Returns:
- number of trailing blank lines
-
endsWithEOL
public boolean endsWithEOL()
- Specified by:
endsWithEOL
in interfaceLineAppendable
- Returns:
- true if not empty and have no unterminated lines
-
getLineRange
private LineInfo getLineRange(int start, int end, java.lang.CharSequence prefix)
-
resetBuilder
private void resetBuilder()
-
addLineRange
private void addLineRange(int start, int end, java.lang.CharSequence prefix)
-
appendEol
private void appendEol(@NotNull @NotNull java.lang.CharSequence eol)
-
rawIndentsOnFirstEol
private void rawIndentsOnFirstEol()
-
appendEol
private void appendEol(int count)
-
isPrefixed
private boolean isPrefixed(int currentLine)
-
getRangePrefixAfterEol
private Pair<Range,java.lang.CharSequence> getRangePrefixAfterEol()
Returns text range if EOL was appendedNOTE: if range == Range.NULL then no line would be added
- Returns:
- pair of line text range if EOL was added and prefix
-
offsetAfterEol
private int offsetAfterEol()
Returns text offset before EOL if EOL was issued- Returns:
- would be offset after adding EOL - 1
-
doEolOnFirstTest
private void doEolOnFirstTest()
-
appendImpl
private void appendImpl(java.lang.CharSequence s, int index)
-
appendImpl
private void appendImpl(java.lang.CharSequence csq, int start, int end)
-
append
@NotNull public @NotNull LineAppendable append(@NotNull @NotNull java.lang.CharSequence csq)
- Specified by:
append
in interfacejava.lang.Appendable
- Specified by:
append
in interfaceLineAppendable
-
getBuilder
@NotNull public @NotNull ISequenceBuilder<?,?> getBuilder()
Description copied from interface:LineAppendable
Get builder used for accumulation- Specified by:
getBuilder
in interfaceLineAppendable
- Returns:
- builder used for accumulation
-
append
@NotNull public @NotNull LineAppendable append(@NotNull @NotNull java.lang.CharSequence csq, int start, int end)
- Specified by:
append
in interfacejava.lang.Appendable
- Specified by:
append
in interfaceLineAppendable
-
append
@NotNull public @NotNull LineAppendable append(char c)
- Specified by:
append
in interfacejava.lang.Appendable
- Specified by:
append
in interfaceLineAppendable
-
append
@NotNull public @NotNull LineAppendable append(char c, int count)
- Specified by:
append
in interfaceLineAppendable
-
repeat
@NotNull public @NotNull LineAppendable repeat(@NotNull @NotNull java.lang.CharSequence csq, int count)
-
repeat
@NotNull public @NotNull LineAppendable repeat(@NotNull @NotNull java.lang.CharSequence csq, int start, int end, int count)
-
line
@NotNull public @NotNull LineAppendable line()
Description copied from interface:LineAppendable
Add a new line if there was any unterminated text appended or if this is a preformatted region- Specified by:
line
in interfaceLineAppendable
- Returns:
- this
-
lineWithTrailingSpaces
@NotNull public @NotNull LineAppendable lineWithTrailingSpaces(int count)
Description copied from interface:LineAppendable
Add a new line, keep trailing spaces if there was any unterminated text appendedNOTE: only applies in preformatted region or if the line is not empty
- Specified by:
lineWithTrailingSpaces
in interfaceLineAppendable
- Parameters:
count
- number of trailing spaces to add- Returns:
- this
-
lineIf
@NotNull public @NotNull LineAppendable lineIf(boolean predicate)
Description copied from interface:LineAppendable
Add a new line, if predicate is true and line() would add an EOL.- Specified by:
lineIf
in interfaceLineAppendable
- Parameters:
predicate
- callLineAppendable.line()
if value is true.- Returns:
- this
-
blankLine
@NotNull public @NotNull LineAppendable blankLine()
Description copied from interface:LineAppendable
Add a blank line, if there is not one already appended.- Specified by:
blankLine
in interfaceLineAppendable
- Returns:
- this
-
blankLineIf
@NotNull public @NotNull LineAppendable blankLineIf(boolean predicate)
Description copied from interface:LineAppendable
Add a blank line, if predicate is true and there isn't already blank lines appended.- Specified by:
blankLineIf
in interfaceLineAppendable
- Parameters:
predicate
- when true append blank line- Returns:
- this
-
blankLine
@NotNull public @NotNull LineAppendable blankLine(int count)
Description copied from interface:LineAppendable
Add a blank lines, if there isn't already given number of blank lines appended. Will append only enough blank lines to increase it to given level. If more are already in the wings then nothing is done.- Specified by:
blankLine
in interfaceLineAppendable
- Parameters:
count
- number of blank lines to append- Returns:
- this
-
lineOnFirstText
@NotNull public @NotNull LineAppendable lineOnFirstText(boolean value)
- Specified by:
lineOnFirstText
in interfaceLineAppendable
-
removeIndentOnFirstEOL
@NotNull public @NotNull LineAppendable removeIndentOnFirstEOL(@NotNull @NotNull java.lang.Runnable listener)
Description copied from interface:LineAppendable
Remove runnable, has no effect if EOL was already appended and runnable was run- Specified by:
removeIndentOnFirstEOL
in interfaceLineAppendable
- Parameters:
listener
- runnable added with addIndentOnFirstEOL- Returns:
- this
-
addIndentOnFirstEOL
@NotNull public @NotNull LineAppendable addIndentOnFirstEOL(@NotNull @NotNull java.lang.Runnable listener)
Description copied from interface:LineAppendable
Add an indent on first EOL appended and run runnable- Specified by:
addIndentOnFirstEOL
in interfaceLineAppendable
- Parameters:
listener
- runnable to run if adding indent on first EOL- Returns:
- this
-
getLineCount
public int getLineCount()
Description copied from interface:LineAppendable
Get the number of lines appended, not including any unterminated ones- Specified by:
getLineCount
in interfaceLineAppendable
- Returns:
- number of full lines appended
-
getLineCountWithPending
public int getLineCountWithPending()
Description copied from interface:LineAppendable
Get the number of lines appended, including any unterminated onesNOTE: if there is an unterminated line it will be available as the last line, without being terminated explicitly
- Specified by:
getLineCountWithPending
in interfaceLineAppendable
- Returns:
- number of lines appended
-
column
public int column()
Description copied from interface:LineAppendable
Get column offset after last append- Specified by:
column
in interfaceLineAppendable
- Returns:
- column offset after last append
-
getLineInfo
@NotNull public @NotNull LineInfo getLineInfo(int lineIndex)
Description copied from interface:LineAppendable
Get Line information at given line indexNOTE: if there is an unterminated line it will be available as the last line, without being terminated explicitly
- Specified by:
getLineInfo
in interfaceLineAppendable
- Parameters:
lineIndex
- line index for the info to get- Returns:
- line info
-
getLine
@NotNull public @NotNull BasedSequence getLine(int lineIndex)
Description copied from interface:LineAppendable
Get Line at given line indexNOTE: if there is an unterminated line it will be available as the last line, without being terminated explicitly
- Specified by:
getLine
in interfaceLineAppendable
- Parameters:
lineIndex
- line index- Returns:
- line char sequence
-
offset
public int offset()
Description copied from interface:LineAppendable
Get text offset of all output lines, excluding any text for the last line being accumulated- Specified by:
offset
in interfaceLineAppendable
- Returns:
- offset of text as would be returned for all
-
offsetWithPending
public int offsetWithPending()
Description copied from interface:LineAppendable
Get offset after last append as if EOL was added but without the EOL itself- Specified by:
offsetWithPending
in interfaceLineAppendable
- Returns:
- offset as would be returned by
LineAppendable.offset()
after line() call less 1 for EOL
-
isPendingSpace
public boolean isPendingSpace()
Description copied from interface:LineAppendable
Test if trailing text ends in space or tab- Specified by:
isPendingSpace
in interfaceLineAppendable
- Returns:
- true if ending in space or tab
-
getPendingSpace
public int getPendingSpace()
Description copied from interface:LineAppendable
Get number of spaces at end of pending text- Specified by:
getPendingSpace
in interfaceLineAppendable
- Returns:
- number of eols at end of text
-
getPendingEOL
public int getPendingEOL()
Description copied from interface:LineAppendable
Get number of EOLs at end of appendable, this is actually number of tail blank lines- Specified by:
getPendingEOL
in interfaceLineAppendable
- Returns:
- number of eols at end of text
-
isPreFormatted
public boolean isPreFormatted()
- Specified by:
isPreFormatted
in interfaceLineAppendable
- Returns:
- true if in pre-formatted region
-
openPreFormatted
@NotNull public @NotNull LineAppendable openPreFormatted(boolean addPrefixToFirstLine)
Description copied from interface:LineAppendable
Open preformatted section and suspend content modification- Specified by:
openPreFormatted
in interfaceLineAppendable
- Parameters:
addPrefixToFirstLine
- if true will add the current prefix to first line- Returns:
- this
-
closePreFormatted
@NotNull public @NotNull LineAppendable closePreFormatted()
Description copied from interface:LineAppendable
Close preformatted section and suspend content modification- Specified by:
closePreFormatted
in interfaceLineAppendable
- Returns:
- this
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toString
@NotNull public @NotNull java.lang.String toString(int maxBlankLines, int maxTrailingBlankLines, boolean withPrefixes)
Description copied from interface:LineAppendable
get the resulting text for all lines- Specified by:
toString
in interfaceLineAppendable
- Parameters:
maxBlankLines
- maximum blank lines to allow in the textmaxTrailingBlankLines
- maximum trailing blank lineswithPrefixes
- true if to include prefixes- Returns:
- resulting text
-
toSequence
@NotNull public @NotNull java.lang.CharSequence toSequence(int maxBlankLines, int maxTrailingBlankLines, boolean withPrefixes)
Description copied from interface:LineAppendable
get the resulting text for all lines- Specified by:
toSequence
in interfaceLineAppendable
- Parameters:
maxBlankLines
- maximum blank lines to allow in the textmaxTrailingBlankLines
- maximum trailing blank lineswithPrefixes
- true if to include prefixes- Returns:
- resulting text
-
appendTo
public <T extends java.lang.Appendable> T appendTo(@NotNull T out, boolean withPrefixes, int maxBlankLines, int maxTrailingBlankLines, int startLine, int endLine) throws java.io.IOException
Description copied from interface:LineAppendable
append lines to appendable with given maximum trailing blank lines and given prefix to add to all linesNOTE:
- Specified by:
appendTo
in interfaceLineAppendable
- Type Parameters:
T
- type of out- Parameters:
out
- appendable to output the resulting lineswithPrefixes
- true if to include prefixesmaxBlankLines
- maximum blank lines to allow in the body,maxTrailingBlankLines
- maximum trailing blank lines at the end, if <maxBlankLines then maxBlankLines will be used, if -1 then no trailing EOL will be addedstartLine
- line from which to start outputendLine
- line at which to stop output- Returns:
- out
- Throws:
java.io.IOException
- if thrown by appendable
-
appendToNoLine
public <T extends java.lang.Appendable> T appendToNoLine(@NotNull T out, boolean withPrefixes, int maxBlankLines, int maxTrailingBlankLines, int startLine, int endLine) throws java.io.IOException
- Throws:
java.io.IOException
-
append
@NotNull public @NotNull LineAppendable append(@NotNull @NotNull LineAppendable lineAppendable, int startLine, int endLine, boolean withPrefixes)
Description copied from interface:LineAppendable
Append lines from another line formatting appendable.NOTE: does not apply formatting options. Instead, appends already formatted lines as is
If there is an accumulating line, it will be terminated by an EOL before appending lines
- Specified by:
append
in interfaceLineAppendable
- Parameters:
lineAppendable
- lines to append, any unterminated lines will be terminated by aLineAppendable.line()
invocation.startLine
- start line to appendendLine
- end line to append, endLine is excluded.withPrefixes
- true if to include prefixes from the lineAppendable.- Returns:
- this
-
removeLinesRaw
private int removeLinesRaw(int startLine, int endLine)
Remove lines and return index from which line info must be recomputed- Parameters:
startLine
- start line index to removeendLine
- end line index to remove- Returns:
- index from which line info must be recomputed
-
recomputeLineInfo
void recomputeLineInfo(int startLine)
-
removeLines
@NotNull public @NotNull LineAppendable removeLines(int startLine, int endLine)
- Specified by:
removeLines
in interfaceLineAppendable
-
removeExtraBlankLines
public LineAppendable removeExtraBlankLines(int maxBlankLines, int maxTrailingBlankLines, int startLine, int endLine)
Description copied from interface:LineAppendable
Normalize the appendable by removing extra blank lines in the body or at the end of given line range- Specified by:
removeExtraBlankLines
in interfaceLineAppendable
- Parameters:
maxBlankLines
- maximum blank lines to allow in the bodymaxTrailingBlankLines
- maximum trailing blank lines ending on endLine, if <maxBlankLines then maxBlankLines will be usedstartLine
- line from which to start outputendLine
- line at which to stop output- Returns:
- this
-
setPrefixLength
public void setPrefixLength(int lineIndex, int prefixLength)
Description copied from interface:LineAppendable
Change prefix length for a given line without changing the line content- Specified by:
setPrefixLength
in interfaceLineAppendable
- Parameters:
lineIndex
- index of the lineprefixLength
- new prefix length
-
createLineInfo
private LineInfo createLineInfo(int lineIndex, @NotNull @NotNull java.lang.CharSequence prefix, @NotNull @NotNull java.lang.CharSequence content)
-
setLine
public void setLine(int lineIndex, @NotNull @NotNull java.lang.CharSequence prefix, @NotNull @NotNull java.lang.CharSequence content)
Description copied from interface:LineAppendable
Set content and prefix for a line- Specified by:
setLine
in interfaceLineAppendable
- Parameters:
lineIndex
- index of the lineprefix
- prefix of the linecontent
- content text of the line
-
insertLine
public void insertLine(int lineIndex, @NotNull @NotNull java.lang.CharSequence prefix, @NotNull @NotNull java.lang.CharSequence content)
Description copied from interface:LineAppendable
Insert a line at the index with given content and prefix for a line- Specified by:
insertLine
in interfaceLineAppendable
- Parameters:
lineIndex
- index of the lineprefix
- prefix of the linecontent
- content text of the line
-
tailBlankLinesToRemove
int tailBlankLinesToRemove(int endLine, int maxTrailingBlankLines)
-
getIndexedLineInfoProxy
@NotNull @NotNull LineAppendableImpl.IndexedLineInfoProxy getIndexedLineInfoProxy(int maxTrailingBlankLines, int startLine, int endLine)
-
getIndexedLineProxy
@NotNull @NotNull LineAppendableImpl.IndexedLineProxy getIndexedLineProxy(int maxTrailingBlankLines, int startLine, int endLine, boolean withPrefixes)
-
iterator
@NotNull public @NotNull java.util.Iterator<LineInfo> iterator()
Description copied from interface:LineAppendable
Full line iterator NOTE: will not issue line() to terminate any unterminated lines before iteration and will not include unterminated lines in iteration- Specified by:
iterator
in interfacejava.lang.Iterable<LineInfo>
- Specified by:
iterator
in interfaceLineAppendable
- Returns:
- iterator over lines
-
getLines
@NotNull public @NotNull java.lang.Iterable<BasedSequence> getLines(int maxTrailingBlankLines, int startLine, int endLine, boolean withPrefixes)
Description copied from interface:LineAppendable
Full line iterator over some linesNOTE: will issue line() to terminate any unterminated lines before iteration
- Specified by:
getLines
in interfaceLineAppendable
- Parameters:
maxTrailingBlankLines
- maximum trailing blank lines, -1 if trailing EOL should be removedstartLine
- start line indexendLine
- end line index, exclusivewithPrefixes
- true if prefixes should be included, else only non-prefix line text- Returns:
- iterator over lines
-
getLinesInfo
@NotNull public @NotNull java.lang.Iterable<LineInfo> getLinesInfo(int maxTrailingBlankLines, int startLine, int endLine)
Description copied from interface:LineAppendable
Full line iterator with line infoNOTE: will issue line() to terminate any unterminated lines before iteration
- Specified by:
getLinesInfo
in interfaceLineAppendable
- Parameters:
maxTrailingBlankLines
- maximum trailing blank lines, -1 if trailing EOL should be removedstartLine
- start line indexendLine
- end line index, exclusive- Returns:
- iterator over lines
-
-