RFR: 8294693: Add Collections.shuffle overload that accepts RandomGenerator interface [v3]
jmehrens
duke at openjdk.org
Tue Oct 18 02:01:05 UTC 2022
On Sat, 15 Oct 2022 07:30:54 GMT, Tagir F. Valeev <tvaleev at openjdk.org> wrote:
> For unsorted sets like LinkedHashSet, it's unclear how to behave if replaceAll returns identical elements. Throw an exception? Shrink the set size via deduplication?
I would assume the spec for replaceAll would be borrowed from Map.html#replaceAll(java.util.function.BiFunction). Shrinking size is not an option because that is a ConcurrentModificationException. Adding elements to the set would a ConcurrentModificationException. Therefore, LinkedHashSet::replaceAll would have to be swapping the order of the linked entries already contained in the set. So in your example of returning identical elements the answer is CCE (or IAE) if the element is not contained in the set. Otherwise, the element is eventually moved to the last entry in the set.
-------------
PR: https://git.openjdk.org/jdk/pull/10520
More information about the core-libs-dev
mailing list