/*
 * [TestAndOr.java]
 *
 * Summary: Anding/Oring an array of booleans.
 *
 * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2009-09-10 initial version
 */
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 ) );  // false
        out.println( or( true, true, false, true ) );  // true
        out.println( and( true, true, true, true ) );  // true
        out.println( or( true, true, true, true ) );  // true
        out.println( and( false, false, false, false ) );  // false
        out.println( or( false, false, false, false ) );  // false
        }
    }