mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 05:25:45 +00:00
Resolves checkstyle errors for facade factory-kit spatial-partition state step-builder (#1077)
* Reduces checkstyle errors in facade * Reduces checkstyle errors in factory-kit * Reduces checkstyle errors in spatial-partition * Reduces checkstyle errors in state * Reduces checkstyle errors in step-builder
This commit is contained in:
committed by
Ilkka Seppälä
parent
2628cc0dfc
commit
c954a436ad
@@ -23,16 +23,15 @@
|
||||
|
||||
package com.iluwatar.spatialpartition;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Random;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Bubble class extends Point. In this example, we create several bubbles in the field,
|
||||
* let them move and keep track of which ones have popped and which ones remain.
|
||||
* Bubble class extends Point. In this example, we create several bubbles in the field, let them
|
||||
* move and keep track of which ones have popped and which ones remain.
|
||||
*/
|
||||
|
||||
public class Bubble extends Point<Bubble> {
|
||||
@@ -42,24 +41,26 @@ public class Bubble extends Point<Bubble> {
|
||||
final int radius;
|
||||
|
||||
Bubble(int x, int y, int id, int radius) {
|
||||
super(x,y,id);
|
||||
super(x, y, id);
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
void move() {
|
||||
//moves by 1 unit in either direction
|
||||
this.x += RANDOM.nextInt(3) - 1;
|
||||
this.y += RANDOM.nextInt(3) - 1;
|
||||
this.coordinateX += RANDOM.nextInt(3) - 1;
|
||||
this.coordinateY += RANDOM.nextInt(3) - 1;
|
||||
}
|
||||
|
||||
boolean touches(Bubble b) {
|
||||
//distance between them is greater than sum of radii (both sides of equation squared)
|
||||
return (this.x - b.x) * (this.x - b.x) + (this.y - b.y) * (this.y - b.y)
|
||||
<= (this.radius + b.radius) * (this.radius + b.radius);
|
||||
return (this.coordinateX - b.coordinateX) * (this.coordinateX - b.coordinateX)
|
||||
+ (this.coordinateY - b.coordinateY) * (this.coordinateY - b.coordinateY)
|
||||
<= (this.radius + b.radius) * (this.radius + b.radius);
|
||||
}
|
||||
|
||||
void pop(Hashtable<Integer, Bubble> allBubbles) {
|
||||
LOGGER.info("Bubble " + this.id + " popped at (" + this.x + "," + this.y + ")!");
|
||||
LOGGER.info("Bubble " + this.id
|
||||
+ " popped at (" + this.coordinateX + "," + this.coordinateY + ")!");
|
||||
allBubbles.remove(this.id);
|
||||
}
|
||||
|
||||
@@ -68,8 +69,8 @@ public class Bubble extends Point<Bubble> {
|
||||
for (int i = 0; i < bubblesToCheck.size(); i++) {
|
||||
Integer otherId = bubblesToCheck.get(i).id;
|
||||
if (allBubbles.get(otherId) != null && //the bubble hasn't been popped yet
|
||||
this.id != otherId && //the two bubbles are not the same
|
||||
this.touches(allBubbles.get(otherId))) { //the bubbles touch
|
||||
this.id != otherId && //the two bubbles are not the same
|
||||
this.touches(allBubbles.get(otherId))) { //the bubbles touch
|
||||
allBubbles.get(otherId).pop(allBubbles);
|
||||
toBePopped = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user