|
11 | 11 | @RestController |
12 | 12 | public class RollController { |
13 | 13 |
|
14 | | - private static final Logger logger = LoggerFactory.getLogger(RollController.class); |
15 | | - private final Random random = new Random(0); |
| 14 | + private static final Logger logger = LoggerFactory.getLogger(RollController.class); |
| 15 | + private final Random random = new Random(0); |
16 | 16 |
|
17 | | - @GetMapping("/rolldice") |
18 | | - public String index(@RequestParam("player") Optional<String> player) throws InterruptedException { |
19 | | - Thread.sleep((long) (Math.abs((random.nextGaussian() + 1.0) * 200.0))); |
20 | | - if (random.nextInt(10) < 3) { |
21 | | - throw new RuntimeException("simulating an error"); |
22 | | - } |
23 | | - int result = this.getRandomNumber(1, 6); |
24 | | - if (player.isPresent()) { |
25 | | - logger.info("{} is rolling the dice: {}", player.get(), result); |
26 | | - } else { |
27 | | - logger.info("Anonymous player is rolling the dice: {}", result); |
28 | | - } |
29 | | - return Integer.toString(result); |
| 17 | + @GetMapping("/rolldice") |
| 18 | + public String index(@RequestParam("player") Optional<String> player) throws InterruptedException { |
| 19 | + Thread.sleep((long) (Math.abs((random.nextGaussian() + 1.0) * 200.0))); |
| 20 | + if (random.nextInt(10) < 3) { |
| 21 | + throw new RuntimeException("simulating an error"); |
30 | 22 | } |
31 | | - |
32 | | - public int getRandomNumber(int min, int max) { |
33 | | - return random.nextInt(min, max + 1); |
| 23 | + int result = this.getRandomNumber(1, 6); |
| 24 | + if (player.isPresent()) { |
| 25 | + logger.info("{} is rolling the dice: {}", player.get(), result); |
| 26 | + } else { |
| 27 | + logger.info("Anonymous player is rolling the dice: {}", result); |
34 | 28 | } |
| 29 | + return Integer.toString(result); |
| 30 | + } |
| 31 | + |
| 32 | + public int getRandomNumber(int min, int max) { |
| 33 | + return random.nextInt(min, max + 1); |
| 34 | + } |
35 | 35 | } |
0 commit comments