package com.mindprod.example;
import static java.lang.System.*;
/**
* Anding/Oring an array of booleans.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-09-10 initial version
* @since 2009-09-10
*/
public final class TestAndOr
{
/**
* and together all the booleans in an array
*
* @param ba boolean array to test
*
* @return true only if all the booleans in the array are true.
*/
private static boolean and( final boolean... ba )
{
for ( boolean b : ba )
{
if ( !b )
{
return false;
}
}
return true;
}
/**
* or together all the booleans in an array
*
* @param ba boolean array to test
*
* @return true if any of the booleans in the array are true.
*/
private static boolean or( final boolean... ba )
{
for ( boolean b : ba )
{
if ( b )
{
return true;
}
}
return false;
}
/**
* Test harness
*
* @param args not used
*/
public static void main( String[] args )
{
out.println( and( true, true, false, true ) );
out.println( or( true, true, false, true ) );
out.println( and( true, true, true, true ) );
out.println( or( true, true, true, true ) );
out.println( and( false, false, false, false ) );
out.println( or( false, false, false, false ) );
}
}