public class FieldPadding extends Object
The method init()
must be called after all properties are set.
If optional is set to true, the field text may be padded with spaces regardless of the configured filler when a value does not exist.
Once configured, a FieldPadding object is thread-safe.
Modifier and Type | Field and Description |
---|---|
static char |
LEFT
Left justification
|
static char |
RIGHT
Right justification
|
Constructor and Description |
---|
FieldPadding()
Constructs a new FieldPadding.
|
Modifier and Type | Method and Description |
---|---|
char |
getFiller()
Returns the character used to pad field text.
|
char |
getJustify()
Returns the justification of the field text within its padding.
|
int |
getLength()
Returns the padded length of the field.
|
Class<?> |
getPropertyType()
Returns the property type of the field, or null if the field is not
bound to a bean object.
|
void |
init()
Initializes padding settings.
|
boolean |
isOptional()
Returns whether the field is optional.
|
String |
pad(String text)
Formats field text.
|
void |
setFiller(char filler)
Sets the character used to pad field text.
|
void |
setJustify(char justify)
Sets the justification of the field text within its padding.
|
void |
setLength(int length)
Sets the padded length of the field.
|
void |
setOptional(boolean required)
Sets whether the field is optional.
|
protected void |
setPaddedNull(String paddedNull)
Sets the padded field text for a null value.
|
void |
setPropertyType(Class<?> type)
Sets the property type of the field.
|
String |
unpad(String fieldText)
Removes padding from the field text.
|
public static final char RIGHT
public static final char LEFT
public void init()
pad(String)
or unpad(String)
is called.public String pad(String text)
text
- the field text to formatpublic String unpad(String fieldText)
fieldText
- the field text to remove paddingpublic char getFiller()
public void setFiller(char filler)
filler
- the filler characterpublic int getLength()
public void setLength(int length)
length
- the padded lengthpublic char getJustify()
public void setJustify(char justify)
public boolean isOptional()
public void setOptional(boolean required)
required
- true if optional, false otherwisepublic Class<?> getPropertyType()
public void setPropertyType(Class<?> type)
type
- the property typeprotected void setPaddedNull(String paddedNull)
paddedNull
- the field text for a null value