/* * Created on Jun 9, 2005 * */ package aima.util; import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class SetOps { public Set union(Set one, Set two) { Set union = new HashSet(one); union.addAll(two); return union; } public Set intersection(Set one, Set two) { Set intersection = new HashSet(one); intersection.retainAll(two); return intersection; } public Set difference(Set one, Set two) { Set three = new HashSet(); Iterator iteratorOne = one.iterator(); while (iteratorOne.hasNext()) { T sym = iteratorOne.next(); if (!(in(two, sym))) { three.add(sym); } } return three; } public boolean in(Set s, T o) { Iterator i = s.iterator(); while (i.hasNext()) { Object obj = i.next(); if (obj.equals(o)) { return true; } } return false; } }