Skip to content

io microsphere util Configurer

github-actions[bot] edited this page Mar 21, 2026 · 19 revisions

Configurer

Type: Class | Module: microsphere-java-core | Package: io.microsphere.util | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/util/Configurer.java

Overview

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.

Declaration

public class Configurer<T>

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Example 1

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

Example 2

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

Example 3

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

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.util.Configurer;

API Reference

Public Methods

Method Description
value
value
compare
compare
on
as
apply
configure
configure
configure
configure
configure

This documentation was auto-generated from the source code of microsphere-java.

Home

annotation-processor

annotation-test

java-annotations

java-core

java-test

jdk-tools

lang-model

Clone this wiki locally