I think a real neat solution for enforcing unique array lists is this one, if it's not too much code for what you're trying to achieve.
public class UniqueOverridingList extends ArrayList {
public enum LAST_RESULT {
ADD, OVERRIDE, NOTHING;
}
private LAST_RESULT lastResult;
public boolean add(T obj) {
for (int i = 0; i < size(); i++) {
if (obj.equals(get(i))) {
set(i, obj);
lastResult = LAST_RESULT.OVERRIDE;
return true;
}
}
boolean b = super.add(obj);
if (b) {
lastResult = LAST_RESULT.ADD;
} else {
lastResult = LAST_RESULT.NOTHING;
}
return b;
}
public boolean addAll(Collection c) {
boolean result = true;
for (T t : c) {
if (!add(t)) {
result = false;
}
}
return result;
}
public LAST_RESULT getLastResult() {
return lastResult;
}
}