Java Boolean And and(boolean b1, boolean b2)

Here you can find the source of and(boolean b1, boolean b2)

Description

Concatenate two booleans with the operation "AND"

License

Open Source License

Parameter

Parameter Description
b1 - the first boolean
b2 - the second boolean

Return

the result (b1 && b2)

Declaration

public static boolean and(boolean b1, boolean b2) 

Method Source Code

//package com.java2s;
/**// ww w .ja v  a 2  s.c o m
 * Syncnapsis Framework - Copyright (c) 2012-2014 ultimate
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either version
 * 3 of the License, or any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MECHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Plublic License along with this program;
 * if not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Concatenate two booleans with the operation "AND"<br>
     * 
     * @param b1 - the first boolean
     * @param b2 - the second boolean
     * @return the result (b1 && b2)
     */
    public static boolean and(boolean b1, boolean b2) {
        return b1 && b2;
    }

    /**
     * Concatenate two booleans with the operation "AND"<br>
     * 
     * @param b1 - the first boolean
     * @param b2 - the second boolean
     * @return the result (b1 && b2)
     */
    public static boolean and(Boolean b1, Boolean b2) {
        if (b1 == null)
            throw new IllegalArgumentException("The given Boolean b1 is null.");
        if (b2 == null)
            throw new IllegalArgumentException("The given Boolean b2 is null.");
        return b1 && b2;
    }

    /**
     * Concatenate more than two booleans with the operation "AND"<br>
     * 
     * @param b - the array of booleans
     * @return the result (b1 && b2 && b3 && ... && bn)
     */
    public static boolean and(boolean[] b) {
        if (b == null)
            throw new IllegalArgumentException("The given Array of Boolean b is null.");
        if (b.length == 0)
            throw new IllegalArgumentException("The given Array of Boolean contains no elements.");
        for (int i = 0; i < b.length; i++) {
            if (!b[i])
                return false;
        }
        return true;
    }

    /**
     * Concatenate more than two booleans with the operation "AND"<br>
     * 
     * @param b - the array of booleans
     * @return the result (b1 && b2 && b3 && ... && bn)
     */
    public static boolean and(Boolean... b) {
        if (b == null)
            throw new IllegalArgumentException("The given Array of Boolean b is null.");
        if (b.length == 0)
            throw new IllegalArgumentException("The given Array of Boolean contains no elements.");
        boolean ret = true;
        for (int i = 0; i < b.length; i++) {
            if (b[i] == null)
                throw new IllegalArgumentException(
                        "The given Array of Boolean contains a null element: index " + i + ".");
            if (!b[i])
                ret = false;
        }
        return ret;
    }
}

Related

  1. and(boolean a, boolean b)
  2. and(boolean val1, boolean val2)
  3. and(boolean... bools)
  4. and(boolean... bs)
  5. and(Boolean... operands)