Class StringConverter<T>

java.lang.Object
me.hsgamer.hscore.config.annotation.converter.impl.StringConverter<T>
Type Parameters:
T - the type of the object
All Implemented Interfaces:
Converter

public abstract class StringConverter<T> extends Object implements Converter
A simple Converter for String to any object
  • Constructor Details

    • StringConverter

      public StringConverter()
  • Method Details

    • of

      public static <T> StringConverter<T> of(Function<String,T> from, Function<T,String> to)
      Create a new instance of the converter
      Type Parameters:
      T - the type of the object
      Parameters:
      from - the function to convert the string to the object
      to - the function to convert the object to the string
      Returns:
      the new instance of the converter
    • convertFrom

      protected abstract T convertFrom(String string)
      Convert the string to the object
      Parameters:
      string - the string
      Returns:
      the object
    • convertTo

      protected abstract String convertTo(T t)
      Convert the object to the string
      Parameters:
      t - the object
      Returns:
      the string
    • convert

      public Object convert(Object raw)
      Description copied from interface: Converter
      Convert the raw value from the config file to the final value for the field
      Specified by:
      convert in interface Converter
      Parameters:
      raw - the raw value
      Returns:
      the final value
    • convertToRaw

      public Object convertToRaw(Object value)
      Description copied from interface: Converter
      Convert the final value from the field to the raw value for the config file
      Specified by:
      convertToRaw in interface Converter
      Parameters:
      value - the final value
      Returns:
      the raw value