Class FormatConverter<T>

java.lang.Object
org.fastnate.data.properties.FormatConverter<T>
Type Parameters:
T - the type of the returned value
All Implemented Interfaces:
PropertyConverter<T>
Direct Known Subclasses:
DateConverter

public class FormatConverter<T> extends Object implements PropertyConverter<T>
Converts a string from an import file to a Java object using a list of Formats. If the value is a number, the appropriate type conversion is applied.
Author:
Tobias Liefke
  • Constructor Details

    • FormatConverter

      public FormatConverter(Format... formats)
      Creates a new instance of a FormatConverter.
      Parameters:
      formats - the list of formats to try for conversion, the first that throws no ParseException is used
  • Method Details

    • convert

      public T convert(Class<? extends T> targetType, String value)
      Description copied from interface: PropertyConverter
      Converts a value from import file to Java.
      Specified by:
      convert in interface PropertyConverter<T>
      Parameters:
      targetType - the type of the target property
      value - the value in the import file
      Returns:
      the value in Java
    • getFormats

      public List<Format> getFormats()
      All formats to test. The first that throws no ParseException is used for conversion.