/*
 * Copyright 2002-2004 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.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.springframework.core.closure.Constraint;

/**
 * A constraint that tests if an argument is one of a group.  Similiar to
 * a database's 'in' operator, and more convenient than using a bunch of ORs.
 * 
 * @author  Keith Donald
 */
public class InGroup implements Constraint {
	private Set group;

	public InGroup(Set group) {
		this.group = new HashSet(group);
	}

	public InGroup(Object[] group) {
		this.group = new HashSet(Arrays.asList(group));
	}

	/**
	 * Tests the variable argument value is in this group.
	 * 
	 * @see org.springframework.core.closure.Constraint#test(java.lang.Object)
	 */
	public boolean test(Object value) {
		return group.contains(value);
	}

	public String toString() {
		return "inGroup [" + group + "]";
	}
}
@@ -715,16 +715,43 @@
 ashSet;%0A
+import java.util.Iterator;%0A
 import j
@@ -882,17 +882,16 @@
 a group.
- 
  Similia
@@ -894,19 +894,16 @@
 iliar to
-%0A *
  a datab
@@ -942,16 +942,19 @@
 nvenient
+%0A *
  than us
@@ -988,17 +988,16 @@
 @author 
- 
 Keith Do
@@ -1050,17 +1050,20 @@
 raint %7B%0A
-%09
+    
 private 
@@ -1074,17 +1074,20 @@
 group;%0A%0A
-%09
+    
 public I
@@ -1098,34 +1098,40 @@
 up(Set group) %7B%0A
-%09%09
+        
 this.group = new
@@ -1147,21 +1147,27 @@
 group);%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 public I
@@ -1191,18 +1191,24 @@
 roup) %7B%0A
-%09%09
+        
 this.gro
@@ -1251,18 +1251,235 @@
 ));%0A
-%09%7D%0A%0A%09/**%0A%09
+    %7D%0A%0A    /**%0A     * returns an iterator of the group elements%0A     * %0A     * @return iterator containing the elements of the group.%0A     */%0A    public Iterator iterator() %7B%0A        return group.iterator();%0A    %7D%0A%0A    /**%0A    
  * T
@@ -1533,14 +1533,20 @@
 up.%0A
-%09 * %0A%09
+     * %0A    
  * @
@@ -1620,14 +1620,20 @@
 ct)%0A
-%09 */%0A%09
+     */%0A    
 publ
@@ -1660,26 +1660,32 @@
 ct value) %7B%0A
-%09%09
+        
 return group
@@ -1706,13 +1706,19 @@
 e);%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 publ
@@ -1744,10 +1744,16 @@
 ) %7B%0A
-%09%09
+        
 retu
@@ -1786,8 +1786,11 @@
 %5D%22;%0A
-%09
+    
 %7D%0A%7D

add iterator method to get access to the group elements