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 Object implements RecordMetaData
  • Field Details

  • Constructor Details

    • RecordMetaDataImpl

      RecordMetaDataImpl(C context)
  • Method Details

    • getMetaData

      private MetaData getMetaData(String name)
    • getValidatedHeaders

      private NormalizedString[] getValidatedHeaders()
    • getMetaData

      private MetaData getMetaData(Enum<?> column)
    • getMetaData

      public MetaData getMetaData(int index)
    • indexOf

      public int indexOf(Enum<?> column)
      Description copied from interface: RecordMetaData
      Returns the index of a given column
      Specified by:
      indexOf in interface RecordMetaData
      Parameters:
      column - the column whose index will be returned
      Returns:
      index of the given column
    • metadataOf

      MetaData metadataOf(String headerName)
    • metadataOf

      MetaData metadataOf(Enum<?> column)
    • metadataOf

      MetaData metadataOf(int columnIndex)
    • indexOf

      public int indexOf(String headerName)
      Description copied from interface: RecordMetaData
      Returns the index of a given column
      Specified by:
      indexOf in interface RecordMetaData
      Parameters:
      headerName - name of the column whose index will be returned
      Returns:
      index of the given column
    • typeOf

      public Class<?> typeOf(Enum<?> column)
      Description copied from interface: RecordMetaData
      Returns the type associated with a given column, defined with the method setTypeOfColumns(type, columns)
      Specified by:
      typeOf in interface RecordMetaData
      Parameters:
      column - the column whose type will be returned
      Returns:
      the type of the given column
    • typeOf

      public Class<?> typeOf(String headerName)
      Description copied from interface: RecordMetaData
      Returns the type associated with a given column name, defined with the method setTypeOfColumns(type, columns)
      Specified by:
      typeOf in interface RecordMetaData
      Parameters:
      headerName - name of the column whose type will be returned
      Returns:
      the type of the given column
    • typeOf

      public Class<?> typeOf(int columnIndex)
      Description copied from interface: RecordMetaData
      Returns the type associated with a given column, defined with the method setTypeOfColumns(type, columns)
      Specified by:
      typeOf in interface RecordMetaData
      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, Enum<?>... columns)
      Description copied from interface: RecordMetaData
      Associates a default value with one or more columns, in case the values contained are null
      Specified by:
      setDefaultValueOfColumns in interface RecordMetaData
      Type Parameters:
      T - type of the default value.
      Parameters:
      defaultValue - the value to be used for the given column when the parsed result is null
      columns - the columns to be associated with a default value.
    • setDefaultValueOfColumns

      public <T> void setDefaultValueOfColumns(T defaultValue, String... headerNames)
      Description copied from interface: RecordMetaData
      Associates a default value with one or more columns, in case the values contained are null
      Specified by:
      setDefaultValueOfColumns in interface RecordMetaData
      Type Parameters:
      T - type of the default value.
      Parameters:
      defaultValue - the value to be used for the given column when the parsed result is null
      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 are null
      Specified by:
      setDefaultValueOfColumns in interface RecordMetaData
      Type Parameters:
      T - type of the default value.
      Parameters:
      defaultValue - the value to be used for the given column when the parsed result is null
      columnIndexes - the column indexes to be associated with a default value.
    • defaultValueOf

      public Object defaultValueOf(Enum<?> column)
      Description copied from interface: RecordMetaData
      Returns the default value associated with a column (defined using setDefaultValueOf(Column, Object))
      Specified by:
      defaultValueOf in interface RecordMetaData
      Parameters:
      column - the column whose default value will be returned
      Returns:
      the default value associated with the given column or null.
    • defaultValueOf

      public Object defaultValueOf(String headerName)
      Description copied from interface: RecordMetaData
      Returns the default value associated with a column (defined using setDefaultValueOf(Column, Object))
      Specified by:
      defaultValueOf in interface RecordMetaData
      Parameters:
      headerName - the column name whose default value will be returned
      Returns:
      the default value associated with the given column or null.
    • defaultValueOf

      public Object defaultValueOf(int columnIndex)
      Description copied from interface: RecordMetaData
      Returns the default value associated with a column (defined using setDefaultValueOf(Column, Object))
      Specified by:
      defaultValueOf in interface RecordMetaData
      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 Enum<T>> FieldSet<T> convertFields(Class<T> enumType, Conversion... conversions)
      Description copied from interface: RecordMetaData
      Associates a sequence of Conversions to fields of a given set of fields
      Specified by:
      convertFields in interface RecordMetaData
      Type Parameters:
      T - the enumeration type
      Parameters:
      enumType - the type of the enumeration whose values represent headers in the input Records
      conversions - 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<String> convertFields(Conversion... conversions)
      Description copied from interface: RecordMetaData
      Associates a sequence of Conversions to fields of a given set of field names
      Specified by:
      convertFields in interface RecordMetaData
      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<Integer> convertIndexes(Conversion... conversions)
      Description copied from interface: RecordMetaData
      Associates a sequence of Conversions to fields of a given set of column indexes
      Specified by:
      convertIndexes in interface RecordMetaData
      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 String[] headers()
      Description copied from interface: RecordMetaData
      Returns the column names of the Records 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 interface RecordMetaData
      Returns:
      the headers associated with the Records parsed from the input
    • selectedHeaders

      public 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 method RecordMetaData.headers().
      Specified by:
      selectedHeaders in interface RecordMetaData
      Returns:
      the sequence of selected headers, or all headers if no selection has been made.
    • getValue

      String getValue(String[] data, String headerName)
    • getValue

      String getValue(String[] data, int columnIndex)
    • getValue

      String getValue(String[] data, Enum<?> column)
    • convert

      private <T> T convert(MetaData md, String[] data, Class<T> expectedType, Conversion[] conversions)
    • convert

      private Object convert(MetaData md, String[] data, Object defaultValue, Conversion[] conversions)
    • convert

      private static Object convert(MetaData md, String[] data, Conversion[] conversions)
    • getValue

      <T> T getValue(String[] data, String headerName, T defaultValue, Conversion[] conversions)
    • getValue

      <T> T getValue(String[] data, int columnIndex, T defaultValue, Conversion[] conversions)
    • getValue

      <T> T getValue(String[] data, Enum<?> column, T defaultValue, Conversion[] conversions)
    • getValue

      <T> T getValue(String[] data, String headerName, Class<T> expectedType, Conversion[] conversions)
    • getValue

      <T> T getValue(String[] data, int columnIndex, Class<T> expectedType, Conversion[] conversions)
    • getValue

      <T> T getValue(String[] data, Enum<?> column, Class<T> expectedType, Conversion[] conversions)
    • convert

      private <T> T convert(MetaData md, String[] data, Class<T> type, T defaultValue, Annotation annotation)
    • initializeMetadataConversions

      private void initializeMetadataConversions(String[] data, MetaData md)
    • getObjectValue

      <T> T getObjectValue(String[] data, String headerName, Class<T> type, T defaultValue)
    • getObjectValue

      <T> T getObjectValue(String[] data, int columnIndex, Class<T> type, T defaultValue)
    • getObjectValue

      <T> T getObjectValue(String[] data, Enum<?> column, Class<T> type, T defaultValue)
    • getObjectValue

      <T> T getObjectValue(String[] data, String headerName, Class<T> type, T defaultValue, String format, String... formatOptions)
    • getObjectValue

      <T> T getObjectValue(String[] data, int columnIndex, Class<T> type, T defaultValue, String format, String... formatOptions)
    • getObjectValue

      <T> T getObjectValue(String[] data, Enum<?> column, Class<T> type, T defaultValue, String format, String... formatOptions)
    • buildBooleanStringAnnotation

      static Annotation buildBooleanStringAnnotation(String[] trueStrings, String[] falseStrings)
    • newFormatAnnotation

      private static Annotation newFormatAnnotation(String format, String... formatOptions)
    • buildAnnotation

      <T> Annotation buildAnnotation(Class<T> type, String args1, String... args2)
    • setTypeOfColumns

      public void setTypeOfColumns(Class<?> type, 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 a Record, 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 interface RecordMetaData
      Parameters:
      type - the type to associate with a list of column
      columns - the columns that will be associated with the given type.
    • setTypeOfColumns

      public void setTypeOfColumns(Class<?> type, 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 a Record, 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 interface RecordMetaData
      Parameters:
      type - the type to associate with a list of column
      headerNames - the columns that will be associated with the given type.
    • setTypeOfColumns

      public void setTypeOfColumns(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 a Record, 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 interface RecordMetaData
      Parameters:
      type - the type to associate with a list of column
      columnIndexes - the columns that will be associated with the given type.
    • containsColumn

      public boolean containsColumn(String headerName)
      Description copied from interface: RecordMetaData
      Queries whether a given header name exists in the Records parsed from the input
      Specified by:
      containsColumn in interface RecordMetaData
      Parameters:
      headerName - name of the header
      Returns:
      true if the given header name exists in the input records, otherwise false