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) Ccontextprivate java.util.Map<java.lang.Class,Conversion>conversionByTypeprivate FieldConversionMappingconversionsprivate java.util.Map<java.lang.Class,java.util.Map<java.lang.annotation.Annotation,Conversion>>conversionsByAnnotationprivate 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.AnnotationbuildAnnotation(java.lang.Class<T> type, java.lang.String args1, java.lang.String... args2)(package private) static java.lang.annotation.AnnotationbuildBooleanStringAnnotation(java.lang.String[] trueStrings, java.lang.String[] falseStrings)booleancontainsColumn(java.lang.String headerName)Queries whether a given header name exists in theRecords parsed from the inputprivate static java.lang.Objectconvert(MetaData md, java.lang.String[] data, Conversion[] conversions)private <T> Tconvert(MetaData md, java.lang.String[] data, java.lang.Class<T> expectedType, Conversion[] conversions)private <T> Tconvert(MetaData md, java.lang.String[] data, java.lang.Class<T> type, T defaultValue, java.lang.annotation.Annotation annotation)private java.lang.Objectconvert(MetaData md, java.lang.String[] data, java.lang.Object defaultValue, Conversion[] conversions)FieldSet<java.lang.String>convertFields(Conversion... conversions)Associates a sequence ofConversions 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 ofConversions to fields of a given set of fieldsFieldSet<java.lang.Integer>convertIndexes(Conversion... conversions)Associates a sequence ofConversions to fields of a given set of column indexesjava.lang.ObjectdefaultValueOf(int columnIndex)Returns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object))java.lang.ObjectdefaultValueOf(java.lang.Enum<?> column)Returns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object))java.lang.ObjectdefaultValueOf(java.lang.String headerName)Returns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object))private FieldConversionMappinggetConversions()MetaDatagetMetaData(int index)private MetaDatagetMetaData(java.lang.Enum<?> column)private MetaDatagetMetaData(java.lang.String name)(package private) <T> TgetObjectValue(java.lang.String[] data, int columnIndex, java.lang.Class<T> type, T defaultValue)(package private) <T> TgetObjectValue(java.lang.String[] data, int columnIndex, java.lang.Class<T> type, T defaultValue, java.lang.String format, java.lang.String... formatOptions)(package private) <T> TgetObjectValue(java.lang.String[] data, java.lang.Enum<?> column, java.lang.Class<T> type, T defaultValue)(package private) <T> TgetObjectValue(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> TgetObjectValue(java.lang.String[] data, java.lang.String headerName, java.lang.Class<T> type, T defaultValue)(package private) <T> TgetObjectValue(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.StringgetValue(java.lang.String[] data, int columnIndex)(package private) <T> TgetValue(java.lang.String[] data, int columnIndex, java.lang.Class<T> expectedType, Conversion[] conversions)(package private) <T> TgetValue(java.lang.String[] data, int columnIndex, T defaultValue, Conversion[] conversions)(package private) java.lang.StringgetValue(java.lang.String[] data, java.lang.Enum<?> column)(package private) <T> TgetValue(java.lang.String[] data, java.lang.Enum<?> column, java.lang.Class<T> expectedType, Conversion[] conversions)(package private) <T> TgetValue(java.lang.String[] data, java.lang.Enum<?> column, T defaultValue, Conversion[] conversions)(package private) java.lang.StringgetValue(java.lang.String[] data, java.lang.String headerName)(package private) <T> TgetValue(java.lang.String[] data, java.lang.String headerName, java.lang.Class<T> expectedType, Conversion[] conversions)(package private) <T> TgetValue(java.lang.String[] data, java.lang.String headerName, T defaultValue, Conversion[] conversions)java.lang.String[]headers()Returns the column names of theRecords parsed from the input.intindexOf(java.lang.Enum<?> column)Returns the index of a given columnintindexOf(java.lang.String headerName)Returns the index of a given columnprivate voidinitializeMetadataConversions(java.lang.String[] data, MetaData md)(package private) MetaDatametadataOf(int columnIndex)(package private) MetaDatametadataOf(java.lang.Enum<?> column)(package private) MetaDatametadataOf(java.lang.String headerName)private static java.lang.annotation.AnnotationnewFormatAnnotation(java.lang.String format, java.lang.String... formatOptions)java.lang.String[]selectedHeaders()Returns the sequence of headers that have been selected.<T> voidsetDefaultValueOfColumns(T defaultValue, int... columnIndexes)Associates a default value with one or more columns, in case the values contained arenull<T> voidsetDefaultValueOfColumns(T defaultValue, java.lang.Enum<?>... columns)Associates a default value with one or more columns, in case the values contained arenull<T> voidsetDefaultValueOfColumns(T defaultValue, java.lang.String... headerNames)Associates a default value with one or more columns, in case the values contained arenullvoidsetTypeOfColumns(java.lang.Class<?> type, int... columnIndexes)Associates a type with one or more column.voidsetTypeOfColumns(java.lang.Class<?> type, java.lang.Enum... columns)Associates a type with one or more column.voidsetTypeOfColumns(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:RecordMetaDataReturns the index of a given column- Specified by:
indexOfin 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:RecordMetaDataReturns the index of a given column- Specified by:
indexOfin 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:RecordMetaDataReturns the type associated with a given column, defined with the methodsetTypeOfColumns(type, columns)- Specified by:
typeOfin 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:RecordMetaDataReturns the type associated with a given column name, defined with the methodsetTypeOfColumns(type, columns)- Specified by:
typeOfin 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:RecordMetaDataReturns the type associated with a given column, defined with the methodsetTypeOfColumns(type, columns)- Specified by:
typeOfin 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:RecordMetaDataAssociates a default value with one or more columns, in case the values contained arenull- Specified by:
setDefaultValueOfColumnsin interfaceRecordMetaData- Type Parameters:
T- type of the default value.- Parameters:
defaultValue- the value to be used for the given column when the parsed result isnullcolumns- the columns to be associated with a default value.
-
setDefaultValueOfColumns
public <T> void setDefaultValueOfColumns(T defaultValue, java.lang.String... headerNames)Description copied from interface:RecordMetaDataAssociates a default value with one or more columns, in case the values contained arenull- Specified by:
setDefaultValueOfColumnsin interfaceRecordMetaData- Type Parameters:
T- type of the default value.- Parameters:
defaultValue- the value to be used for the given column when the parsed result isnullheaderNames- the column names to be associated with a default value.
-
setDefaultValueOfColumns
public <T> void setDefaultValueOfColumns(T defaultValue, int... columnIndexes)Description copied from interface:RecordMetaDataAssociates a default value with one or more columns, in case the values contained arenull- Specified by:
setDefaultValueOfColumnsin interfaceRecordMetaData- Type Parameters:
T- type of the default value.- Parameters:
defaultValue- the value to be used for the given column when the parsed result isnullcolumnIndexes- the column indexes to be associated with a default value.
-
defaultValueOf
public java.lang.Object defaultValueOf(java.lang.Enum<?> column)
Description copied from interface:RecordMetaDataReturns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object))- Specified by:
defaultValueOfin 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:RecordMetaDataReturns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object))- Specified by:
defaultValueOfin 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:RecordMetaDataReturns the default value associated with a column (defined usingsetDefaultValueOf(Column, Object))- Specified by:
defaultValueOfin 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:RecordMetaDataAssociates a sequence ofConversions to fields of a given set of fields- Specified by:
convertFieldsin interfaceRecordMetaData- Type Parameters:
T- the enumeration type- Parameters:
enumType- the type of the enumeration whose values represent headers in the inputRecordsconversions- 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:RecordMetaDataAssociates a sequence ofConversions to fields of a given set of field names- Specified by:
convertFieldsin 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:RecordMetaDataAssociates a sequence ofConversions to fields of a given set of column indexes- Specified by:
convertIndexesin 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:RecordMetaDataReturns the column names of theRecords 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:
headersin interfaceRecordMetaData- Returns:
- the headers associated with the
Records parsed from the input
-
selectedHeaders
public java.lang.String[] selectedHeaders()
Description copied from interface:RecordMetaDataReturns 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:
selectedHeadersin 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:RecordMetaDataAssociates 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:
setTypeOfColumnsin 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:RecordMetaDataAssociates 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:
setTypeOfColumnsin 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:RecordMetaDataAssociates 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:
setTypeOfColumnsin 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:RecordMetaDataQueries whether a given header name exists in theRecords parsed from the input- Specified by:
containsColumnin interfaceRecordMetaData- Parameters:
headerName- name of the header- Returns:
trueif the given header name exists in the input records, otherwisefalse
-
-