Class AbstractColumn
java.lang.Object
io.github.kelsoncm.fwf.columns.AbstractColumn
- Direct Known Subclasses:
CharColumn, DateTimeColumn, PositiveIntegerColumn
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
FieldsModifier and TypeFieldDescriptionprotected final StringHuman-readable description of the column.protected final StringThe unique name of the column.protected final intThe fixed character length (size) of the column.protected Integer1-based starting character position of the column within a line. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractColumn(String name, int size) Constructs a newAbstractColumnwith a name and size.AbstractColumn(String name, int size, String description) Constructs a newAbstractColumnwith a name, size, and description. -
Method Summary
Modifier and TypeMethodDescriptionGets the column description.intgetEnd()Calculates and returns the 1-based end position of the column.getName()Gets the column name.intgetSize()Gets the column size in characters.getStart()Gets the 1-based start position of the column.voidSets the 1-based start position of the column.abstract StringFormats a domain value into a fixed-width string representation of exact column size.Converts a raw fixed-width string slice into a parsed object value.protected StringvalidateToStrSize(String value) Validates that the formatted string output exactly matches the column size.
-
Field Details
-
name
The unique name of the column. -
size
protected final int sizeThe fixed character length (size) of the column. -
description
Human-readable description of the column. -
start
1-based starting character position of the column within a line.
-
-
Constructor Details
-
AbstractColumn
Constructs a newAbstractColumnwith a name, size, and description.- Parameters:
name- the column name, must not be null or blanksize- the fixed character size of the column, must be greater than 0description- human-readable description of the column, defaults to name if null- Throws:
NullPointerException- ifnameis nullIllegalArgumentException- ifnameis blank orsize<= 0
-
AbstractColumn
Constructs a newAbstractColumnwith a name and size.- Parameters:
name- the column name, must not be null or blanksize- the fixed character size of the column, must be greater than 0- Throws:
NullPointerException- ifnameis nullIllegalArgumentException- ifnameis blank orsize<= 0
-
-
Method Details
-
getName
-
getSize
public int getSize()Gets the column size in characters.- Returns:
- column size
-
getDescription
-
getStart
Gets the 1-based start position of the column.- Returns:
- 1-based start index, or null if not yet positioned
-
setStart
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- ifstartis nullIllegalArgumentException- ifstart<= 0
-
toValue
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- ifsliceis null or does not match column size
-
validateToStrSize
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
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
-