Class ConversionTable
- java.lang.Object
-
- com.electronwill.nightconfig.core.conversion.ConversionTable
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class ConversionTable extends java.lang.Object implements java.lang.CloneableContains conversions functions organized by value's type. A ConversionTable grows as necessary.
-
-
Constructor Summary
Constructors Constructor Description ConversionTable()Creates a new empty ConversionTable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConversionTablechainThen(ConversionTable after)Returns a ConversionTable that behaves as if the specified table was applied just after this table, for every conversion.ConversionTableclone()booleancontains(java.lang.Class<?> classToConvert)Checks that a function is defined for the specified class.java.lang.Objectconvert(java.lang.Object value)Converts a value using the conversion function that corresponds to its type.voidconvertDeep(Config config)Performs a deep in-place conversion of a Config.voidconvertShallow(Config config)Performs a shallow in-place conversion of a Config.<T> voidput(java.lang.Class<T> classToConvert, java.util.function.Function<? super T,java.lang.Object> conversionFunction)Puts a conversion function to the table.voidremove(java.lang.Class<?> classToConvert)Removes the function that is currently defined for the specified class, if any.java.lang.StringtoString()UnmodifiableConfigwrap(UnmodifiableConfig config)Returns an UnmodifiableConfig that converts "just-in-time" the values of the specified UnmodifiableConfig.CommentedConfigwrapRead(CommentedConfig config)Returns an Config that converts "just-in-time" the values that are read from the specified Config.ConfigwrapRead(Config config)Returns an Config that converts "just-in-time" the values that are read from the specified Config.CommentedFileConfigwrapRead(CommentedFileConfig config)Returns an Config that converts "just-in-time" the values that are read from the specified Config.FileConfigwrapRead(FileConfig config)Returns an Config that converts "just-in-time" the values that are read from the specified Config.CommentedConfigwrapWrite(CommentedConfig config, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)Returns an Config that converts "just-in-time" the values that are put into the specified Config.ConfigwrapWrite(Config config, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)Returns an Config that converts "just-in-time" the values that are put into the specified Config.CommentedFileConfigwrapWrite(CommentedFileConfig config, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)Returns an Config that converts "just-in-time" the values that are put into the specified Config.FileConfigwrapWrite(FileConfig config, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)Returns an Config that converts "just-in-time" the values that are put into the specified Config.
-
-
-
Method Detail
-
put
public <T> void put(java.lang.Class<T> classToConvert, java.util.function.Function<? super T,java.lang.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 nullconversionFunction- the conversion function
-
remove
public void remove(java.lang.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(java.lang.Class<?> classToConvert)
Checks that a function is defined for the specified class.- Parameters:
classToConvert- the class of the values that the function converts- Returns:
trueif the table contains a function for the class,falseotherwise
-
convert
public java.lang.Object convert(java.lang.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, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
Returns an Config that converts "just-in-time" the values that are put into the specified Config.- Parameters:
config- the config to wrapsupportValueTypePredicate- 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, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
Returns an Config that converts "just-in-time" the values that are put into the specified Config.- Parameters:
config- the config to wrapsupportValueTypePredicate- 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, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
Returns an Config that converts "just-in-time" the values that are put into the specified Config.- Parameters:
config- the config to wrapsupportValueTypePredicate- 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, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
Returns an Config that converts "just-in-time" the values that are put into the specified Config.- Parameters:
config- the config to wrapsupportValueTypePredicate- 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:
clonein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-