Java examples for java.lang:boolean
Returns true if at least one of elements are true otherwise false.
public class Main{ private static final String NULL_ARRAY_MSG = "The Array must not be null"; private static final String EMPTY_ARRAY_MSG = "Array is empty"; private static final String NULL_VALUE_IN_ARRAY_MSG = "Array shouldn`t contain null objects"; /**//from ww w . j a va 2 s . c o m * Returns true if at least one of elements are true otherwise false. * * @exception java.lang.IllegalArgumentException for null or an empty array. */ public static boolean or(boolean[] values) { checkOnEmptyArray(values); boolean result = values[0]; for (int i = 1; i < values.length; i++) { result = result || values[i]; } return result; } /** * Returns true if at least one of elements are true otherwise false. * * @exception java.lang.IllegalArgumentException for null or an empty array or null value in the array. */ public static boolean or(Boolean[] values) { checkOnEmptyArray(values); Boolean result = values[0]; for (int i = 1; i < values.length; i++) { result = result || values[i]; } return result; } private static void checkOnEmptyArray(Boolean[] values) { if (values == null) { throw new IllegalArgumentException(NULL_ARRAY_MSG); } if (values.length == 0) { throw new IllegalArgumentException(EMPTY_ARRAY_MSG); } if (CollectionUtils.hasNull(values)) { throw new IllegalArgumentException(NULL_VALUE_IN_ARRAY_MSG); } } private static void checkOnEmptyArray(boolean[] values) { if (values == null) { throw new IllegalArgumentException(NULL_ARRAY_MSG); } if (values.length == 0) { throw new IllegalArgumentException(EMPTY_ARRAY_MSG); } } }