8274683: Code example provided by RandomGeneratorFactory does not compile

Reviewed-by: darcy
This commit is contained in:
Jim Laskey 2022-04-21 13:40:02 +00:00
parent 42baaa3bb8
commit 4732b1d038

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -67,7 +67,7 @@ import jdk.internal.util.random.RandomSupport.RandomGeneratorProperties;
* {@link RandomGeneratorFactory#create()} is used for random seed
* construction. Example;
*
* <pre>{@code
* {@snippet :
* RandomGeneratorFactory<RandomGenerator> factory = RandomGeneratorFactory.of("Random");
*
* for (int i = 0; i < 10; i++) {
@ -76,7 +76,7 @@ import jdk.internal.util.random.RandomSupport.RandomGeneratorProperties;
* System.out.println(random.nextDouble());
* }).start();
* }
* }</pre>
* }
*
* RandomGeneratorFactory also provides methods describing the attributes (or properties)
* of a generator and can be used to select random number generator
@ -87,16 +87,17 @@ import jdk.internal.util.random.RandomSupport.RandomGeneratorProperties;
* {@link RandomGenerator RandomGenerators}
* with the highest number of state bits.
*
* <pre>{@code
* {@snippet :
* RandomGeneratorFactory<RandomGenerator> best = RandomGeneratorFactory.all()
* .sorted(Comparator.comparingInt(RandomGenerator::stateBits).reversed())
* .filter(rgf -> !rgf.name().equals("SecureRandom")) // SecureRandom has MAX_VALUE stateBits.
* .sorted(Comparator.comparingInt(RandomGeneratorFactory<RandomGenerator>::stateBits).reversed())
* .findFirst()
* .orElse(RandomGeneratorFactory.of("Random"));
* System.out.println(best.name() + " in " + best.group() + " was selected");
*
* RandomGenerator rng = best.create();
* System.out.println(rng.nextLong());
* }</pre>
* }
*
* @since 17
*