Class AbstractColumn

java.lang.Object
io.github.kelsoncm.fwf.columns.AbstractColumn
Direct Known Subclasses:
CharColumn, DateTimeColumn, PositiveIntegerColumn

public abstract class AbstractColumn extends Object
Base abstract class representing a column within a Fixed Width File layout.

Manages column metadata such as name, size, description, 1-based start/end position calculation, value parsing, and string formatting.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final String
    Human-readable description of the column.
    protected final String
    The unique name of the column.
    protected final int
    The fixed character length (size) of the column.
    protected Integer
    1-based starting character position of the column within a line.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractColumn(String name, int size)
    Constructs a new AbstractColumn with a name and size.
    AbstractColumn(String name, int size, String description)
    Constructs a new AbstractColumn with a name, size, and description.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the column description.
    int
    Calculates and returns the 1-based end position of the column.
    Gets the column name.
    int
    Gets the column size in characters.
    Gets the 1-based start position of the column.
    void
    Sets the 1-based start position of the column.
    abstract String
    toStr(Object value)
    Formats a domain value into a fixed-width string representation of exact column size.
    toValue(String slice)
    Converts a raw fixed-width string slice into a parsed object value.
    protected String
    Validates that the formatted string output exactly matches the column size.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • name

      protected final String name
      The unique name of the column.
    • size

      protected final int size
      The fixed character length (size) of the column.
    • description

      protected final String description
      Human-readable description of the column.
    • start

      protected Integer start
      1-based starting character position of the column within a line.
  • Constructor Details

    • AbstractColumn

      public AbstractColumn(String name, int size, String description)
      Constructs a new AbstractColumn with a name, size, and description.
      Parameters:
      name - the column name, must not be null or blank
      size - the fixed character size of the column, must be greater than 0
      description - human-readable description of the column, defaults to name if null
      Throws:
      NullPointerException - if name is null
      IllegalArgumentException - if name is blank or size <= 0
    • AbstractColumn

      public AbstractColumn(String name, int size)
      Constructs a new AbstractColumn with a name and size.
      Parameters:
      name - the column name, must not be null or blank
      size - the fixed character size of the column, must be greater than 0
      Throws:
      NullPointerException - if name is null
      IllegalArgumentException - if name is blank or size <= 0
  • Method Details

    • getName

      public String getName()
      Gets the column name.
      Returns:
      column name
    • getSize

      public int getSize()
      Gets the column size in characters.
      Returns:
      column size
    • getDescription

      public String getDescription()
      Gets the column description.
      Returns:
      column description
    • getStart

      public Integer getStart()
      Gets the 1-based start position of the column.
      Returns:
      1-based start index, or null if not yet positioned
    • setStart

      public void setStart(Integer start)
      Sets the 1-based start position of the column.
      Parameters:
      start - 1-based start index
    • getEnd

      public int getEnd()
      Calculates and returns the 1-based end position of the column.
      Returns:
      1-based end index
      Throws:
      NullPointerException - if start is null
      IllegalArgumentException - if start <= 0
    • toValue

      public Object toValue(String slice)
      Converts a raw fixed-width string slice into a parsed object value.
      Parameters:
      slice - raw substring sliced from a fixed-width line
      Returns:
      parsed value object
      Throws:
      IllegalArgumentException - if slice is null or does not match column size
    • validateToStrSize

      protected String validateToStrSize(String value)
      Validates that the formatted string output exactly matches the column size.
      Parameters:
      value - formatted string to check
      Returns:
      the verified string
      Throws:
      IllegalArgumentException - if string length does not equal column size
    • toStr

      public abstract String toStr(Object value)
      Formats a domain value into a fixed-width string representation of exact column size.
      Parameters:
      value - domain value to format
      Returns:
      fixed-width formatted string of length getSize()
      Throws:
      IllegalArgumentException - if the value cannot be serialized or formatted