-
Notifications
You must be signed in to change notification settings - Fork 0
Optional
Aide Optional contains:
- Optional classes for different types
- Conditionals
- Utils
Aide provides extended optionals for some types. All optionals implement GenericOptional
and can be converted to standard Optional
with generic()
.
BooleanOptional
stores boolean value. Null values are not supported and NullPointerException
will be thrown.
BooleanOptional.of(Modifier.isPublic(executable.getModifiers()))
.ifFalseThrow(() -> ReflectionException.format("Wrapping is supported for PUBLIC methods only!"));
BooleanOptional
stores string value. Null values are not supported and NullPointerException
will be thrown.
StringOptional stringOptional = StringOptional.of("String");
String actual = stringOptional.mapOnCondition(s -> true, v -> "My" + v).get();
assert "MyString".equals(actual);
ThrowableOptional
allows you to handle checked exceptions in lambda expressions.
public void exceptional() throws Throwable {
}
// No try-catch needed
ThrowableOptional.sneaky(() -> exceptional());
Conditionals are conditional statements as standard if-else for example, but in functional style.
IfTrueConditional
works like standard if-else: it evaluates predicates and return value from first success branch.
AbstractSignature signature = IfTrueConditional.create()
.ifTrue(exact).then(() -> ExactMethodSignature.from(method))
.orElseGet(() -> MethodSignature.from(method));
WhenConditional
works like IfTrueConditional
except it doesn't return any value and just evaluates action on first success branch.
WhenConditional.create()
.when(someObj, Objects::nonNull).then(MyClass::nonNull)
.when(someObj, Objects::isNull).then(MyClass::isNull)
.orDoNothing();
ObjectUtils
contains some useful methods for Object