public interface String_To_Justified extends IsTransformer<String,StrBuilder>
Converts a string to a justified string of given length. If the given string length is less than the required length, it will be stretched by inserting white spaces. The returned string will be of the required length, blank strings will have only blanks characters.
The method can be further customized by - Setting an inner white space character - replace all white spaces in the text with that character
The default length is DEFAULT_LENGTH.
The default inner white space character is DEFAULT_INNER_WHITESPACE_CHARACTER.
The actual return object is of type StrBuilder to minimize the creation of lots of strings for more complex transformations.
An implementation can chose to provide a builder to append the padded string to as well.
| Modifier and Type | Field and Description |
|---|---|
static char |
DEFAULT_INNER_WHITESPACE_CHARACTER
Default white space replacement character, set to ' '.
|
static int |
DEFAULT_LENGTH
The default width, set to 80.
|
| Modifier and Type | Method and Description |
|---|---|
static StrBuilder |
convert(String s,
int length)
Returns justified string of given length.
|
static StrBuilder |
convert(String s,
int length,
Character innerWsChar)
Returns justified string of given length.
|
static StrBuilder |
convert(String s,
int length,
Character innerWsChar,
StrBuilder builder)
Returns justified string of given length.
|
static StrBuilder |
convert(String s,
int length,
StrBuilder builder)
Returns justified string of given length.
|
static String_To_Justified |
create(int length,
Character innerWsChar,
StrBuilder builder)
Creates a transformer that converts a string to a justified string of given length.
|
default StrBuilder |
getBuilderForAppend()
Returns a builder to append the justified string to, rather than creating a new builder.
|
default Character |
getInnerWsChar()
Returns the white space replacement character.
|
default int |
getLength()
Returns the required length for the conversion.
|
default StrBuilder |
transform(String s)
Transforms from one representation to another.
|
apply, transformstatic final int DEFAULT_LENGTH
The default width, set to 80.
static final char DEFAULT_INNER_WHITESPACE_CHARACTER
Default white space replacement character, set to ' '.
default int getLength()
Returns the required length for the conversion.
DEFAULT_LENGTHdefault Character getInnerWsChar()
Returns the white space replacement character.
DEFAULT_INNER_WHITESPACE_CHARACTERdefault StrBuilder getBuilderForAppend()
Returns a builder to append the justified string to, rather than creating a new builder.
default StrBuilder transform(String s)
TransformerTransforms from one representation to another.
transform in interface Transformer<String,StrBuilder>s - input representationstatic String_To_Justified create(int length, Character innerWsChar, StrBuilder builder)
Creates a transformer that converts a string to a justified string of given length.
length - the required length (must be >0)innerWsChar - inner white space replacement characterbuilder - an optional builder to append the padded string to, used if set, ignored if nullNullPointerException - if an argument was unexpectedly nullIllegalArgumentException - if an argument was illegalinterface description for how the converter worksstatic StrBuilder convert(String s, int length)
Returns justified string of given length.
s - input stringlength - the required length (must be >0)NullPointerException - if an argument was unexpectedly nullIllegalArgumentException - if an argument was illegalinterface description for how the conversion worksstatic StrBuilder convert(String s, int length, Character innerWsChar)
Returns justified string of given length.
s - input stringlength - the required length (must be >0)innerWsChar - inner white space replacement character, default is used if nullNullPointerException - if an argument was unexpectedly nullIllegalArgumentException - if an argument was illegalinterface description for how the conversion worksstatic StrBuilder convert(String s, int length, StrBuilder builder)
Returns justified string of given length.
s - input stringlength - the required length (must be >0)builder - an optional builder to append the padded string to, used if set, ignored if nullNullPointerException - if an argument was unexpectedly nullIllegalArgumentException - if an argument was illegalinterface description for how the conversion worksstatic StrBuilder convert(String s, int length, Character innerWsChar, StrBuilder builder)
Returns justified string of given length.
s - input stringlength - the required length (must be >0)innerWsChar - inner white space replacement character, default is used if nullbuilder - an optional builder to append the padded string to, used if set, ignored if nullNullPointerException - if an argument was unexpectedly nullIllegalArgumentException - if an argument was illegalinterface description for how the conversion worksCopyright © 2016–2017. All rights reserved.