Class CharValue

java.lang.Object
org.apache.juneau.commons.lang.Value<Character>
org.apache.juneau.commons.lang.CharValue

public class CharValue extends Value<Character>
A simple mutable character value.

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:

// Create a character value to track the last character seen CharValue lastChar = CharValue.create(); // Use in a lambda to track state charStream.forEach(ch -> { if (Character.isUpperCase(ch)) { lastChar.set(ch); } }); log("Last uppercase char: " + lastChar.get());

See Also:
  • Constructor Details

    • CharValue

      public CharValue(Character value)
      Constructor.
      Parameters:
      value - The initial value.
  • Method Details

    • create

      public static CharValue 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

      public static CharValue of(Character value)
      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

      public CharValue add(Character x)
      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

      public CharValue 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

      public CharValue 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

      public boolean is(Character value)
      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'));

      Overrides:
      is in class Value<Character>
      Parameters:
      value - The character to compare to.
      Returns:
      true if the current value is equal to the specified character.
    • isAny

      public boolean isAny(Character... values)
      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

      public boolean isAny(String values)
      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.