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 Details

    • tryGet

      <U> Optional<U> tryGet(JsonElement json, ValueMapper<U,?> mapper)
      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 a Pair is corrected and it find an array with two elements, it would do something like correct(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 as correct(JsonElement, ValueMapper, Function) but with an extractor that returns an Optional. 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

      static <X, R> Function<X,Optional<R>> check(Predicate<X> present, Function<X,R> result)
      Gets a Function that first passes the argument to the given Predicate to check whether a value is available. If a value is available, uses the given Function to compute the result. If the predicate returns false, the returned Optional will be empty.