- java.lang.Object
-
- com.pervasive.datarush.schema.FixedWidthTextRecord
-
- All Implemented Interfaces:
RecordTextSchema<FixedSizeTextType>,TextSchema
public class FixedWidthTextRecord extends Object
A definition of a fixed-width record in a text file. As fields as fixed-size, structured text file readers and writers can identify fields based on their position within the record.
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,TextField<T>>textFieldsByName
-
Constructor Summary
Constructors Constructor Description FixedWidthTextRecord()Defines an empty fixed-width record.FixedWidthTextRecord(TextConversionDefaults defaults)Defines an empty fixed-width record with the specified text conversion behavior.FixedWidthTextRecord(TextConversionDefaults defaults, Map<String,FixedSizeTextType> fieldTypes)Defines a record with the specified text conversion behavior and fields.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TokenFormattercreateFieldFormatter(String fieldName)Creates a new formatter for values of the specified field.TokenParsercreateFieldParser(String fieldName)Creates a new parser for values of the specified field.voiddefineField(String name, T type)Defines a new field in the record with the specified name and type.voiddefineField(String name, T type, FieldDomain domain)Defines a new field in the record with the specified name and type.TextConversionDefaultsgetDefaults()Gets the default conversion behaviors for fields in the schema which do not explicitly define any.intgetFieldCount()Gets the number of fields defined in the record.FieldDomaingetFieldDomain(String name)Gets the domain of the specified field in the record.List<String>getFieldNames()Gets the names of the fields defined in the record.intgetFieldOffset(String name)Gets the offset the the specified field from the start of the record.intgetFieldSize(String name)Gets the size of the specified field.TgetFieldType(String name)Gets the type of the specified fields in the record.intgetRecordLength()The defined length of the record.List<TextField<FixedSizeTextType>>getTextFields()RecordTokenTypegetTokenType()Gets the type of the token representation of the text record.booleanisFieldDefined(String name)Indicates whether a field with the given name is already defined.voidsetFieldType(String name, T newType)Modifies the value conversion scheme for an existing field.
-
-
-
Field Detail
-
textFieldsByName
protected final Map<String,TextField<T extends TextDataType>> textFieldsByName
-
-
Constructor Detail
-
FixedWidthTextRecord
public FixedWidthTextRecord()
Defines an empty fixed-width record. Default text conversion behavior is used.An empty record definition is not meaningful; it is expected that at least one field will be defined before the schema is used. The length of the record is determined from the size of the fields.
- See Also:
TextConversionDefaults
-
FixedWidthTextRecord
public FixedWidthTextRecord(TextConversionDefaults defaults)
Defines an empty fixed-width record with the specified text conversion behavior.An empty record definition is not meaningful; it is expected that at least one field will be defined before the schema is used. The length of the record is determined from the size of the fields.
- Parameters:
defaults- text conversion behavior to apply by default to the schema
-
FixedWidthTextRecord
public FixedWidthTextRecord(TextConversionDefaults defaults, Map<String,FixedSizeTextType> fieldTypes)
Defines a record with the specified text conversion behavior and fields. The field order is the iteration order of the provided field mapping.- Parameters:
defaults- default text conversion behavior for the schemafieldTypes- the defined fields in the record schema default to the schema
-
-
Method Detail
-
getRecordLength
public int getRecordLength()
The defined length of the record.- Returns:
- the length of the record in characters
-
getTextFields
public List<TextField<FixedSizeTextType>> getTextFields()
-
getFieldSize
public int getFieldSize(String name)
Gets the size of the specified field.- Parameters:
name- the field for which to report the size. This field must exist in the schema.- Returns:
- the defined size of the field
-
getFieldOffset
public int getFieldOffset(String name)
Gets the offset the the specified field from the start of the record.- Parameters:
name- the field for which to calculate the offset. This field must exist in the schema.- Returns:
- the offset from the start of the record, measured in characters
-
getDefaults
public final TextConversionDefaults getDefaults()
Description copied from interface:RecordTextSchemaGets the default conversion behaviors for fields in the schema which do not explicitly define any. These include settings such as the null indicator for values and whether string values are trimmed or preserved as is.- Specified by:
getDefaultsin interfaceRecordTextSchema<T extends TextDataType>- Returns:
- the default behavior for the schema
-
getTokenType
public final RecordTokenType getTokenType()
Description copied from interface:RecordTextSchemaGets the type of the token representation of the text record. The fields of the resulting type are in the same order and have the same name as the fields in the schema.- Specified by:
getTokenTypein interfaceRecordTextSchema<T extends TextDataType>- Returns:
- the token type representing the schema
-
getFieldCount
public final int getFieldCount()
Description copied from interface:RecordTextSchemaGets the number of fields defined in the record.- Specified by:
getFieldCountin interfaceRecordTextSchema<T extends TextDataType>- Returns:
- the number of defined fields
-
getFieldNames
public final List<String> getFieldNames()
Description copied from interface:RecordTextSchemaGets the names of the fields defined in the record. The names are returned in the order they were defined.- Specified by:
getFieldNamesin interfaceRecordTextSchema<T extends TextDataType>- Returns:
- a list of defined field names
-
isFieldDefined
public final boolean isFieldDefined(String name)
Description copied from interface:RecordTextSchemaIndicates whether a field with the given name is already defined.- Specified by:
isFieldDefinedin interfaceRecordTextSchema<T extends TextDataType>- Parameters:
name- the field to check- Returns:
trueif a field with the name is defined in the schema,falseotherwise.
-
defineField
public final void defineField(String name, T type)
Defines a new field in the record with the specified name and type.- Parameters:
name- the name associated with the field. The name must be unique amongst all defined fields.type- specifies how to convert between text and token values
-
defineField
public final void defineField(String name, T type, FieldDomain domain)
Defines a new field in the record with the specified name and type.- Parameters:
name- the name associated with the field. The name must be unique amongst all defined fields.type- specifies how to convert between text and token values
-
getFieldType
public final T getFieldType(String name)
Description copied from interface:RecordTextSchemaGets the type of the specified fields in the record. The names are returned in the order they were defined.- Specified by:
getFieldTypein interfaceRecordTextSchema<T extends TextDataType>- Parameters:
name- the field for which to fetch the type- Returns:
- the text type of the named field
-
getFieldDomain
public final FieldDomain getFieldDomain(String name)
Description copied from interface:RecordTextSchemaGets the domain of the specified field in the record.- Specified by:
getFieldDomainin interfaceRecordTextSchema<T extends TextDataType>- Parameters:
name- the field for which to fetch the domain- Returns:
- the domain of the named field
-
setFieldType
public final void setFieldType(String name, T newType)
Modifies the value conversion scheme for an existing field.- Parameters:
name- the field to modify. This field must exist in the schema.newType- specifies how to convert between text and token values
-
createFieldParser
public final TokenParser createFieldParser(String fieldName)
Description copied from interface:RecordTextSchemaCreates a new parser for values of the specified field.- Specified by:
createFieldParserin interfaceRecordTextSchema<T extends TextDataType>- Parameters:
fieldName- the field for which to obtain a parser- Returns:
- a parser for converting text values to token values for the field
-
createFieldFormatter
public final TokenFormatter createFieldFormatter(String fieldName)
Description copied from interface:RecordTextSchemaCreates a new formatter for values of the specified field.- Specified by:
createFieldFormatterin interfaceRecordTextSchema<T extends TextDataType>- Parameters:
fieldName- the field for which to obtain a formatter- Returns:
- a formatter for converting token values to text values for the field
-
-