Class RecordMetaDataImpl<C extends Context>
- java.lang.Object
-
- com.univocity.parsers.common.record.RecordMetaDataImpl<C>
-
- All Implemented Interfaces:
RecordMetaData
class RecordMetaDataImpl<C extends Context> extends java.lang.Object implements RecordMetaData
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Integer,java.lang.annotation.Annotation>
annotationHashes
(package private) C
context
private java.util.Map<java.lang.Class,Conversion>
conversionByType
private FieldConversionMapping
conversions
private java.util.Map<java.lang.Class,java.util.Map<java.lang.annotation.Annotation,Conversion>>
conversionsByAnnotation
private MetaData[]
indexMap
-
Constructor Summary
Constructors Constructor Description RecordMetaDataImpl(C context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) <T> java.lang.annotation.Annotation
buildAnnotation(java.lang.Class<T> type, java.lang.String args1, java.lang.String... args2)
(package private) static java.lang.annotation.Annotation
buildBooleanStringAnnotation(java.lang.String[] trueStrings, java.lang.String[] falseStrings)
boolean
containsColumn(java.lang.String headerName)
Queries whether a given header name exists in theRecord
s parsed from the inputprivate static java.lang.Object
convert(MetaData md, java.lang.String[] data, Conversion[] conversions)
private <T> T
convert(MetaData md, java.lang.String[] data, java.lang.Class<T> expectedType, Conversion[] conversions)
private <T> T
convert(MetaData md, java.lang.String[] data, java.lang.Class<T> type, T defaultValue, java.lang.annotation.Annotation annotation)
private java.lang.Object
convert(MetaData md, java.lang.String[] data, java.lang.Object defaultValue, Conversion[] conversions)
FieldSet<java.lang.String>
convertFields(Conversion... conversions)
Associates a sequence ofConversion
s to fields of a given set of field names<T extends java.lang.Enum<T>>
FieldSet<T>convertFields(java.lang.Class<T> enumType, Conversion... conversions)
Associates a sequence ofConversion
s to fields of a given set of fieldsFieldSet<java.lang.Integer>
convertIndexes(Conversion... conversions)
Associates a sequence ofConversion
s to fields of a given set of column indexesjava.lang.Object
defaultValueOf(int columnIndex)
Returns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object)
)java.lang.Object
defaultValueOf(java.lang.Enum<?> column)
Returns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object)
)java.lang.Object
defaultValueOf(java.lang.String headerName)
Returns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object)
)private FieldConversionMapping
getConversions()
MetaData
getMetaData(int index)
private MetaData
getMetaData(java.lang.Enum<?> column)
private MetaData
getMetaData(java.lang.String name)
(package private) <T> T
getObjectValue(java.lang.String[] data, int columnIndex, java.lang.Class<T> type, T defaultValue)
(package private) <T> T
getObjectValue(java.lang.String[] data, int columnIndex, java.lang.Class<T> type, T defaultValue, java.lang.String format, java.lang.String... formatOptions)
(package private) <T> T
getObjectValue(java.lang.String[] data, java.lang.Enum<?> column, java.lang.Class<T> type, T defaultValue)
(package private) <T> T
getObjectValue(java.lang.String[] data, java.lang.Enum<?> column, java.lang.Class<T> type, T defaultValue, java.lang.String format, java.lang.String... formatOptions)
(package private) <T> T
getObjectValue(java.lang.String[] data, java.lang.String headerName, java.lang.Class<T> type, T defaultValue)
(package private) <T> T
getObjectValue(java.lang.String[] data, java.lang.String headerName, java.lang.Class<T> type, T defaultValue, java.lang.String format, java.lang.String... formatOptions)
private NormalizedString[]
getValidatedHeaders()
(package private) java.lang.String
getValue(java.lang.String[] data, int columnIndex)
(package private) <T> T
getValue(java.lang.String[] data, int columnIndex, java.lang.Class<T> expectedType, Conversion[] conversions)
(package private) <T> T
getValue(java.lang.String[] data, int columnIndex, T defaultValue, Conversion[] conversions)
(package private) java.lang.String
getValue(java.lang.String[] data, java.lang.Enum<?> column)
(package private) <T> T
getValue(java.lang.String[] data, java.lang.Enum<?> column, java.lang.Class<T> expectedType, Conversion[] conversions)
(package private) <T> T
getValue(java.lang.String[] data, java.lang.Enum<?> column, T defaultValue, Conversion[] conversions)
(package private) java.lang.String
getValue(java.lang.String[] data, java.lang.String headerName)
(package private) <T> T
getValue(java.lang.String[] data, java.lang.String headerName, java.lang.Class<T> expectedType, Conversion[] conversions)
(package private) <T> T
getValue(java.lang.String[] data, java.lang.String headerName, T defaultValue, Conversion[] conversions)
java.lang.String[]
headers()
Returns the column names of theRecord
s parsed from the input.int
indexOf(java.lang.Enum<?> column)
Returns the index of a given columnint
indexOf(java.lang.String headerName)
Returns the index of a given columnprivate void
initializeMetadataConversions(java.lang.String[] data, MetaData md)
(package private) MetaData
metadataOf(int columnIndex)
(package private) MetaData
metadataOf(java.lang.Enum<?> column)
(package private) MetaData
metadataOf(java.lang.String headerName)
private static java.lang.annotation.Annotation
newFormatAnnotation(java.lang.String format, java.lang.String... formatOptions)
java.lang.String[]
selectedHeaders()
Returns the sequence of headers that have been selected.<T> void
setDefaultValueOfColumns(T defaultValue, int... columnIndexes)
Associates a default value with one or more columns, in case the values contained arenull
<T> void
setDefaultValueOfColumns(T defaultValue, java.lang.Enum<?>... columns)
Associates a default value with one or more columns, in case the values contained arenull
<T> void
setDefaultValueOfColumns(T defaultValue, java.lang.String... headerNames)
Associates a default value with one or more columns, in case the values contained arenull
void
setTypeOfColumns(java.lang.Class<?> type, int... columnIndexes)
Associates a type with one or more column.void
setTypeOfColumns(java.lang.Class<?> type, java.lang.Enum... columns)
Associates a type with one or more column.void
setTypeOfColumns(java.lang.Class<?> type, java.lang.String... headerNames)
Associates a type with one or more column.java.lang.Class<?>
typeOf(int columnIndex)
Returns the type associated with a given column, defined with the methodsetTypeOfColumns(type, columns)
java.lang.Class<?>
typeOf(java.lang.Enum<?> column)
Returns the type associated with a given column, defined with the methodsetTypeOfColumns(type, columns)
java.lang.Class<?>
typeOf(java.lang.String headerName)
Returns the type associated with a given column name, defined with the methodsetTypeOfColumns(type, columns)
-
-
-
Field Detail
-
conversionByType
private java.util.Map<java.lang.Class,Conversion> conversionByType
-
conversionsByAnnotation
private java.util.Map<java.lang.Class,java.util.Map<java.lang.annotation.Annotation,Conversion>> conversionsByAnnotation
-
annotationHashes
private java.util.Map<java.lang.Integer,java.lang.annotation.Annotation> annotationHashes
-
indexMap
private MetaData[] indexMap
-
conversions
private FieldConversionMapping conversions
-
-
Constructor Detail
-
RecordMetaDataImpl
RecordMetaDataImpl(C context)
-
-
Method Detail
-
getMetaData
private MetaData getMetaData(java.lang.String name)
-
getValidatedHeaders
private NormalizedString[] getValidatedHeaders()
-
getMetaData
private MetaData getMetaData(java.lang.Enum<?> column)
-
getMetaData
public MetaData getMetaData(int index)
-
indexOf
public int indexOf(java.lang.Enum<?> column)
Description copied from interface:RecordMetaData
Returns the index of a given column- Specified by:
indexOf
in interfaceRecordMetaData
- Parameters:
column
- the column whose index will be returned- Returns:
- index of the given column
-
metadataOf
MetaData metadataOf(java.lang.String headerName)
-
metadataOf
MetaData metadataOf(java.lang.Enum<?> column)
-
metadataOf
MetaData metadataOf(int columnIndex)
-
indexOf
public int indexOf(java.lang.String headerName)
Description copied from interface:RecordMetaData
Returns the index of a given column- Specified by:
indexOf
in interfaceRecordMetaData
- Parameters:
headerName
- name of the column whose index will be returned- Returns:
- index of the given column
-
typeOf
public java.lang.Class<?> typeOf(java.lang.Enum<?> column)
Description copied from interface:RecordMetaData
Returns the type associated with a given column, defined with the methodsetTypeOfColumns(type, columns)
- Specified by:
typeOf
in interfaceRecordMetaData
- Parameters:
column
- the column whose type will be returned- Returns:
- the type of the given column
-
typeOf
public java.lang.Class<?> typeOf(java.lang.String headerName)
Description copied from interface:RecordMetaData
Returns the type associated with a given column name, defined with the methodsetTypeOfColumns(type, columns)
- Specified by:
typeOf
in interfaceRecordMetaData
- Parameters:
headerName
- name of the column whose type will be returned- Returns:
- the type of the given column
-
typeOf
public java.lang.Class<?> typeOf(int columnIndex)
Description copied from interface:RecordMetaData
Returns the type associated with a given column, defined with the methodsetTypeOfColumns(type, columns)
- Specified by:
typeOf
in interfaceRecordMetaData
- Parameters:
columnIndex
- the position of the column whose type will be returned- Returns:
- the type of the given column
-
setDefaultValueOfColumns
public <T> void setDefaultValueOfColumns(T defaultValue, java.lang.Enum<?>... columns)
Description copied from interface:RecordMetaData
Associates a default value with one or more columns, in case the values contained arenull
- Specified by:
setDefaultValueOfColumns
in interfaceRecordMetaData
- Type Parameters:
T
- type of the default value.- Parameters:
defaultValue
- the value to be used for the given column when the parsed result isnull
columns
- the columns to be associated with a default value.
-
setDefaultValueOfColumns
public <T> void setDefaultValueOfColumns(T defaultValue, java.lang.String... headerNames)
Description copied from interface:RecordMetaData
Associates a default value with one or more columns, in case the values contained arenull
- Specified by:
setDefaultValueOfColumns
in interfaceRecordMetaData
- Type Parameters:
T
- type of the default value.- Parameters:
defaultValue
- the value to be used for the given column when the parsed result isnull
headerNames
- the column names to be associated with a default value.
-
setDefaultValueOfColumns
public <T> void setDefaultValueOfColumns(T defaultValue, int... columnIndexes)
Description copied from interface:RecordMetaData
Associates a default value with one or more columns, in case the values contained arenull
- Specified by:
setDefaultValueOfColumns
in interfaceRecordMetaData
- Type Parameters:
T
- type of the default value.- Parameters:
defaultValue
- the value to be used for the given column when the parsed result isnull
columnIndexes
- the column indexes to be associated with a default value.
-
defaultValueOf
public java.lang.Object defaultValueOf(java.lang.Enum<?> column)
Description copied from interface:RecordMetaData
Returns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object)
)- Specified by:
defaultValueOf
in interfaceRecordMetaData
- Parameters:
column
- the column whose default value will be returned- Returns:
- the default value associated with the given column or
null
.
-
defaultValueOf
public java.lang.Object defaultValueOf(java.lang.String headerName)
Description copied from interface:RecordMetaData
Returns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object)
)- Specified by:
defaultValueOf
in interfaceRecordMetaData
- Parameters:
headerName
- the column name whose default value will be returned- Returns:
- the default value associated with the given column or
null
.
-
defaultValueOf
public java.lang.Object defaultValueOf(int columnIndex)
Description copied from interface:RecordMetaData
Returns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object)
)- Specified by:
defaultValueOf
in interfaceRecordMetaData
- Parameters:
columnIndex
- the column index whose default value will be returned- Returns:
- the default value associated with the given column or
null
.
-
getConversions
private FieldConversionMapping getConversions()
-
convertFields
public <T extends java.lang.Enum<T>> FieldSet<T> convertFields(java.lang.Class<T> enumType, Conversion... conversions)
Description copied from interface:RecordMetaData
Associates a sequence ofConversion
s to fields of a given set of fields- Specified by:
convertFields
in interfaceRecordMetaData
- Type Parameters:
T
- the enumeration type- Parameters:
enumType
- the type of the enumeration whose values represent headers in the inputRecord
sconversions
- the sequence of conversions to apply- Returns:
- (modifiable) set of fields to be selected and against which the given conversion sequence will be applied.
-
convertFields
public FieldSet<java.lang.String> convertFields(Conversion... conversions)
Description copied from interface:RecordMetaData
Associates a sequence ofConversion
s to fields of a given set of field names- Specified by:
convertFields
in interfaceRecordMetaData
- Parameters:
conversions
- the sequence of conversions to apply- Returns:
- (modifiable) set of fields names to be selected and against which the given conversion sequence will be applied.
-
convertIndexes
public FieldSet<java.lang.Integer> convertIndexes(Conversion... conversions)
Description copied from interface:RecordMetaData
Associates a sequence ofConversion
s to fields of a given set of column indexes- Specified by:
convertIndexes
in interfaceRecordMetaData
- Parameters:
conversions
- the sequence of conversions to apply- Returns:
- (modifiable) set of column indexes to be selected and against which the given conversion sequence will be applied.
-
headers
public java.lang.String[] headers()
Description copied from interface:RecordMetaData
Returns the column names of theRecord
s parsed from the input.If the headers are extracted from the input (i.e.
CommonParserSettings.isHeaderExtractionEnabled()
== true), then these values will be returned.If no headers are extracted from the input, then the configured headers in
CommonSettings.getHeaders()
will be returned.- Specified by:
headers
in interfaceRecordMetaData
- Returns:
- the headers associated with the
Record
s parsed from the input
-
selectedHeaders
public java.lang.String[] selectedHeaders()
Description copied from interface:RecordMetaData
Returns the sequence of headers that have been selected. If no selection has been made, all available headers will be returned, producing the same output as a call to methodRecordMetaData.headers()
.- Specified by:
selectedHeaders
in interfaceRecordMetaData
- Returns:
- the sequence of selected headers, or all headers if no selection has been made.
-
getValue
java.lang.String getValue(java.lang.String[] data, java.lang.String headerName)
-
getValue
java.lang.String getValue(java.lang.String[] data, int columnIndex)
-
getValue
java.lang.String getValue(java.lang.String[] data, java.lang.Enum<?> column)
-
convert
private <T> T convert(MetaData md, java.lang.String[] data, java.lang.Class<T> expectedType, Conversion[] conversions)
-
convert
private java.lang.Object convert(MetaData md, java.lang.String[] data, java.lang.Object defaultValue, Conversion[] conversions)
-
convert
private static java.lang.Object convert(MetaData md, java.lang.String[] data, Conversion[] conversions)
-
getValue
<T> T getValue(java.lang.String[] data, java.lang.String headerName, T defaultValue, Conversion[] conversions)
-
getValue
<T> T getValue(java.lang.String[] data, int columnIndex, T defaultValue, Conversion[] conversions)
-
getValue
<T> T getValue(java.lang.String[] data, java.lang.Enum<?> column, T defaultValue, Conversion[] conversions)
-
getValue
<T> T getValue(java.lang.String[] data, java.lang.String headerName, java.lang.Class<T> expectedType, Conversion[] conversions)
-
getValue
<T> T getValue(java.lang.String[] data, int columnIndex, java.lang.Class<T> expectedType, Conversion[] conversions)
-
getValue
<T> T getValue(java.lang.String[] data, java.lang.Enum<?> column, java.lang.Class<T> expectedType, Conversion[] conversions)
-
convert
private <T> T convert(MetaData md, java.lang.String[] data, java.lang.Class<T> type, T defaultValue, java.lang.annotation.Annotation annotation)
-
initializeMetadataConversions
private void initializeMetadataConversions(java.lang.String[] data, MetaData md)
-
getObjectValue
<T> T getObjectValue(java.lang.String[] data, java.lang.String headerName, java.lang.Class<T> type, T defaultValue)
-
getObjectValue
<T> T getObjectValue(java.lang.String[] data, int columnIndex, java.lang.Class<T> type, T defaultValue)
-
getObjectValue
<T> T getObjectValue(java.lang.String[] data, java.lang.Enum<?> column, java.lang.Class<T> type, T defaultValue)
-
getObjectValue
<T> T getObjectValue(java.lang.String[] data, java.lang.String headerName, java.lang.Class<T> type, T defaultValue, java.lang.String format, java.lang.String... formatOptions)
-
getObjectValue
<T> T getObjectValue(java.lang.String[] data, int columnIndex, java.lang.Class<T> type, T defaultValue, java.lang.String format, java.lang.String... formatOptions)
-
getObjectValue
<T> T getObjectValue(java.lang.String[] data, java.lang.Enum<?> column, java.lang.Class<T> type, T defaultValue, java.lang.String format, java.lang.String... formatOptions)
-
buildBooleanStringAnnotation
static java.lang.annotation.Annotation buildBooleanStringAnnotation(java.lang.String[] trueStrings, java.lang.String[] falseStrings)
-
newFormatAnnotation
private static java.lang.annotation.Annotation newFormatAnnotation(java.lang.String format, java.lang.String... formatOptions)
-
buildAnnotation
<T> java.lang.annotation.Annotation buildAnnotation(java.lang.Class<T> type, java.lang.String args1, java.lang.String... args2)
-
setTypeOfColumns
public void setTypeOfColumns(java.lang.Class<?> type, java.lang.Enum... columns)
Description copied from interface:RecordMetaData
Associates a type with one or more column. This allows the parsed data to be converted automatically to the given type when reading data from aRecord
, e.g.Record.toFieldObjectMap(String...)
will convert the selected field values to their respective types, and then set the result as the values in the map.- Specified by:
setTypeOfColumns
in interfaceRecordMetaData
- Parameters:
type
- the type to associate with a list of columncolumns
- the columns that will be associated with the given type.
-
setTypeOfColumns
public void setTypeOfColumns(java.lang.Class<?> type, java.lang.String... headerNames)
Description copied from interface:RecordMetaData
Associates a type with one or more column. This allows the parsed data to be converted automatically to the given type when reading data from aRecord
, e.g.Record.toFieldObjectMap(String...)
will convert the selected field values to their respective types, and then set the result as the values in the map.- Specified by:
setTypeOfColumns
in interfaceRecordMetaData
- Parameters:
type
- the type to associate with a list of columnheaderNames
- the columns that will be associated with the given type.
-
setTypeOfColumns
public void setTypeOfColumns(java.lang.Class<?> type, int... columnIndexes)
Description copied from interface:RecordMetaData
Associates a type with one or more column. This allows the parsed data to be converted automatically to the given type when reading data from aRecord
, e.g.Record.toFieldObjectMap(String...)
will convert the selected field values to their respective types, and then set the result as the values in the map.- Specified by:
setTypeOfColumns
in interfaceRecordMetaData
- Parameters:
type
- the type to associate with a list of columncolumnIndexes
- the columns that will be associated with the given type.
-
containsColumn
public boolean containsColumn(java.lang.String headerName)
Description copied from interface:RecordMetaData
Queries whether a given header name exists in theRecord
s parsed from the input- Specified by:
containsColumn
in interfaceRecordMetaData
- Parameters:
headerName
- name of the header- Returns:
true
if the given header name exists in the input records, otherwisefalse
-
-