Class FieldPadding

  • Direct Known Subclasses:
    FixedLengthFieldPadding

    public class FieldPadding
    extends java.lang.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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static char LEFT
      Left justification
      static char RIGHT
      Right justification
    • Constructor Summary

      Constructors 
      Constructor Description
      FieldPadding()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      java.lang.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.
      java.lang.String pad​(java.lang.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​(java.lang.String paddedNull)
      Sets the padded field text for a null value.
      void setPropertyType​(java.lang.Class<?> type)
      Sets the property type of the field.
      java.lang.String unpad​(java.lang.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
    • Constructor Detail

      • FieldPadding

        public 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 java.lang.String pad​(java.lang.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 java.lang.String unpad​(java.lang.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 java.lang.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​(java.lang.Class<?> type)
        Sets the property type of the field.
        Parameters:
        type - the property type
      • setPaddedNull

        protected void setPaddedNull​(java.lang.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