Class StringValue

java.lang.Object
org.apache.juneau.commons.lang.Value<String>
org.apache.juneau.commons.lang.StringValue

public class StringValue extends Value<String>
A simple mutable string value.

This class extends Value<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:

// Create a mutable string StringValue name = StringValue.of("John"); // Check equality if (name.is("John")) { System.out.println("Name is John"); } // Check multiple values if (name.isAny("John", "Jane", "Bob")) { System.out.println("Name found"); }

See Also:
  • Constructor Details

    • StringValue

      public StringValue()
      Constructor.
    • StringValue

      public StringValue(String value)
      Constructor.
      Parameters:
      value - The initial value.
  • Method Details

    • create

      public static StringValue create()
      Creates a new empty string value.
      Example:

      StringValue name = StringValue.create(); assertNull(name.get());

      Returns:
      A new string value.
    • of

      public static StringValue of(String value)
      Creates a new string value with the specified initial value.
      Example:

      StringValue name = StringValue.of("Hello"); assertEquals("Hello", name.get());

      Parameters:
      value - The initial value.
      Returns:
      A new string value.
    • is

      public boolean is(String value)
      Checks if the current value is equal to the specified value.

      Uses Utils.eq(Object, Object) for deep equality comparison, which handles nulls safely.

      Example:

      StringValue name = StringValue.of("John"); assertTrue(name.is("John")); assertFalse(name.is("Jane")); // Handles null safely StringValue empty = StringValue.create(); assertTrue(empty.is(null));

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

      public boolean isAny(String... values)
      Checks if the current value matches any of the specified values.

      Uses Utils.eq(Object, Object) for deep equality comparison of each value.

      Example:

      StringValue name = StringValue.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.
      Returns:
      true if the current value matches any of the specified values.