Class CharHolder
This class extends Holder<Character> and provides a convenient way to pass mutable
character references to lambdas, inner classes, or methods.
Notes:
- This class is not thread-safe.
Example:
See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds the specified value to the current value.Adds the specified value to the current value and returns the new value.static CharHoldercreate()Creates a new character value initialized to'\0' (null character).Decrements the value by 1.Decrements the value by 1 and returns the new value.Increments the value by 1.Increments the value by 1 and returns the new value.booleanChecks if the current value is equal to the specified character.booleanChecks if the current value matches any of the specified characters.booleanChecks if the current value matches any character in the specified string.static CharHolderCreates a new character value with the specified initial value.
-
Constructor Details
-
CharHolder
Constructor.- Parameters:
value- The initial value. Can benull .
-
-
Method Details
-
create
Creates a new character value initialized to'\0' (null character).Example:
CharHolder
value = CharHolder.create ();assertEquals ('\0',value .get());- Returns:
- A new character value.
-
of
Creates a new character value with the specified initial value.Example:
CharHolder
value = CharHolder.of ('A');assertEquals ('A',value .get());- Parameters:
value- The initial value. Can benull .- Returns:
- A new character value.
-
add
Adds the specified value to the current value.Example:
CharHolder
value = CharHolder.of ('A');value .add((char )5);assertEquals ('F',value .get());- Parameters:
x- The value to add. Can benull (treated as0 ).- Returns:
- This object.
-
addAndGet
Adds the specified value to the current value and returns the new value.Example:
CharHolder
value = CharHolder.of ('A');char result =value .addAndGet((char )5);// Returns 'F' assertEquals ('F',value .get());- Parameters:
x- The value to add. Can benull (treated as0 ).- Returns:
- The new value after addition.
-
decrement
Decrements the value by 1.Example:
CharHolder
value = CharHolder.of ('B');value .decrement();assertEquals ('A',value .get());- Returns:
- This object.
-
decrementAndGet
Decrements the value by 1 and returns the new value.Example:
CharHolder
value = CharHolder.of ('B');char result =value .decrementAndGet();// Returns 'A' assertEquals ('A',value .get());- Returns:
- The decremented value.
-
increment
Increments the value by 1.Example:
CharHolder
value = CharHolder.of ('A');value .increment();assertEquals ('B',value .get());- Returns:
- This object.
-
incrementAndGet
Increments the value by 1 and returns the new value.Example:
CharHolder
value = CharHolder.of ('A');char result =value .incrementAndGet();// Returns 'B' assertEquals ('B',value .get());- Returns:
- The incremented value.
-
is
Checks if the current value is equal to the specified character.Uses
Shorts.eq(Object, Object)for deep equality comparison, which handles nulls safely.Example:
CharHolder
value = CharHolder.of ('A');assertTrue (value .is('A'));assertFalse (value .is('B')); -
isAny
Checks if the current value matches any of the specified characters.Uses
Shorts.eq(Object, Object)for deep equality comparison of each character.Example:
CharHolder
value = CharHolder.of ('B');assertTrue (value .isAny('A', 'B', 'C'));assertFalse (value .isAny('X', 'Y'));- Parameters:
values- The characters to compare to. Must not benull .- Returns:
true if the current value matches any of the specified characters.
-
isAny
Checks if the current value matches any character in the specified string.Example:
CharHolder
value = CharHolder.of ('B');assertTrue (value .isAny("ABC" ));assertFalse (value .isAny("XYZ" ));// Null/empty string returns false assertFalse (value .isAny((null ));assertFalse (value .isAny("" ));- Parameters:
values- The string containing characters to compare to. Can benull or empty.- Returns:
true if the current value matches any character in the string.
-