From 82f9a6c2323b412036965fc51e5ec155b6cf7741 Mon Sep 17 00:00:00 2001 From: Christopher O'Connell Date: Sun, 20 Oct 2019 02:02:36 -0400 Subject: [PATCH] 1010: Fixed the two remaining SonarCloud errors (#1023) The two remaining files were still creating a Random everytime the method was called. These were missed in the previous commit because the previous commit had fixed only one of the methods; in other words, there were multiple methods that were creating the Random object on each call. --- .../java/com/iluwatar/hexagonal/sampledata/SampleData.java | 3 +-- .../src/main/java/com/iluwatar/typeobject/CellPool.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/hexagonal/src/main/java/com/iluwatar/hexagonal/sampledata/SampleData.java b/hexagonal/src/main/java/com/iluwatar/hexagonal/sampledata/SampleData.java index bc4e963e1..29a9d3233 100644 --- a/hexagonal/src/main/java/com/iluwatar/hexagonal/sampledata/SampleData.java +++ b/hexagonal/src/main/java/com/iluwatar/hexagonal/sampledata/SampleData.java @@ -102,8 +102,7 @@ public class SampleData { } private static PlayerDetails getRandomPlayerDetails() { - Random random = new Random(); - int idx = random.nextInt(PLAYERS.size()); + int idx = RANDOM.nextInt(PLAYERS.size()); return PLAYERS.get(idx); } } diff --git a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CellPool.java b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CellPool.java index e04cce4f0..6014da0cf 100644 --- a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CellPool.java +++ b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CellPool.java @@ -71,8 +71,7 @@ public class CellPool { } void addNewCell(Cell c) { - Random rand = new Random(); - c.candy = randomCode[rand.nextInt(randomCode.length)]; //changing candytype to new + c.candy = randomCode[RANDOM.nextInt(randomCode.length)]; //changing candytype to new this.pool.add(c); pointer++; }