1 /* 2 * Copyright 2004-2009 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springmodules.validation.util.condition.common; 18 19 import java.util.Collection; 20 21 import org.springmodules.validation.util.condition.Condition; 22 23 /** 24 * A compound condition that represent a logical and of all its associated conditions. 25 * 26 * @author Uri Boness 27 */ 28 public class AndCondition extends AbstractCompoundCondition { 29 30 /** 31 * Constructs a new AndCondition with the given condition array. 32 * 33 * @param conditions The conditions this condition is compound from. 34 */ 35 public AndCondition(Condition[] conditions) { 36 super(conditions); 37 } 38 39 /** 40 * Constructs a new AndCondition with the given condition collection. 41 * 42 * @param conditions The conditions this condition is compound from. 43 */ 44 public AndCondition(Collection conditions) { 45 super(conditions); 46 } 47 48 /** 49 * Checks whether all the associated conditions of this condition return <code>true</code>. 50 * 51 * @param object The object to be checked. 52 * @return <code>true</code> if all the associated conditions return <code>true</code>, <code>false</code> otherwise. 53 */ 54 public boolean doCheck(Object object) { 55 Condition[] conditions = getConditions(); 56 for (int i = 0; i < conditions.length; i++) { 57 if (!conditions[i].check(object)) { 58 return false; 59 } 60 } 61 return true; 62 } 63 64 }