public class FixedWidthFields extends Object implements Cloneable
Constructor and Description |
---|
FixedWidthFields(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. |
FixedWidthFields(int... fieldLengths)
Creates a new instance initialized with the lengths of all fields in a fixed-width record.
|
FixedWidthFields(LinkedHashMap<String,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(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(String name,
int length)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(String name,
int length,
char padding)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(String name,
int length,
FieldAlignment alignment)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(String name,
int length,
FieldAlignment alignment,
char padding)
Adds the length of the next field in a fixed-width record.
|
FixedWidthFields |
addField(String name,
int startPosition,
int endPosition)
Adds the range of the next field in a fixed-width record.
|
FixedWidthFields |
addField(String name,
int startPosition,
int endPosition,
char padding)
Adds the range of the next field in a fixed-width record.
|
FixedWidthFields |
addField(String name,
int startPosition,
int endPosition,
FieldAlignment alignment)
Adds the range of the next field in a fixed-width record.
|
FixedWidthFields |
addField(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(Class beanClass)
Creates a new instance initialized from
FixedWidth annotations in the fields and methods of a given class. |
static FixedWidthFields |
forWriting(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(String fieldName)
Returns the alignment of a given field.
|
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
|
NormalizedString[] |
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.
|
int |
getFieldsPerRecord()
Returns the number of fields in a fixed-width record
|
int |
indexOf(String fieldName)
Returns the index of a field name.
|
void |
keepPaddingOn(int position,
int... positions)
Configures a given list of fields to retain the padding character in any parsed values,
overriding the any default set for the whole input in
FixedWidthParserSettings.getKeepPadding() |
void |
keepPaddingOn(String name,
String... names)
Configures a given list of fields to retain the padding character in any parsed values,
overriding the any default set for the whole input in
FixedWidthParserSettings.getKeepPadding() |
void |
setAlignment(FieldAlignment alignment,
int... positions)
Applies alignment to a given list of fields
|
void |
setAlignment(FieldAlignment alignment,
String... names)
Applies alignment to a given list of fields
|
void |
setFieldLength(int position,
int newLength)
Modifies the length of a given field
|
void |
setFieldLength(String name,
int newLength)
Modifies the length of a given field
|
void |
setPadding(char padding,
int... positions)
Applies a custom padding character to a given list of fields
|
void |
setPadding(char padding,
String... names)
Applies a custom padding character to a given list of fields
|
void |
stripPaddingFrom(int position,
int... positions)
Configures a given list of fields to remove the padding character in any parsed values,
overriding the any default set for the whole input in
FixedWidthParserSettings.getKeepPadding() |
void |
stripPaddingFrom(String name,
String... names)
Configures a given list of fields to remove the padding character in any parsed values,
overriding the any default set for the whole input in
FixedWidthParserSettings.getKeepPadding() |
String |
toString() |
public FixedWidthFields(LinkedHashMap<String,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(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(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.public static FixedWidthFields forParsing(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(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(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(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(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(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 fieldpublic 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(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(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(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(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 fieldpublic int getFieldsPerRecord()
public NormalizedString[] getFieldNames()
public int[] getFieldLengths()
public void setFieldLength(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, String... names)
alignment
- the alignment to applynames
- the names of the fields that should be alignedpublic int indexOf(String fieldName)
IllegalArgumentException
will be thrown if no names have been defined.fieldName
- the name of the field to be searchedpublic FieldAlignment getAlignment(int position)
position
- the index of the field whose alignment will be returnedpublic FieldAlignment getAlignment(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.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, String... names)
padding
- the padding to applynames
- the names of the fields that should use the given padding characterpublic void keepPaddingOn(int position, int... positions)
FixedWidthParserSettings.getKeepPadding()
position
- the positions of the fields that should keep the padding characterpositions
- additional positionspublic void keepPaddingOn(String name, String... names)
FixedWidthParserSettings.getKeepPadding()
name
- the name of the first field that should keep the padding characternames
- the names of more fields that should keep the padding characterpublic void stripPaddingFrom(int position, int... positions)
FixedWidthParserSettings.getKeepPadding()
position
- the positions of the fields that should keep the padding characterpositions
- additional positionspublic void stripPaddingFrom(String name, String... names)
FixedWidthParserSettings.getKeepPadding()
name
- the name of the first field that have any padding characters removednames
- the names of the fields that should have any padding characters removedprotected FixedWidthFields clone()
Copyright © 2022 Univocity Software Pty Ltd. All rights reserved.