BeanIO 2.0.4

org.beanio.internal.parser.format
Class FieldPadding

java.lang.Object
  extended by org.beanio.internal.parser.format.FieldPadding
Direct Known Subclasses:
FixedLengthFieldPadding

public class FieldPadding
extends Object

Provides field padding functionality. By default, padded fields are left justified and padded using a space.

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.

Since:
2.0
Author:
Kevin Seim

Field Summary
static char LEFT
          Left justification
static char RIGHT
          Right justification
 
Constructor Summary
FieldPadding()
          Constructs a new FieldPadding.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RIGHT

public static final char RIGHT
Right justification

See Also:
Constant Field Values

LEFT

public static final char LEFT
Left justification

See Also:
Constant Field Values
Constructor Detail

FieldPadding

public FieldPadding()
Constructs a new FieldPadding.

Method Detail

init

public void init()
Initializes padding settings. This method must be invoked before pad(String) or unpad(String) is called.


pad

public String pad(String text)
Formats field text. If text.length() exceeds the padding length, the text will be truncated, otherwise it will be padded with filler.

Parameters:
text - the field text to format
Returns:
the formatted field text

unpad

public String unpad(String fieldText)
Removes padding from the field text.

Parameters:
fieldText - the field text to remove padding
Returns:
the unpadded field text

getFiller

public char getFiller()
Returns the character used to pad field text.

Returns:
the filler character

setFiller

public void setFiller(char filler)
Sets the character used to pad field text.

Parameters:
filler - the filler character

getLength

public int getLength()
Returns the padded length of the field.

Returns:
the padded length

setLength

public void setLength(int length)
Sets the padded length of the field.

Parameters:
length - the padded length

getJustify

public char getJustify()
Returns the justification of the field text within its padding.

Returns:
either LEFT or RIGHT

setJustify

public void setJustify(char justify)
Sets the justification of the field text within its padding.

Parameters:
justify - either LEFT or RIGHT

isOptional

public boolean isOptional()
Returns whether the field is optional.

Returns:
true if optional, false otherwise

setOptional

public void setOptional(boolean required)
Sets whether the field is optional.

Parameters:
required - true if optional, false otherwise

getPropertyType

public Class<?> getPropertyType()
Returns the property type of the field, or null if the field is not bound to a bean object.

Returns:
the property type

setPropertyType

public void setPropertyType(Class<?> type)
Sets the property type of the field.

Parameters:
type - the property type

setPaddedNull

protected void setPaddedNull(String paddedNull)
Sets the padded field text for a null value. Defaults to the empty string.

Parameters:
paddedNull - the field text for a null value

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim