Class ConversionTable
java.lang.Object
com.electronwill.nightconfig.core.conversion.ConversionTable
- All Implemented Interfaces:
Cloneable
Contains conversions functions organized by value's type. A ConversionTable grows as necessary.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchainThen(ConversionTable after) Returns a ConversionTable that behaves as if the specified table was applied just after this table, for every conversion.clone()booleanChecks that a function is defined for the specified class.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> voidPuts a conversion function to the table.voidRemoves the function that is currently defined for the specified class, if any.toString()wrap(UnmodifiableConfig config) Returns an UnmodifiableConfig that converts "just-in-time" the values of the specified UnmodifiableConfig.wrapRead(CommentedConfig config) Returns an Config that converts "just-in-time" the values that are read from the specified Config.Returns an Config that converts "just-in-time" the values that are read from the specified Config.wrapRead(CommentedFileConfig config) Returns an Config that converts "just-in-time" the values that are read from the specified Config.wrapRead(FileConfig config) Returns an Config that converts "just-in-time" the values that are read from the specified Config.wrapWrite(CommentedConfig config, Predicate<Class<?>> supportValueTypePredicate) Returns an Config that converts "just-in-time" the values that are put into the specified Config.Returns an Config that converts "just-in-time" the values that are put into the specified Config.wrapWrite(CommentedFileConfig config, Predicate<Class<?>> supportValueTypePredicate) Returns an Config that converts "just-in-time" the values that are put into the specified Config.wrapWrite(FileConfig config, Predicate<Class<?>> supportValueTypePredicate) Returns an Config that converts "just-in-time" the values that are put into the specified Config.
-
Constructor Details
-
ConversionTable
public ConversionTable()Creates a new empty ConversionTable.
-
-
Method Details
-
put
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
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
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
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
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
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
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
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
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
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
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
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
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, 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 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
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, 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 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
-
toString
-