Class Configurer<T>

  • Type Parameters:
    T - the type of the value being configured

    public class Configurer<T>
    extends java.lang.Object
    A fluent configuration utility for applying conditional operations on a value of type T.

    The Configurer class provides a builder-style API to configure and manipulate values, with support for comparison, predicate checks, type conversion, and application of consumer actions. It is designed to be non-thread-safe and intended for single-thread usage.

    Key Features

    • Value initialization with static factory methods.
    • Conditional comparison to detect changes in value.
    • Predicate-based filtering to control flow based on the current value.
    • Type conversion using functional interfaces.
    • Consumer application to perform side effects on the final value.
    • Detailed logging of each operation for traceability.

    Example Usage

    Basic Configuration Flow

    
     Configurer.configure("timeout", 30)
               .compare(25)
               .on(value -> value > 0)
               .as(value -> value * 1000)
               .apply(value -> System.setProperty("timeout.ms", String.valueOf(value)));
     

    Chaining Multiple Operations

    
     Configurer.configure(() -> System.getenv("DEBUG_MODE"))
               .on(mode -> "true".equalsIgnoreCase(mode))
               .as(Boolean::valueOf)
               .apply(enabled -> logger.info("Debug mode is enabled: {}", enabled));
     

    Discarding or Filtering Values

    
     Configurer.configure("username", () -> System.getProperty("user.name"))
               .on(name -> name.length() > 3)
               .apply(name -> System.out.println("Welcome, " + name));
     

    In the above example, if the username length is less than or equal to 3, the value will be discarded, and no action will be taken.

    Since:
    1.0.0
    Author:
    Mercy
    • Constructor Detail

      • Configurer

        protected Configurer​(java.lang.String name)
      • Configurer

        protected Configurer​(java.util.function.Supplier<T> valueSupplier)
      • Configurer

        protected Configurer​(T value)
      • Configurer

        protected Configurer​(java.lang.String name,
                             java.util.function.Supplier<T> valueSupplier)
      • Configurer

        protected Configurer​(java.lang.String name,
                             T value)
    • Method Detail

      • value

        public <T> Configurer<T> value​(T value)
      • value

        public <T> Configurer<T> value​(java.util.function.Supplier<T> valueSupplier)
      • compare

        public Configurer<T> compare​(java.util.function.Supplier<T> comparedValueSupplier)
      • compare

        public Configurer<T> compare​(T comparedValue)
      • on

        public Configurer<T> on​(java.util.function.Predicate<? super T> predicate)
      • as

        public <R> Configurer<R> as​(java.util.function.Function<T,​R> function)
      • apply

        public void apply​(java.util.function.Consumer<T> valueConsumer)
      • configure

        public static <T> Configurer<T> configure​(java.lang.String name)
      • configure

        public static <T> Configurer<T> configure​(java.lang.String name,
                                                  T value)
      • configure

        public static <T> Configurer<T> configure​(java.lang.String name,
                                                  java.util.function.Supplier<T> valueSupplier)
      • configure

        public static <T> Configurer<T> configure​(T value)
      • configure

        public static <T> Configurer<T> configure​(java.util.function.Supplier<T> valueSupplier)