// setup the two bags we'll be using
BagAttribute[] bags = new BagAttribute[2];
bags[0] = (BagAttribute) (argValues[0]);
bags[1] = (BagAttribute) (argValues[1]);
AttributeValue result = null;
Set<AttributeValue> set = new HashSet<AttributeValue>();
switch (getFunctionId()) {
// *-intersection takes two bags of the same type and returns
// a bag of that type
case ID_BASE_INTERSECTION:
// create a bag with the common elements of both inputs, removing
// all duplicate values
Iterator<AttributeValue> it = bags[0].iterator();
// find all the things in bags[0] that are also in bags[1]
while (it.hasNext()) {
AttributeValue value = (AttributeValue) (it.next());
if (bags[1].contains(value)) {
// sets won't allow duplicates, so this addition is ok
set.add(value);
}
}