public class FixedWidthFields
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
private java.util.List<FieldAlignment> |
fieldAlignment |
private java.util.List<java.lang.Integer> |
fieldLengths |
private java.util.List<java.lang.String> |
fieldNames |
private java.util.List<java.lang.Character> |
fieldPadding |
private java.util.List<java.lang.Boolean> |
fieldsToIgnore |
private boolean |
noNames |
private int |
totalLength |
Modifier | Constructor and Description |
---|---|
|
FixedWidthFields(java.lang.Class beanClass)
Deprecated.
use
forParsing(Class) and forWriting(Class) to initialize the fields from the given
class and filter out getters and setters that target the same field. If the given class has any annotated methods
only the setters will be used, making it usable only for parsing. |
private |
FixedWidthFields(java.lang.Class beanClass,
MethodFilter methodFilter)
Creates a new instance initialized from
FixedWidth annotations in the fields of a given class. |
|
FixedWidthFields(int... fieldLengths)
Creates a new instance initialized with the lengths of all fields in a fixed-width record.
|
|
FixedWidthFields(java.util.LinkedHashMap<java.lang.String,java.lang.Integer> fields)
Defines a sequence of field names used to refer to columns in the input/output text of an entity, along with their lengths.
|
|
FixedWidthFields(java.lang.String[] headers,
int[] lengths)
Defines a sequence of field names used to refer to columns in the input/output text of an entity, along with their lengths.
|
Modifier and Type | Method and Description |
---|---|
FixedWidthFields |
addField(int length)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(int length,
char padding)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(int length,
FieldAlignment alignment)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(int length,
FieldAlignment alignment,
char padding)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(int startPosition,
int endPosition)
Adds the range of the next field in a fixed-width record.
|
FixedWidthFields |
addField(int startPosition,
int endPosition,
char padding)
Adds the range of the next field in a fixed-width record.
|
FixedWidthFields |
addField(int startPosition,
int endPosition,
FieldAlignment alignment)
Adds the range of the next field in a fixed-width record.
|
FixedWidthFields |
addField(int startPosition,
int endPosition,
FieldAlignment alignment,
char padding)
Adds the range of the next field in a fixed-width record.
|
FixedWidthFields |
addField(java.lang.String name,
int length)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(java.lang.String name,
int length,
char padding)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(java.lang.String name,
int length,
FieldAlignment alignment)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(java.lang.String name,
int length,
FieldAlignment alignment,
char padding)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(java.lang.String name,
int startPosition,
int endPosition)
Adds the range of the next field in a fixed-width record.
|
FixedWidthFields |
addField(java.lang.String name,
int startPosition,
int endPosition,
char padding)
Adds the range of the next field in a fixed-width record.
|
FixedWidthFields |
addField(java.lang.String name,
int startPosition,
int endPosition,
FieldAlignment alignment)
Adds the range of the next field in a fixed-width record.
|
FixedWidthFields |
addField(java.lang.String name,
int startPosition,
int endPosition,
FieldAlignment alignment,
char padding)
Adds the range of the next field in a fixed-width record.
|
protected FixedWidthFields |
clone() |
static FixedWidthFields |
forParsing(java.lang.Class beanClass)
Creates a new instance initialized from
FixedWidth annotations in the fields and methods of a given class. |
static FixedWidthFields |
forWriting(java.lang.Class beanClass)
Creates a new instance initialized from
FixedWidth annotations in the fields and methods of a given class. |
FieldAlignment |
getAlignment(int position)
Returns the alignment of a given field.
|
FieldAlignment |
getAlignment(java.lang.String fieldName)
Returns the alignment of a given field.
|
(package private) int[] |
getAllLengths() |
FieldAlignment[] |
getFieldAlignments()
Returns a copy of the sequence of alignment settings to apply over each field in the fixed-width record.
|
int[] |
getFieldLengths()
Returns a copy of the sequence of field lengths of a fixed-width record
|
java.lang.String[] |
getFieldNames()
Returns the name of each field in a fixed-width record, if any
|
char[] |
getFieldPaddings()
Returns a copy of the sequence of padding characters to apply over each field in the fixed-width record.
|
(package private) char[] |
getFieldPaddings(FixedWidthFormat format) |
int |
getFieldsPerRecord()
Returns the number of fields in a fixed-width record
|
(package private) boolean[] |
getFieldsToIgnore()
Returns the sequence of fields to ignore.
|
private <T> java.util.List<T> |
getSelectedElements(java.util.List<T> elements) |
int |
indexOf(java.lang.String fieldName)
Returns the index of a field name.
|
void |
setAlignment(FieldAlignment alignment,
int... positions)
Applies alignment to a given list of fields
|
void |
setAlignment(FieldAlignment alignment,
java.lang.String... names)
Applies alignment to a given list of fields
|
private void |
setAlignment(int position,
FieldAlignment alignment) |
void |
setFieldLength(int position,
int newLength)
Modifies the length of a given field
|
void |
setFieldLength(java.lang.String name,
int newLength)
Modifies the length of a given field
|
(package private) static void |
setHeadersIfPossible(FixedWidthFields fieldLengths,
CommonSettings settings) |
void |
setPadding(char padding,
int... positions)
Applies a custom padding character to a given list of fields
|
void |
setPadding(char padding,
java.lang.String... names)
Applies a custom padding character to a given list of fields
|
private void |
setPadding(int position,
char padding) |
java.lang.String |
toString() |
private void |
validateIndex(int position) |
private void |
validateLength(java.lang.String name,
int length) |
private java.util.List<java.lang.Integer> fieldLengths
private java.util.List<java.lang.Boolean> fieldsToIgnore
private java.util.List<java.lang.String> fieldNames
private java.util.List<FieldAlignment> fieldAlignment
private java.util.List<java.lang.Character> fieldPadding
private boolean noNames
private int totalLength
public FixedWidthFields(java.util.LinkedHashMap<java.lang.String,java.lang.Integer> fields)
CommonSettings.setHeaders(String...)
.fields
- a LinkedHashMap
containing the sequence of fields to be associated with each column in the input/output, with their respective length.public FixedWidthFields(java.lang.String[] headers, int[] lengths)
CommonSettings.setHeaders(String...)
.headers
- the sequence of fields to be associated with each column in the input/outputlengths
- the sequence of lengths to be associated with each given header. The size of this array must match the number of given headers.public FixedWidthFields(int... fieldLengths)
fieldLengths
- The number lengths of all fields in a fixed-width record. All lengths must be greater than 0.@Deprecated public FixedWidthFields(java.lang.Class beanClass)
forParsing(Class)
and forWriting(Class)
to initialize the fields from the given
class and filter out getters and setters that target the same field. If the given class has any annotated methods
only the setters will be used, making it usable only for parsing.FixedWidth
annotations in the fields and methods of a given class. Note that
all fields should additionally have the Parsed
annotation to configure header names and/or their positions.beanClass
- the class whose FixedWidth
annotations will be processed to configure this field list.private FixedWidthFields(java.lang.Class beanClass, MethodFilter methodFilter)
FixedWidth
annotations in the fields of a given class. Note that
all fields should additionally have the Parsed
annotation to configure header names and/or their positions.beanClass
- the class whose FixedWidth
annotations will be processed to configure this field list.methodFilter
- filter to apply over annotated methods when the fixed-width writer is reading data from beans (to write values to an output)
or writing values into beans (when parsing). It is used to choose either a "get" or a "set"
method annotated with Parsed
, when both methods target the same field.public static FixedWidthFields forParsing(java.lang.Class beanClass)
FixedWidth
annotations in the fields and methods of a given class. Note that
all fields should additionally have the Parsed
annotation to configure header names and/or their positions.
Only setter methods will be considered as fields.beanClass
- the class whose FixedWidth
annotations will be processed to configure this field list.FixedWidthFields
instance built with the FixedWidth
annotations found in the given class' attributes and methods (excluding getters)public static FixedWidthFields forWriting(java.lang.Class beanClass)
FixedWidth
annotations in the fields and methods of a given class. Note that
all fields should additionally have the Parsed
annotation to configure header names and/or their positions.
Only getter methods will be considered as fields.beanClass
- the class whose FixedWidth
annotations will be processed to configure this field list.FixedWidthFields
instance built with the FixedWidth
annotations found in the given class' attributes and methods (excluding setters)public FixedWidthFields addField(int startPosition, int endPosition)
startPosition
- starting position of the field.endPosition
- ending position of the fieldpublic FixedWidthFields addField(java.lang.String name, int startPosition, int endPosition)
name
- the name of the next field. It is not validated.startPosition
- starting position of the field.endPosition
- ending position of the fieldpublic FixedWidthFields addField(java.lang.String name, int startPosition, int endPosition, char padding)
name
- the name of the next field. It is not validated.startPosition
- starting position of the field.endPosition
- ending position of the fieldpadding
- the representation of unused space in this fieldpublic FixedWidthFields addField(java.lang.String name, int startPosition, int endPosition, FieldAlignment alignment)
name
- the name of the next field. It is not validated.startPosition
- starting position of the field.endPosition
- ending position of the fieldalignment
- the alignment of the fieldpublic FixedWidthFields addField(int startPosition, int endPosition, FieldAlignment alignment)
startPosition
- starting position of the field.endPosition
- ending position of the fieldalignment
- the alignment of the fieldpublic FixedWidthFields addField(int startPosition, int endPosition, FieldAlignment alignment, char padding)
startPosition
- starting position of the field.endPosition
- ending position of the fieldalignment
- the alignment of the fieldpadding
- the representation of unused space in this fieldpublic FixedWidthFields addField(int startPosition, int endPosition, char padding)
startPosition
- starting position of the field.endPosition
- ending position of the fieldpadding
- the representation of unused space in this fieldpublic FixedWidthFields addField(java.lang.String name, int startPosition, int endPosition, FieldAlignment alignment, char padding)
name
- the name of the next field. It is not validated.startPosition
- starting position of the field.endPosition
- ending position of the fieldalignment
- the alignment of the fieldpadding
- the representation of unused space in this fieldboolean[] getFieldsToIgnore()
public FixedWidthFields addField(int length)
length
- the length of the next field. It must be greater than 0.public FixedWidthFields addField(int length, FieldAlignment alignment)
length
- the length of the next field. It must be greater than 0.alignment
- the alignment of the fieldpublic FixedWidthFields addField(java.lang.String name, int length)
name
- the name of the next field. It is not validated.length
- the length of the next field. It must be greater than 0.public FixedWidthFields addField(java.lang.String name, int length, FieldAlignment alignment)
name
- the name of the next field. It is not validated.length
- the length of the next field. It must be greater than 0.alignment
- the alignment of the fieldpublic FixedWidthFields addField(int length, char padding)
length
- the length of the next field. It must be greater than 0.padding
- the representation of unused space in this fieldpublic FixedWidthFields addField(int length, FieldAlignment alignment, char padding)
length
- the length of the next field. It must be greater than 0.alignment
- the alignment of the fieldpadding
- the representation of unused space in this fieldpublic FixedWidthFields addField(java.lang.String name, int length, char padding)
name
- the name of the next field. It is not validated.length
- the length of the next field. It must be greater than 0.padding
- the representation of unused space in this fieldpublic FixedWidthFields addField(java.lang.String name, int length, FieldAlignment alignment, char padding)
name
- the name of the next field. It is not validated.length
- the length of the next field. It must be greater than 0.alignment
- the alignment of the fieldpadding
- the representation of unused space in this fieldprivate void validateLength(java.lang.String name, int length)
public int getFieldsPerRecord()
public java.lang.String[] getFieldNames()
private <T> java.util.List<T> getSelectedElements(java.util.List<T> elements)
public int[] getFieldLengths()
int[] getAllLengths()
public void setFieldLength(java.lang.String name, int newLength)
name
- the name of the field whose length must be alterednewLength
- the new length of the given fieldpublic void setFieldLength(int position, int newLength)
position
- the position of the field whose length must be alterednewLength
- the new length of the given fieldpublic void setAlignment(FieldAlignment alignment, int... positions)
alignment
- the alignment to applypositions
- the positions of the fields that should be alignedpublic void setAlignment(FieldAlignment alignment, java.lang.String... names)
alignment
- the alignment to applynames
- the names of the fields that should be alignedprivate void validateIndex(int position)
public int indexOf(java.lang.String fieldName)
IllegalArgumentException
will be thrown if no names have been defined.fieldName
- the name of the field to be searchedprivate void setAlignment(int position, FieldAlignment alignment)
public FieldAlignment getAlignment(int position)
position
- the index of the field whose alignment will be returnedpublic FieldAlignment getAlignment(java.lang.String fieldName)
IllegalArgumentException
will be thrown if no names have been defined.fieldName
- the name of the field whose alignment will be returnedpublic FieldAlignment[] getFieldAlignments()
public char[] getFieldPaddings()
'\0'
) is used to inform no padding has been explicitly set for a field, and that the
default padding character defined in FixedWidthFormat.getPadding()
should be used.char[] getFieldPaddings(FixedWidthFormat format)
public void setPadding(char padding, int... positions)
padding
- the padding to applypositions
- the positions of the fields that should use the given padding characterpublic void setPadding(char padding, java.lang.String... names)
padding
- the padding to applynames
- the names of the fields that should use the given padding characterprivate void setPadding(int position, char padding)
public java.lang.String toString()
toString
in class java.lang.Object
static void setHeadersIfPossible(FixedWidthFields fieldLengths, CommonSettings settings)
protected FixedWidthFields clone()
clone
in class java.lang.Object