Interface StringConverter<T>

Type Parameters:
T - The type
All Superinterfaces:
TypeConverter<T>

public interface StringConverter<T> extends TypeConverter<T>
A TypeConverter which can convert data directly to and from strings
  • Method Details

    • create

      static <T> StringConverter<T> create(Function<String,T> loader, Function<T,String> saver)
      Creates a StringConverter using a loading function and a saving function
      Type Parameters:
      T - The type
      Parameters:
      loader - A loading function which can convert from a string to the type
      saver - A saving function which can convert from the type to a string
      Returns:
      The created StringConverter
    • fromString

      T fromString(String str)
      Converts from a string
      Parameters:
      str - The string
      Returns:
      The resulting object
    • toString

      String toString(T t)
      Converts to a string
      Parameters:
      t - The object to convert
      Returns:
      The string representation
    • loadFrom

      default T loadFrom(DataHolder section, String path, T currentValue)
      Description copied from interface: TypeConverter
      Attemps to load the object from config
      Specified by:
      loadFrom in interface TypeConverter<T>
      Parameters:
      section - The ConfigurationSection to load from
      path - The path to the data in the ConfigurationSection
      currentValue - The current value, used for collections and maps
      Returns:
    • saveTo

      default void saveTo(T t, DataHolder section, String path)
      Description copied from interface: TypeConverter
      Attemps to save the object to config
      Specified by:
      saveTo in interface TypeConverter<T>
      Parameters:
      t - The object to save
      section - The ConfigurationSection to save to
      path - The path to the data that should be saved in the ConfigurationSection