Class ConversionManager

java.lang.Object
redempt.redlib.config.ConversionManager

public class ConversionManager extends Object
  • Constructor Details

    • ConversionManager

      public ConversionManager(org.bukkit.plugin.Plugin plugin)
  • Method Details

    • loadClass

      public Class<?> loadClass(String name)
      Loads a class by name, using a cache
      Parameters:
      name - The name of the class to load
      Returns:
      The class
    • getConverter

      public <T> TypeConverter<T> getConverter(ConfigType<T> type)
      Gets the TypeConverter for a given type
      Type Parameters:
      T - The parameter type
      Parameters:
      type - The ConfigType
      Returns:
      The TypeConverter, making a new one if none exists for the given type
    • addConverter

      public <T> ConversionManager addConverter(Class<T> clazz, Function<String,T> loader, Function<T,String> saver)
      Registers a string converter to this ConversionManager
      Type Parameters:
      T - The type
      Parameters:
      clazz - The class type the converter is for
      loader - A function to convert a string to the given type
      saver - A function to convert the given type to a string
      Returns:
      This ConversionManager
    • addConverter

      public <T> ConversionManager addConverter(ConfigType<T> type, TypeConverter<T> converter)
      Registers a converter to this ConversionManager
      Type Parameters:
      T - The type
      Parameters:
      type - The type the converter is for
      converter - The converter
      Returns:
      This ConversionManager
    • getStringConverter

      public <T> StringConverter<T> getStringConverter(ConfigType<T> type)
      Gets a StringConverter for a given type
      Type Parameters:
      T - The type
      Parameters:
      type - The type to get a StringConverter for
      Returns:
      The StringConverter associated with the given type
      Throws:
      IllegalStateException - If a StringConverter does not exist for the given type