diff --git a/abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java b/abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java index 70190604150b..4ad3ce84085c 100644 --- a/abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java +++ b/abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java @@ -75,16 +75,16 @@ private String buildStringRepresentation() { builder.append(getClass().getName()).append("["); // Explaining variable for document properties map - Map documentProperties = this.documentProperties; + Map mpdocumentProperties = this.documentProperties; // Explaining variable for the size of document properties map - int numProperties = documentProperties.size(); + int numProperties = mpdocumentProperties.size(); // Explaining variable for tracking the current property index int currentPropertyIndex = 0; // Iterate over document properties map - for (Map.Entry entry : documentProperties.entrySet()) { + for (Map.Entry entry : mpdocumentProperties.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); diff --git a/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java b/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java index a86e6273d5b5..2b932727bd58 100644 --- a/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java +++ b/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java @@ -75,9 +75,9 @@ void shouldRetrieveEmptyStreamForNonExistingChildren() { @Test void shouldIncludePropsInToString() { var props = Map.of(KEY, (Object) VALUE); - var document = new DocumentImplementation(props); - assertTrue(document.toString().contains(KEY)); - assertTrue(document.toString().contains(VALUE)); + var varDocument = new DocumentImplementation(props); + assertTrue(varDocument.toString().contains(KEY)); + assertTrue(varDocument.toString().contains(VALUE)); } @Test diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/DataStore.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/DataStore.java index e9fdaa14ec1f..a7d063710c68 100644 --- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/DataStore.java +++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/DataStore.java @@ -34,7 +34,7 @@ public abstract class DataStore { private final HashMap inner; - public DataStore() { + protected DataStore() { inner = new HashMap<>(); } diff --git a/serialized-lob/src/main/java/com/iluwatar/slob/dbservice/DatabaseService.java b/serialized-lob/src/main/java/com/iluwatar/slob/dbservice/DatabaseService.java index ea54592c99d1..66555a849b1b 100644 --- a/serialized-lob/src/main/java/com/iluwatar/slob/dbservice/DatabaseService.java +++ b/serialized-lob/src/main/java/com/iluwatar/slob/dbservice/DatabaseService.java @@ -92,7 +92,7 @@ public void startupService() throws SQLException { try (var connection = dataSource.getConnection(); var statement = connection.createStatement()) { - if (dataTypeDb.equals("BINARY")) { + if (dataTypeDb.equals(BINARY_DATA)) { statement.execute(CREATE_BINARY_SCHEMA_DDL); } else { statement.execute(CREATE_TEXT_SCHEMA_DDL); diff --git a/serialized-lob/src/main/java/com/iluwatar/slob/lob/Forest.java b/serialized-lob/src/main/java/com/iluwatar/slob/lob/Forest.java index 1c14d55debd8..ae0f2ce9a9a2 100644 --- a/serialized-lob/src/main/java/com/iluwatar/slob/lob/Forest.java +++ b/serialized-lob/src/main/java/com/iluwatar/slob/lob/Forest.java @@ -48,6 +48,7 @@ public class Forest implements Serializable { private String name; + private String NEWLINE = "\n--------------------------\n"; private Set animals = new HashSet<>(); private Set plants = new HashSet<>(); @@ -105,16 +106,16 @@ public String toString() { sb.append("Forest Name = ").append(name).append("\n"); sb.append("Animals found in the ").append(name).append(" Forest: \n"); for (Animal animal : animals) { - sb.append("\n--------------------------\n"); + sb.append(NEWLINE); sb.append(animal.toString()); - sb.append("\n--------------------------\n"); + sb.append(NEWLINE); } sb.append("\n"); sb.append("Plants in the ").append(name).append(" Forest: \n"); for (Plant plant : plants) { - sb.append("\n--------------------------\n"); + sb.append(NEWLINE); sb.append(plant.toString()); - sb.append("\n--------------------------\n"); + sb.append(NEWLINE); } return sb.toString(); } diff --git a/type-object/src/main/java/com/iluwatar/typeobject/CandyGame.java b/type-object/src/main/java/com/iluwatar/typeobject/CandyGame.java index 85d39c8c79c3..55475c4b9473 100644 --- a/type-object/src/main/java/com/iluwatar/typeobject/CandyGame.java +++ b/type-object/src/main/java/com/iluwatar/typeobject/CandyGame.java @@ -79,23 +79,23 @@ void printGameStatus() { List adjacentCells(int y, int x) { var adjacent = new ArrayList(); - if (y == 0) { + if (y == 0 && cells.length > 0) { adjacent.add(this.cells[1][x]); } - if (x == 0) { + if (x == 0 & cells.length > 0) { adjacent.add(this.cells[y][1]); } - if (y == cells.length - 1) { + if ((cells.length > 0) && (y == cells.length - 1)) { adjacent.add(this.cells[cells.length - 2][x]); } - if (x == cells.length - 1) { + if ((cells.length > 0) && (x == cells.length - 1)) { adjacent.add(this.cells[y][cells.length - 2]); } - if (y > 0 && y < cells.length - 1) { + if ((cells.length > 0) && y > 0 && y < cells.length - 1) { adjacent.add(this.cells[y - 1][x]); adjacent.add(this.cells[y + 1][x]); } - if (x > 0 && x < cells.length - 1) { + if ((cells.length > 0) && x > 0 && x < cells.length - 1) { adjacent.add(this.cells[y][x - 1]); adjacent.add(this.cells[y][x + 1]); } @@ -103,23 +103,25 @@ List adjacentCells(int y, int x) { } boolean continueRound() { - for (var i = 0; i < this.cells.length; i++) { - if (this.cells[cells.length - 1][i].candy.getType().equals(Type.REWARD_FRUIT)) { - return true; + if(this.cells.length >0) { + for (var i = 0; i < this.cells.length; i++) { + if (this.cells[cells.length - 1][i].candy.getType().equals(Type.REWARD_FRUIT)) { + return true; + } } - } - for (var i = 0; i < this.cells.length; i++) { - for (var j = 0; j < this.cells.length; j++) { - if (!this.cells[i][j].candy.getType().equals(Type.REWARD_FRUIT)) { - var adj = adjacentCells(i, j); - for (Cell cell : adj) { - if (this.cells[i][j].candy.name.equals(cell.candy.name)) { - return true; + for (var i = 0; i < this.cells.length; i++) { + for (var j = 0; j < this.cells.length; j++) { + if (!this.cells[i][j].candy.getType().equals(Type.REWARD_FRUIT)) { + var adj = adjacentCells(i, j); + for (Cell cell : adj) { + if (this.cells[i][j].candy.name.equals(cell.candy.name)) { + return true; + } } } } - } } + } return false; }