Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonarcloud vernability fix issue #2865 #3058

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ private String buildStringRepresentation() {
builder.append(getClass().getName()).append("[");

// Explaining variable for document properties map
Map<String, Object> documentProperties = this.documentProperties;
Map<String, Object> 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<String, Object> entry : documentProperties.entrySet()) {
for (Map.Entry<String, Object> entry : mpdocumentProperties.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public abstract class DataStore<V> {
private final HashMap<String, V> inner;

public DataStore() {
protected DataStore() {
inner = new HashMap<>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
public class Forest implements Serializable {

private String name;
private String NEWLINE = "\n--------------------------\n";
private Set<Animal> animals = new HashSet<>();
private Set<Plant> plants = new HashSet<>();

Expand Down Expand Up @@ -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();
}
Expand Down
38 changes: 20 additions & 18 deletions type-object/src/main/java/com/iluwatar/typeobject/CandyGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,47 +79,49 @@ void printGameStatus() {

List<Cell> adjacentCells(int y, int x) {
var adjacent = new ArrayList<Cell>();
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]);
}
return adjacent;
}

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;
}

Expand Down
Loading