RFR: 8294693: Add Collections.shuffle overload that accepts RandomGenerator interface [v3]
jmehrens
duke at openjdk.org
Fri Oct 14 02:22:59 UTC 2022
On Wed, 12 Oct 2022 13:26:29 GMT, Tagir F. Valeev <tvaleev at openjdk.org> wrote:
>> Java 17 added RandomGenerator interface. However, existing method Collections.shuffle accepts old java.util.Random class. While since Java 19, it's possible to use Random.from(RandomGenerator) wrapper, it would be more convenient to provide direct overload shuffle(List<?> list, RandomGenerator rnd).
>
> Tagir F. Valeev has updated the pull request incrementally with one additional commit since the last revision:
>
> Fixes according to review
>
> 1. Reduce duplication in tests
> 2. Use JumpableGenerator#copy() instead of create(1) in tests, as according to the spec, seed can be ignored
> 3. Simplify documentation for shuffle(List, Random) to avoid duplication.
Should this PR be held back by JEP: 431: Sequenced Collections?
Depending on the final API for SequencedCollection I would think it would be possible to shuffle the contents of a sequenced collection (accessed order set) if replaceAll(java.util.function.UnaryOperator) was added from List. Shuffle could be implemented like the current non-random access branch today but replace the ListIterator logic with replaceAll.
Waiting for that API to settle might save us from having to add another shuffle overload to Collections. Currently there is a workaround to shuffle with a RandomGenerator by using the wrapper which should remove some of the pressure to get this into a release quickly.
-------------
PR: https://git.openjdk.org/jdk/pull/10520
More information about the core-libs-dev
mailing list