001 /*
002 * Copyright 2002-2004 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy
006 * of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations
014 * under the License.
015 */
016 package org.springframework.rules.constraint;
017
018 import java.util.Iterator;
019
020 import org.springframework.rules.constraint.Constraint;
021
022 /**
023 * A "or" compound constraint (aka disjunction).
024 *
025 * @author Keith Donald
026 */
027 public class Or extends CompoundConstraint {
028
029 /**
030 * Creates a empty UnaryOr disjunction.
031 */
032 public Or() {
033 super();
034 }
035
036 /**
037 * "Ors" two constraints.
038 *
039 * @param constraint1
040 * The first constraint.
041 * @param constraint2
042 * The second constraint.
043 */
044 public Or(Constraint constraint1, Constraint constraint2) {
045 super(constraint1, constraint2);
046 }
047
048 /**
049 * "Ors" the specified constraints.
050 *
051 * @param constraints
052 * The constraints
053 */
054 public Or(Constraint[] constraints) {
055 super(constraints);
056 }
057
058 /**
059 * Tests if any of the constraints aggregated by this compound constraint
060 * test <code>true</code>.
061 *
062 * @see Constraint#test(java.lang.Object)
063 */
064 public boolean test(Object value) {
065 for (Iterator i = iterator(); i.hasNext();) {
066 if (((Constraint)i.next()).test(value)) {
067 return true;
068 }
069 }
070 return false;
071 }
072 }