java.lang.Object
xyz.ronella.trivial.decorator.OptionalString
A class that wraps an Optional instance of type String.
- Since:
- 2.12.0
-
Constructor Summary
ConstructorsConstructorDescriptionOptionalString(Optional<String> optional) Creates an instance of OptionalString. -
Method Summary
Modifier and TypeMethodDescriptionvoidifPresentNotBlank(Consumer<String> action) If the string value is present and not blank, performs the given action with the value, otherwise does nothing.voidifPresentNotBlankOrElse(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.voidifPresentNotEmpty(Consumer<String> action) If the string value is present and not empty, performs the given action with the value, otherwise does nothing.voidifPresentNotEmptyOrElse(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.booleanisBlank()Identifies if the optional string is blank.booleanisEmpty()Identifies if optional string is empty.
-
Constructor Details
-
OptionalString
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
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
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
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 presentemptyAction- 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
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 presentemptyAction- 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.
-