T
- The base type of objects parsed and formatted by this class.public abstract class TabularFormat<T> extends CompoundFormat<T>
beforeFill
, fillCharacter
and columnSeparator
)
for easier usage in format(…)
method implementations.
Subclasses can use those fields like below:
Formatting table without border:
TableAppender table = new TableAppender(out, ""); // ... do some work, then add a column separator: table.append(beforeFill); table.nextColumn(fillCharacter); table.append(columnSeparator);
Formatting table with a border:
TableAppender table = new TableAppender(out, columnSeparator); // ... do some work, then add a column separator: table.append(beforeFill); table.nextColumn(fillCharacter);
TableAppender
,
Serialized FormDefined in the sis-utility
module
Format.Field
Modifier and Type | Field and Description |
---|---|
protected String |
beforeFill
The string to write before the
fillCharacter , or an empty string if none. |
protected String |
columnSeparator
The string to write after the
fillCharacter , or an empty string if none. |
protected char |
fillCharacter
The character to repeat after the content of a cell for alignment with the next column.
|
protected String |
lineSeparator
The line separator to use for formatting the tree.
|
protected boolean |
omitTrailingNulls
true if the trailing null values shall be omitted at formatting time. |
Constructor and Description |
---|
TabularFormat(Locale locale,
TimeZone timezone)
Creates a new tabular format.
|
Modifier and Type | Method and Description |
---|---|
protected Matcher |
getColumnSeparatorMatcher(CharSequence text)
Returns a matcher for the column separators in the given text.
|
String |
getColumnSeparatorPattern()
Returns the pattern of characters used in column separators.
|
String |
getLineSeparator()
Returns the current line separator.
|
void |
setColumnSeparatorPattern(String pattern)
Sets the pattern of the characters to insert between the columns.
|
void |
setLineSeparator(String separator)
Sets the line separator.
|
clone, createFormat, format, format, getFormat, getLocale, getTimeZone, getValueType, parse, parseObject, parseObject
format, formatToCharacterIterator
protected String lineSeparator
getLineSeparator()
,
setLineSeparator(String)
protected String columnSeparator
fillCharacter
, or an empty string if none.
This is the sequence of characters after the "[ ]
" pair of brackets in the
pattern given to the setColumnSeparatorPattern(String)
method.protected char fillCharacter
[ ]
" pair of brackets in the pattern given
to the setColumnSeparatorPattern(String)
method.
Subclasses will typically use this value in calls to TableAppender.nextColumn(char)
.
protected String beforeFill
fillCharacter
, or an empty string if none.
This is the sequence of characters before the "[ ]
" pair of brackets in the
pattern given to the setColumnSeparatorPattern(String)
method.protected boolean omitTrailingNulls
true
if the trailing null
values shall be omitted at formatting time.
This flag is controlled by the presence or absence of the '?'
character at the
beginning of the pattern given to the setColumnSeparatorPattern(String)
method.public TabularFormat(Locale locale, TimeZone timezone)
locale
- The locale to use for numbers, dates and angles formatting,
or null
for the root locale.timezone
- The timezone, or null
for UTC.public String getLineSeparator()
public void setLineSeparator(String separator)
separator
- The new line separator.public String getColumnSeparatorPattern()
setColumnSeparatorPattern(String)
for a description of the pattern syntax.public void setColumnSeparatorPattern(String pattern) throws IllegalArgumentException
"[ ]"
pair of bracket, with exactly one character
between them. This character will be repeated as many time as needed for columns alignment.
The formatting pattern can optionally be followed by a regular expression to be used at
parsing time. If omitted, the parsing pattern will be inferred from the formatting pattern.
If specified, then the parse
method will invoke
the Matcher.find()
method for determining the column boundaries.
The characters listed below have special meaning in the pattern. Other characters are appended as-is between the columns.
Character(s) | Meaning |
---|---|
'?' | Omit the column separator for trailing null values. |
"[ ]" | Repeat the character between bracket as needed. |
'/' | Separate the formatting pattern from the parsing pattern. |
'\\' | Escape any of the characters listed in this table. |
'?'
shall be the first character in the pattern.'/'
is present, anything on its right side shall be compliant
with the Pattern
syntax."?……[…] "
pattern means "If the next value is non-null, then insert the
"……"
string, repeat the '…'
character as many time as needed (may be zero),
then insert a space".
pattern
- The pattern of the new column separator.IllegalArgumentException
- If the given pattern is illegal.protected Matcher getColumnSeparatorMatcher(CharSequence text)
parse(…)
implementations.text
- The text for which to get a matcher.Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.