Package org.moddingx.libx.config.correct
Interface ConfigCorrection<T>
public interface ConfigCorrection<T>
An instance of this interface is passed when a config is corrected. It can be used to best
restore matching parts of the config.
-
Method Summary
Modifier and TypeMethodDescriptiondefault <U> Optional<U> correct(JsonElement json, ValueMapper<U, ?> mapper, Function<T, U> extractor) Tries to get a value from a piece of json given a matching value mapper and a function to extract a default value for the value that this method should retrieve when given a default value for this config value.<U> Optional<U> tryCorrect(JsonElement json, ValueMapper<U, ?> mapper, Function<T, Optional<U>> extractor) Same ascorrect(JsonElement, ValueMapper, Function)but with an extractor that returns anOptional.<U> Optional<U> tryGet(JsonElement json, ValueMapper<U, ?> mapper) Tries to get a value from a piece of json given a matching value mapper.
-
Method Details
-
tryGet
Tries to get a value from a piece of json given a matching value mapper. This should be used if there's no way to get a default value in any way.- Returns:
- The corrected value for the given json or an empty option if it could not be corrected.
-
correct
default <U> Optional<U> correct(@Nullable JsonElement json, ValueMapper<U, ?> mapper, Function<T, U> extractor) Tries to get a value from a piece of json given a matching value mapper and a function to extract a default value for the value that this method should retrieve when given a default value for this config value. For example when aPairis corrected and it find an array with two elements, it would do something likecorrect(jsonArray.get(0), firstMapper, Pair::getLeft);to correct the first value from the pair. Set json to null if you can't get a matching piece of json in any case.- Returns:
- The corrected value for the given json or an empty option if it could not be corrected.
-
tryCorrect
<U> Optional<U> tryCorrect(@Nullable JsonElement json, ValueMapper<U, ?> mapper, Function<T, Optional<U>> extractor) Same ascorrect(JsonElement, ValueMapper, Function)but with an extractor that returns anOptional. It should return an empty optional to mark that there's no default value available or a filled optional with an appropriate default value. -
check
-