Class BooleanOperations

java.lang.Object
de.cuioss.tools.base.BooleanOperations

public final class BooleanOperations extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    areAllFalse(boolean... parameter)
    Shorthand for checking if all given booleans are false
    static boolean
    areAllTrue(boolean... parameter)
    Shorthand for checking if all the given booleans are true
    static boolean
    isAnyFalse(boolean... parameter)
    Shorthand for checking if at least one of the given booleans is false
    static boolean
    isAnyTrue(boolean... parameter)
    Shorthand for checking if at least one of the given booleans is true
    static boolean
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • isAnyTrue

      public static boolean isAnyTrue(boolean... parameter)
      Shorthand for checking if at least one of the given booleans is true
      Parameters:
      parameter - ellipsis of boolean values
      Returns:
      true if one of parameters is true, false otherwise
    • areAllTrue

      public static boolean areAllTrue(boolean... parameter)
      Shorthand for checking if all the given booleans are true
      Parameters:
      parameter - ellipsis of boolean values
      Returns:
      true if all parameters are true or no parameter is given ratio: no given false, false otherwise
    • areAllFalse

      public static boolean areAllFalse(boolean... parameter)
      Shorthand for checking if all given booleans are false
      Parameters:
      parameter - ellipsis of boolean values
      Returns:
      true if all parameters are false, true otherwise. false if no parameter is passed, ratio: no given false
    • isAnyFalse

      public static boolean isAnyFalse(boolean... parameter)
      Shorthand for checking if at least one of the given booleans is false
      Parameters:
      parameter - ellipsis of boolean values
      Returns:
      true if one of parameters is false, true otherwise
    • isValidBoolean

      public static boolean isValidBoolean(String value)
      Parameters:
      value - to be checked
      Returns:
      true, if the given value represents a boolean value i.e. "true" or "false" ignoring case.