Class ConversionTable

java.lang.Object
com.electronwill.nightconfig.core.conversion.ConversionTable
All Implemented Interfaces:
Cloneable

public final class ConversionTable extends Object implements Cloneable
Contains conversions functions organized by value's type. A ConversionTable grows as necessary.
  • Constructor Details

    • ConversionTable

      public ConversionTable()
      Creates a new empty ConversionTable.
  • Method Details

    • put

      public <T> void put(Class<T> classToConvert, Function<? super T,Object> conversionFunction)
      Puts a conversion function to the table. If a function is already defined for the specified class then it is replaced.
      Type Parameters:
      T - the type of the values that the function can convert
      Parameters:
      classToConvert - the class of the values that the function can convert, may be null
      conversionFunction - the conversion function
    • remove

      public void remove(Class<?> classToConvert)
      Removes the function that is currently defined for the specified class, if any.
      Parameters:
      classToConvert - the class of the values that the function we want to remove converts
    • contains

      public boolean contains(Class<?> classToConvert)
      Checks that a function is defined for the specified class.
      Parameters:
      classToConvert - the class of the values that the function converts
      Returns:
      true if the table contains a function for the class, false otherwise
    • convert

      public Object convert(Object value)
      Converts a value using the conversion function that corresponds to its type.
      Parameters:
      value - the value to convert, may be null
      Returns:
      the result of the conversion
    • convertShallow

      public void convertShallow(Config config)
      Performs a shallow in-place conversion of a Config. Each first-level value of the config is converted using the conversion function that corresponds to its type.
      Parameters:
      config - the config to convert
    • convertDeep

      public void convertDeep(Config config)
      Performs a deep in-place conversion of a Config. Each simple (ie non-Config) value of the config is converted using the conversion function that corresponds to its type.
      Parameters:
      config - the config to convert
    • chainThen

      public ConversionTable chainThen(ConversionTable after)
      Returns a ConversionTable that behaves as if the specified table was applied just after this table, for every conversion.
      Parameters:
      after - the table to apply after this one
      Returns:
      a ConversionTable that applies this table and then the specified table
    • wrap

      public UnmodifiableConfig wrap(UnmodifiableConfig config)
      Returns an UnmodifiableConfig that converts "just-in-time" the values of the specified UnmodifiableConfig.
      Parameters:
      config - the config to wrap
      Returns:
      a wrapper that converts the config's values using this conversion table.
    • wrapRead

      public Config wrapRead(Config config)
      Returns an Config that converts "just-in-time" the values that are read from the specified Config.
      Parameters:
      config - the config to wrap
      Returns:
      a wrapper that converts the values read from the config
    • wrapRead

      public CommentedConfig wrapRead(CommentedConfig config)
      Returns an Config that converts "just-in-time" the values that are read from the specified Config.
      Parameters:
      config - the config to wrap
      Returns:
      a wrapper that converts the values read from the config
    • wrapRead

      public FileConfig wrapRead(FileConfig config)
      Returns an Config that converts "just-in-time" the values that are read from the specified Config.
      Parameters:
      config - the config to wrap
      Returns:
      a wrapper that converts the values read from the config
    • wrapRead

      public CommentedFileConfig wrapRead(CommentedFileConfig config)
      Returns an Config that converts "just-in-time" the values that are read from the specified Config.
      Parameters:
      config - the config to wrap
      Returns:
      a wrapper that converts the values read from the config
    • wrapWrite

      public Config wrapWrite(Config config, Predicate<Class<?>> supportValueTypePredicate)
      Returns an Config that converts "just-in-time" the values that are put into the specified Config.
      Parameters:
      config - the config to wrap
      supportValueTypePredicate - Predicate that checks if a given class is supported by the returned config
      Returns:
      a wrapper that converts the values put into the config
    • wrapWrite

      public CommentedConfig wrapWrite(CommentedConfig config, Predicate<Class<?>> supportValueTypePredicate)
      Returns an Config that converts "just-in-time" the values that are put into the specified Config.
      Parameters:
      config - the config to wrap
      supportValueTypePredicate - Predicate that checks if a given class is supported by the returned config
      Returns:
      a wrapper that converts the values put into the config
    • wrapWrite

      public FileConfig wrapWrite(FileConfig config, Predicate<Class<?>> supportValueTypePredicate)
      Returns an Config that converts "just-in-time" the values that are put into the specified Config.
      Parameters:
      config - the config to wrap
      supportValueTypePredicate - Predicate that checks if a given class is supported by the returned config
      Returns:
      a wrapper that converts the values put into the config
    • wrapWrite

      public CommentedFileConfig wrapWrite(CommentedFileConfig config, Predicate<Class<?>> supportValueTypePredicate)
      Returns an Config that converts "just-in-time" the values that are put into the specified Config.
      Parameters:
      config - the config to wrap
      supportValueTypePredicate - Predicate that checks if a given class is supported by the returned config
      Returns:
      a wrapper that converts the values put into the config
    • clone

      public ConversionTable clone()
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object