Skip to content

Commit c25ad52

Browse files
committed
Update Compatible.java
1 parent cb021dc commit c25ad52

1 file changed

Lines changed: 49 additions & 3 deletions

File tree

microsphere-java-core/src/main/java/io/microsphere/util/Compatible.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,56 @@
2626
import static java.util.Optional.ofNullable;
2727

2828
/**
29-
* Compatible
29+
* A utility class to conditionally execute logic based on version comparison.
3030
*
31-
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
32-
* @since 1.0.0
31+
* <p>{@link Compatible} allows defining conditional logic that is executed only if the current version meets a specified
32+
* condition relative to another version. It supports common version comparison operations such as equal to, greater than,
33+
* less than, and their inclusive counterparts.</p>
34+
*
35+
* <h3>Example Usage</h3>
36+
*
37+
* <h4>Example 1: Basic Usage</h4>
38+
* <pre>{@code
39+
* Version currentVersion = Version.of("1.2.3");
40+
* Compatible<Void, String> compatible = new Compatible<>(currentVersion, v -> "Matched Condition");
41+
*
42+
* // Execute logic only if current version is greater than "1.2.0"
43+
* Optional<String> result = compatible.on(">", "1.2.0", v -> "Executed").call();
44+
* System.out.println(result.orElse("Not Matched")); // Output: Executed
45+
* }</pre>
46+
*
47+
* <h4>Example 2: Chaining Conditions</h4>
48+
* <pre>{@code
49+
* Version currentVersion = Version.of("2.0.0");
50+
* Compatible<Void, String> base = new Compatible<>(currentVersion, null);
51+
*
52+
* // Apply multiple conditions in sequence
53+
* Optional<String> result = base
54+
* .on("<", "1.9.0", v -> "Older")
55+
* .on("==", "2.0.0", v -> "Exact Match")
56+
* .on(">=", "2.0.0", v -> "At least 2.0.0")
57+
* .call();
58+
*
59+
* System.out.println(result.orElse("No condition matched")); // Output: Exact Match
60+
* }</pre>
61+
*
62+
* <h4>Example 3: Using with Class-based Version</h4>
63+
* <pre>{@code
64+
* // Automatically fetches version from the manifest of the JAR containing MyComponent.class
65+
* Compatible<MyComponent, Boolean> compatibilityCheck = Compatible.of(MyComponent.class);
66+
*
67+
* boolean isSupported = compatibilityCheck
68+
* .on(">=", "1.5.0", v -> true)
69+
* .on("<", "1.5.0", v -> false)
70+
* .get() != null;
71+
*
72+
* System.out.println("Feature supported: " + isSupported);
73+
* }</pre>
74+
*
75+
* @param <T> the type of context object associated with this compatibility check (not used directly in logic)
76+
* @param <R> the return type of the conditional function
77+
* @see Version
78+
* @see Version.Operator
3379
*/
3480
public class Compatible<T, R> {
3581

0 commit comments

Comments
 (0)