Class OptionalString

java.lang.Object
xyz.ronella.trivial.decorator.OptionalString

public class OptionalString extends Object
A class that wraps an Optional instance of type String.
Since:
2.12.0
  • Constructor Details

    • OptionalString

      public OptionalString(Optional<String> optional)
      Creates an instance of OptionalString.
      Parameters:
      optional - An instance Optional of type String.
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Identifies if optional string is empty.
      Returns:
      Returns true when the string is empty.
    • isBlank

      public boolean isBlank()
      Identifies if the optional string is blank.
      Returns:
      Returns true when the string is blank.
    • ifPresentNotBlank

      public void ifPresentNotBlank(Consumer<String> action)
      If the string value is present and not blank, performs the given action with the value, otherwise does nothing.
      Parameters:
      action - The action to be performed, if a value is present
      Throws:
      NullPointerException - If value is present and the given action is null
    • ifPresentNotEmpty

      public void ifPresentNotEmpty(Consumer<String> action)
      If the string value is present and not empty, performs the given action with the value, otherwise does nothing.
      Parameters:
      action - The action to be performed, if a value is present
      Throws:
      NullPointerException - If value is present and the given action is null
    • ifPresentNotBlankOrElse

      public void ifPresentNotBlankOrElse(Consumer<String> action, Runnable emptyAction)
      If the string value is present and not blank, performs the given action with the value, otherwise performs the given empty-based action.
      Parameters:
      action - The action to be performed, if a value is present
      emptyAction - The empty-based action to be performed, if no value is present
      Throws:
      NullPointerException - If a value is present and the given action is null, or no value is present and the given empty-based action is null.
    • ifPresentNotEmptyOrElse

      public void ifPresentNotEmptyOrElse(Consumer<String> action, Runnable emptyAction)
      If the string value is present and not empty, performs the given action with the value, otherwise performs the given empty-based action.
      Parameters:
      action - The action to be performed, if a value is present
      emptyAction - The empty-based action to be performed, if no value is present
      Throws:
      NullPointerException - If a value is present and the given action is null, or no value is present and the given empty-based action is null.