Revision: 1207
Author:   jhoskens
Date:     2006-06-21 02:08:04 -0700 (Wed, 21 Jun 2006)
ViewCVS:  http://svn.sourceforge.net/spring-rich-c/?rev=1207&view=rev

Log Message:
-----------
Added XOR: patch from issue RCP-370

Added Paths:
-----------
    
trunk/spring-richclient/support/src/main/java/org/springframework/rules/constraint/XOr.java
Added: 
trunk/spring-richclient/support/src/main/java/org/springframework/rules/constraint/XOr.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/rules/constraint/XOr.java
                         (rev 0)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/rules/constraint/XOr.java
 2006-06-21 09:08:04 UTC (rev 1207)
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.springframework.rules.constraint;
+
+import java.util.Iterator;
+
+import org.springframework.core.closure.Constraint;
+
+/**
+ * A "xor" compound constraint (aka exclusive disjunction).
+ * 
+ * @author Mathias Broekelmann
+ * 
+ */
+public class XOr extends CompoundConstraint {
+
+  /**
+   * Creates a empty UnaryOr disjunction.
+   */
+  public XOr() {
+    super();
+  }
+
+  /**
+   * "Ors" two constraints.
+   * 
+   * @param constraint1
+   *          The first constraint.
+   * @param constraint2
+   *          The second constraint.
+   */
+  public XOr(Constraint constraint1, Constraint constraint2) {
+    super(constraint1, constraint2);
+  }
+
+  /**
+   * "Ors" the specified constraints.
+   * 
+   * @param constraints
+   *          The constraints
+   */
+  public XOr(Constraint[] constraints) {
+    super(constraints);
+  }
+
+  /**
+   * Tests if any of the constraints aggregated by this compound constraint 
test
+   * <code>true</code>.
+   * 
+   * @see org.springframework.core.closure.Constraint#test(java.lang.Object)
+   */
+  public boolean test(Object value) {
+    boolean found = false;
+    for (Iterator i = iterator(); i.hasNext();) {
+      if (((Constraint) i.next()).test(value)) {
+        if (found) {
+          return false;
+        }
+        found = true;
+      }
+    }
+    return found;
+  }
+
+}


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs

Reply via email to