/** * Selects the entry from the list with the maximum value for ID, removing the all other entries and their values. * Assumptions: {@code list} is non-null and contains at least two valid entries. * * @param list the list to be scanned * @return the entry with the maximum value. * @throws GenericEntityException if {@link #removeEntryAndValue(GenericValue)} does */ private GenericValue selectMaximumIdAndRemoveOthers(@Nonnull List<GenericValue> list) throws GenericEntityException { final GenericValue winner = selectMaximumId(list); for (GenericValue other : list) { // The reference to "winner" was selected from this list, so "!=" is sane //noinspection ObjectEquality if (other != winner) { removeEntryAndValue(other); } } return winner; }