Class CharValue
This class extends Value<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 CharValuecreate()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 CharValueCreates a new character value with the specified initial value.
-
Constructor Details
-
CharValue
Constructor.- Parameters:
value- The initial value.
-
-
Method Details
-
create
Creates a new character value initialized to'\0' (null character).Example:
CharValue
value = CharValue.create ();assertEquals ('\0',value .get());- Returns:
- A new character value.
-
of
Creates a new character value with the specified initial value.Example:
CharValue
value = CharValue.of ('A');assertEquals ('A',value .get());- Parameters:
value- The initial value.- Returns:
- A new character value.
-
add
Adds the specified value to the current value.Example:
CharValue
value = CharValue.of ('A');value .add((char )5);assertEquals ('F',value .get());- Parameters:
x- The value to add.- Returns:
- This object.
-
addAndGet
Adds the specified value to the current value and returns the new value.Example:
CharValue
value = CharValue.of ('A');char result =value .addAndGet((char )5);// Returns 'F' assertEquals ('F',value .get());- Parameters:
x- The value to add.- Returns:
- The new value after addition.
-
decrement
Decrements the value by 1.Example:
CharValue
value = CharValue.of ('B');value .decrement();assertEquals ('A',value .get());- Returns:
- This object.
-
decrementAndGet
Decrements the value by 1 and returns the new value.Example:
CharValue
value = CharValue.of ('B');char result =value .decrementAndGet();// Returns 'A' assertEquals ('A',value .get());- Returns:
- The decremented value.
-
increment
Increments the value by 1.Example:
CharValue
value = CharValue.of ('A');value .increment();assertEquals ('B',value .get());- Returns:
- This object.
-
incrementAndGet
Increments the value by 1 and returns the new value.Example:
CharValue
value = CharValue.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
Utils.eq(Object, Object)for deep equality comparison, which handles nulls safely.Example:
CharValue
value = CharValue.of ('A');assertTrue (value .is('A'));assertFalse (value .is('B')); -
isAny
Checks if the current value matches any of the specified characters.Uses
Utils.eq(Object, Object)for deep equality comparison of each character.Example:
CharValue
value = CharValue.of ('B');assertTrue (value .isAny('A', 'B', 'C'));assertFalse (value .isAny('X', 'Y'));- Parameters:
values- The characters to compare to.- 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:
CharValue
value = CharValue.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.- Returns:
true if the current value matches any character in the string.
-