env.warning("Wrong parameter count for array_diff()");
return NullValue.NULL;
}
AbstractFunction func =
env.findFunction(arrays[arrays.length - 1].toString().intern());
if (func == null) {
env.warning("Invalid comparison function");
return NullValue.NULL;
}
ArrayValue diffArray = new ArrayValueImpl();
for (Map.Entry<Value, Value> entry : array.entrySet()) {
boolean keyFound = false;
Value entryKey = entry.getKey();
for (int k = 0; k < arrays.length - 1 && ! keyFound; k++) {
if (! (arrays[k] instanceof ArrayValue)) {
env.warning("Argument #" + (k + 2) + " is not an array");
return NullValue.NULL;
}
Iterator<Value> keyItr = ((ArrayValue) arrays[k]).keySet().iterator();
keyFound = false;
while (keyItr.hasNext() && ! keyFound) {
Value currentKey = keyItr.next();
keyFound = ((int) func.call(env, entryKey, currentKey).toLong()) == 0;
}
}
if (! keyFound)
diffArray.put(entryKey, entry.getValue());