@Override public boolean check(ValidationContext ctx, T t) { int n = getNumObjects(ctx, t); for (int i = 0; i < n; i++) { U id = getNextObject(ctx, t, i); // If id not null, but already in set if (id != null && !ids.add(id)) { if (id instanceof String) { String idStr = (String) id; if (idStr.trim().length() == 0) { continue; } } ids.clear(); // TODO - going through the list each time, having a map and going through the list only once would be much better. return false; // TODO - how do we provides the id and the elements that had the duplicated id ? } } ids.clear(); return true; }