java.lang.Object
de.cuioss.tools.base.BooleanOperations
Utility Class providing some boolean operations. In essence, it simplifies
'or' and 'and' operations. Some examples from the unit-tests:
@Test
void shouldDetectAnyTrue() {
assertTrue(BooleanOperations.isAnyTrue(true));
assertTrue(BooleanOperations.isAnyTrue(true, true));
assertTrue(BooleanOperations.isAnyTrue(true, false));
assertFalse(BooleanOperations.isAnyTrue(false, false));
// Not really sensible, but defined contract -> Corner Case
assertFalse(BooleanOperations.isAnyTrue());
assertFalse(BooleanOperations.isAnyTrue(null));
}
@Test
void shouldDetectAnyFalse() {
assertFalse(BooleanOperations.isAnyFalse(true));
assertTrue(BooleanOperations.isAnyFalse(true, false));
assertTrue(BooleanOperations.isAnyFalse(false, false));
// Not really sensible, but defined contract -> Corner Case
assertFalse(BooleanOperations.isAnyFalse());
assertFalse(BooleanOperations.isAnyFalse(null));
}
@Test
void shouldDetectAllFalse() {
assertFalse(BooleanOperations.areAllFalse(true));
assertFalse(BooleanOperations.areAllFalse(true, false));
assertFalse(BooleanOperations.areAllFalse(true, true));
assertTrue(BooleanOperations.areAllFalse(false, false));
// Not really sensible, but defined contract -> Corner Case
assertFalse(BooleanOperations.areAllFalse());
assertFalse(BooleanOperations.areAllFalse(null));
}
@Test
void shouldDetectAllTrue() {
assertTrue(BooleanOperations.areAllTrue(true));
assertFalse(BooleanOperations.areAllTrue(true, false));
assertTrue(BooleanOperations.areAllTrue(true, true));
assertFalse(BooleanOperations.areAllTrue(false, false));
// Not really sensible, but defined contract -> Corner Case
assertTrue(BooleanOperations.areAllTrue());
assertTrue(BooleanOperations.areAllTrue(null));
}
- Author:
- Eugen Fischer, Oliver Wolff
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareAllFalse(boolean... parameter) Shorthand for checking if all given booleans arefalsestatic booleanareAllTrue(boolean... parameter) Shorthand for checking if all the given booleans aretruestatic booleanisAnyFalse(boolean... parameter) Shorthand for checking if at least one of the given booleans isfalsestatic booleanisAnyTrue(boolean... parameter) Shorthand for checking if at least one of the given booleans istruestatic booleanisValidBoolean(String value)
-
Constructor Details
-
BooleanOperations
public BooleanOperations()
-
-
Method Details
-
isAnyTrue
Shorthand for checking if at least one of the given booleans istrue- Parameters:
parameter- ellipsis of boolean values- Returns:
trueif one of parameters istrue,falseotherwise
-
areAllTrue
Shorthand for checking if all the given booleans aretrue- Parameters:
parameter- ellipsis of boolean values- Returns:
trueif all parameters aretrueor no parameter is given ratio: no given false,falseotherwise
-
areAllFalse
Shorthand for checking if all given booleans arefalse- Parameters:
parameter- ellipsis of boolean values- Returns:
trueif all parameters arefalse,trueotherwise.falseif no parameter is passed, ratio: no given false
-
isAnyFalse
Shorthand for checking if at least one of the given booleans isfalse- Parameters:
parameter- ellipsis of boolean values- Returns:
trueif one of parameters isfalse,trueotherwise
-
isValidBoolean
- Parameters:
value- to be checked- Returns:
- true, if the given value represents a boolean value i.e. "true" or "false" ignoring case.
-