我需要验证给定的ID列表不包含任何重复值.我这样做的尝试可以在这里显示:
public void validate(RecordCollection collection)
throws BusinessException {
LinkedHashMap existingIds = new LinkedHashMap();
for (Record record : collection.getArrayList()) {
// check that you don't have two records with the same id
if (existingIds.containsKey(record.getID())) {
throw new BusinessException("records must be unique.",
ExceptionCodes.RECORDS_MUST_BE_UNIQUE);
}
//add the id to the map of existing ids
existingIds.put(record.getID(), vo.getID());
}
有没有更有效的方法来实现此验证?