Class StringHolder
This class extends Holder<String> and adds convenience methods for string
equality testing, which are useful in lambdas and conditional logic.
Notes:
- This class is not thread-safe. For concurrent access, use synchronization or atomic classes.
Example:
See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringHoldercreate()Creates a new empty string value.booleanChecks if the current value is equal to the specified value.booleanChecks if the current value matches any of the specified values.static StringHolderCreates a new string value with the specified initial value.
-
Constructor Details
-
StringHolder
public StringHolder()Constructor. -
StringHolder
Constructor.- Parameters:
value- The initial value. Can benull .
-
-
Method Details
-
create
Creates a new empty string value.Example:
StringHolder
name = StringHolder.create ();assertNull (name .get());- Returns:
- A new string value.
-
of
Creates a new string value with the specified initial value.Example:
StringHolder
name = StringHolder.of ("Hello" );assertEquals ("Hello" ,name .get());- Parameters:
value- The initial value. Can benull .- Returns:
- A new string value.
-
is
Checks if the current value is equal to the specified value.Uses
Shorts.eq(Object, Object)for deep equality comparison, which handles nulls safely.Example:
StringHolder
name = StringHolder.of ("John" );assertTrue (name .is("John" ));assertFalse (name .is("Jane" ));// Handles null safely StringHolderempty = StringHolder.create ();assertTrue (empty .is(null )); -
isAny
Checks if the current value matches any of the specified values.Uses
Shorts.eq(Object, Object)for deep equality comparison of each value.Example:
StringHolder
name = StringHolder.of ("John" );assertTrue (name .isAny("John" ,"Jane" ,"Bob" ));assertFalse (name .isAny("Alice" ,"Charlie" ));// Empty array returns false assertFalse (name .isAny());- Parameters:
values- The values to compare to. Must not benull .- Returns:
true if the current value matches any of the specified values.
-