📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code * Fix merge conflicts and some sonar issues Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
		| @@ -24,8 +24,7 @@ | ||||
| package com.iluwatar.doubledispatch; | ||||
|  | ||||
| import java.util.List; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
|  | ||||
| /** | ||||
|  * When a message with a parameter is sent to an object, the resultant behaviour is defined by the | ||||
| @@ -46,10 +45,9 @@ import org.slf4j.LoggerFactory; | ||||
|  * coordinates. If there is an overlap, then the objects collide utilizing the Double Dispatch | ||||
|  * pattern. | ||||
|  */ | ||||
| @Slf4j | ||||
| public class App { | ||||
|  | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(App.class); | ||||
|  | ||||
|   /** | ||||
|    * Program entry point. | ||||
|    * | ||||
|   | ||||
| @@ -24,16 +24,14 @@ | ||||
| package com.iluwatar.doubledispatch; | ||||
|  | ||||
| import com.iluwatar.doubledispatch.constants.AppConstants; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
|  | ||||
| /** | ||||
|  * Meteoroid game object. | ||||
|  */ | ||||
| @Slf4j | ||||
| public class Meteoroid extends GameObject { | ||||
|  | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(Meteoroid.class); | ||||
|  | ||||
|   public Meteoroid(int left, int top, int right, int bottom) { | ||||
|     super(left, top, right, bottom); | ||||
|   } | ||||
|   | ||||
| @@ -23,9 +23,14 @@ | ||||
|  | ||||
| package com.iluwatar.doubledispatch; | ||||
|  | ||||
| import lombok.Getter; | ||||
| import lombok.RequiredArgsConstructor; | ||||
|  | ||||
| /** | ||||
|  * Rectangle has coordinates and can be checked for overlap against other Rectangles. | ||||
|  */ | ||||
| @Getter | ||||
| @RequiredArgsConstructor | ||||
| public class Rectangle { | ||||
|  | ||||
|   private final int left; | ||||
| @@ -33,32 +38,6 @@ public class Rectangle { | ||||
|   private final int right; | ||||
|   private final int bottom; | ||||
|  | ||||
|   /** | ||||
|    * Constructor. | ||||
|    */ | ||||
|   public Rectangle(int left, int top, int right, int bottom) { | ||||
|     this.left = left; | ||||
|     this.top = top; | ||||
|     this.right = right; | ||||
|     this.bottom = bottom; | ||||
|   } | ||||
|  | ||||
|   public int getLeft() { | ||||
|     return left; | ||||
|   } | ||||
|  | ||||
|   public int getTop() { | ||||
|     return top; | ||||
|   } | ||||
|  | ||||
|   public int getRight() { | ||||
|     return right; | ||||
|   } | ||||
|  | ||||
|   public int getBottom() { | ||||
|     return bottom; | ||||
|   } | ||||
|  | ||||
|   boolean intersectsWith(Rectangle r) { | ||||
|     return !(r.getLeft() > getRight() || r.getRight() < getLeft() || r.getTop() > getBottom() || r | ||||
|         .getBottom() < getTop()); | ||||
|   | ||||
| @@ -24,16 +24,14 @@ | ||||
| package com.iluwatar.doubledispatch; | ||||
|  | ||||
| import com.iluwatar.doubledispatch.constants.AppConstants; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
|  | ||||
| /** | ||||
|  * Space station Mir game object. | ||||
|  */ | ||||
| @Slf4j | ||||
| public class SpaceStationMir extends GameObject { | ||||
|  | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(SpaceStationMir.class); | ||||
|  | ||||
|   public SpaceStationMir(int left, int top, int right, int bottom) { | ||||
|     super(left, top, right, bottom); | ||||
|   } | ||||
|   | ||||
| @@ -34,7 +34,7 @@ import org.junit.jupiter.api.Test; | ||||
|  * | ||||
|  * @author Jeroen Meulemeester | ||||
|  */ | ||||
| public class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> { | ||||
| class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> { | ||||
|  | ||||
|   @Override | ||||
|   final FlamingAsteroid getTestedObject() { | ||||
| @@ -45,7 +45,7 @@ public class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> { | ||||
|    * Test the constructor parameters | ||||
|    */ | ||||
|   @Test | ||||
|   public void testConstructor() { | ||||
|   void testConstructor() { | ||||
|     final var asteroid = new FlamingAsteroid(1, 2, 3, 4); | ||||
|     assertEquals(1, asteroid.getLeft()); | ||||
|     assertEquals(2, asteroid.getTop()); | ||||
| @@ -60,7 +60,7 @@ public class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> { | ||||
|    * Test what happens we collide with an asteroid | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideFlamingAsteroid() { | ||||
|   void testCollideFlamingAsteroid() { | ||||
|     testCollision( | ||||
|         new FlamingAsteroid(1, 2, 3, 4), | ||||
|         false, true, | ||||
| @@ -72,7 +72,7 @@ public class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> { | ||||
|    * Test what happens we collide with an meteoroid | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideMeteoroid() { | ||||
|   void testCollideMeteoroid() { | ||||
|     testCollision( | ||||
|         new Meteoroid(1, 1, 3, 4), | ||||
|         false, false, | ||||
| @@ -84,7 +84,7 @@ public class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> { | ||||
|    * Test what happens we collide with ISS | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideSpaceStationIss() { | ||||
|   void testCollideSpaceStationIss() { | ||||
|     testCollision( | ||||
|         new SpaceStationIss(1, 1, 3, 4), | ||||
|         true, true, | ||||
| @@ -96,7 +96,7 @@ public class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> { | ||||
|    * Test what happens we collide with MIR | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideSpaceStationMir() { | ||||
|   void testCollideSpaceStationMir() { | ||||
|     testCollision( | ||||
|         new SpaceStationMir(1, 1, 3, 4), | ||||
|         true, true, | ||||
|   | ||||
| @@ -33,7 +33,7 @@ import org.junit.jupiter.api.Test; | ||||
|  * | ||||
|  * @author Jeroen Meulemeester | ||||
|  */ | ||||
| public class MeteoroidTest extends CollisionTest<Meteoroid> { | ||||
| class MeteoroidTest extends CollisionTest<Meteoroid> { | ||||
|  | ||||
|   @Override | ||||
|   final Meteoroid getTestedObject() { | ||||
| @@ -44,7 +44,7 @@ public class MeteoroidTest extends CollisionTest<Meteoroid> { | ||||
|    * Test the constructor parameters | ||||
|    */ | ||||
|   @Test | ||||
|   public void testConstructor() { | ||||
|   void testConstructor() { | ||||
|     final var meteoroid = new Meteoroid(1, 2, 3, 4); | ||||
|     assertEquals(1, meteoroid.getLeft()); | ||||
|     assertEquals(2, meteoroid.getTop()); | ||||
| @@ -59,7 +59,7 @@ public class MeteoroidTest extends CollisionTest<Meteoroid> { | ||||
|    * Test what happens we collide with an asteroid | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideFlamingAsteroid() { | ||||
|   void testCollideFlamingAsteroid() { | ||||
|     testCollision( | ||||
|         new FlamingAsteroid(1, 1, 3, 4), | ||||
|         false, true, | ||||
| @@ -71,7 +71,7 @@ public class MeteoroidTest extends CollisionTest<Meteoroid> { | ||||
|    * Test what happens we collide with an meteoroid | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideMeteoroid() { | ||||
|   void testCollideMeteoroid() { | ||||
|     testCollision( | ||||
|         new Meteoroid(1, 1, 3, 4), | ||||
|         false, false, | ||||
| @@ -83,7 +83,7 @@ public class MeteoroidTest extends CollisionTest<Meteoroid> { | ||||
|    * Test what happens we collide with ISS | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideSpaceStationIss() { | ||||
|   void testCollideSpaceStationIss() { | ||||
|     testCollision( | ||||
|         new SpaceStationIss(1, 1, 3, 4), | ||||
|         true, false, | ||||
| @@ -95,7 +95,7 @@ public class MeteoroidTest extends CollisionTest<Meteoroid> { | ||||
|    * Test what happens we collide with MIR | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideSpaceStationMir() { | ||||
|   void testCollideSpaceStationMir() { | ||||
|     testCollision( | ||||
|         new SpaceStationMir(1, 1, 3, 4), | ||||
|         true, false, | ||||
|   | ||||
| @@ -32,13 +32,13 @@ import org.junit.jupiter.api.Test; | ||||
| /** | ||||
|  * Unit test for Rectangle | ||||
|  */ | ||||
| public class RectangleTest { | ||||
| class RectangleTest { | ||||
|  | ||||
|   /** | ||||
|    * Test if the values passed through the constructor matches the values fetched from the getters | ||||
|    */ | ||||
|   @Test | ||||
|   public void testConstructor() { | ||||
|   void testConstructor() { | ||||
|     final var rectangle = new Rectangle(1, 2, 3, 4); | ||||
|     assertEquals(1, rectangle.getLeft()); | ||||
|     assertEquals(2, rectangle.getTop()); | ||||
| @@ -51,7 +51,7 @@ public class RectangleTest { | ||||
|    * #toString()} | ||||
|    */ | ||||
|   @Test | ||||
|   public void testToString() throws Exception { | ||||
|   void testToString() throws Exception { | ||||
|     final var rectangle = new Rectangle(1, 2, 3, 4); | ||||
|     assertEquals("[1,2,3,4]", rectangle.toString()); | ||||
|   } | ||||
| @@ -60,7 +60,7 @@ public class RectangleTest { | ||||
|    * Test if the {@link Rectangle} class can detect if it intersects with another rectangle. | ||||
|    */ | ||||
|   @Test | ||||
|   public void testIntersection() { | ||||
|   void testIntersection() { | ||||
|     assertTrue(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(0, 0, 1, 1))); | ||||
|     assertTrue(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(-1, -5, 7, 8))); | ||||
|     assertFalse(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(2, 2, 3, 3))); | ||||
|   | ||||
| @@ -33,7 +33,7 @@ import org.junit.jupiter.api.Test; | ||||
|  * | ||||
|  * @author Jeroen Meulemeester | ||||
|  */ | ||||
| public class SpaceStationIssTest extends CollisionTest<SpaceStationIss> { | ||||
| class SpaceStationIssTest extends CollisionTest<SpaceStationIss> { | ||||
|  | ||||
|   @Override | ||||
|   final SpaceStationIss getTestedObject() { | ||||
| @@ -44,7 +44,7 @@ public class SpaceStationIssTest extends CollisionTest<SpaceStationIss> { | ||||
|    * Test the constructor parameters | ||||
|    */ | ||||
|   @Test | ||||
|   public void testConstructor() { | ||||
|   void testConstructor() { | ||||
|     final var iss = new SpaceStationIss(1, 2, 3, 4); | ||||
|     assertEquals(1, iss.getLeft()); | ||||
|     assertEquals(2, iss.getTop()); | ||||
| @@ -59,7 +59,7 @@ public class SpaceStationIssTest extends CollisionTest<SpaceStationIss> { | ||||
|    * Test what happens we collide with an asteroid | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideFlamingAsteroid() { | ||||
|   void testCollideFlamingAsteroid() { | ||||
|     testCollision( | ||||
|         new FlamingAsteroid(1, 1, 3, 4), | ||||
|         false, true, | ||||
| @@ -71,7 +71,7 @@ public class SpaceStationIssTest extends CollisionTest<SpaceStationIss> { | ||||
|    * Test what happens we collide with an meteoroid | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideMeteoroid() { | ||||
|   void testCollideMeteoroid() { | ||||
|     testCollision( | ||||
|         new Meteoroid(1, 1, 3, 4), | ||||
|         false, false, | ||||
| @@ -83,7 +83,7 @@ public class SpaceStationIssTest extends CollisionTest<SpaceStationIss> { | ||||
|    * Test what happens we collide with ISS | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideSpaceStationIss() { | ||||
|   void testCollideSpaceStationIss() { | ||||
|     testCollision( | ||||
|         new SpaceStationIss(1, 1, 3, 4), | ||||
|         true, false, | ||||
| @@ -95,7 +95,7 @@ public class SpaceStationIssTest extends CollisionTest<SpaceStationIss> { | ||||
|    * Test what happens we collide with MIR | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideSpaceStationMir() { | ||||
|   void testCollideSpaceStationMir() { | ||||
|     testCollision( | ||||
|         new SpaceStationMir(1, 1, 3, 4), | ||||
|         true, false, | ||||
|   | ||||
| @@ -33,7 +33,7 @@ import org.junit.jupiter.api.Test; | ||||
|  * | ||||
|  * @author Jeroen Meulemeester | ||||
|  */ | ||||
| public class SpaceStationMirTest extends CollisionTest<SpaceStationMir> { | ||||
| class SpaceStationMirTest extends CollisionTest<SpaceStationMir> { | ||||
|  | ||||
|   @Override | ||||
|   final SpaceStationMir getTestedObject() { | ||||
| @@ -44,7 +44,7 @@ public class SpaceStationMirTest extends CollisionTest<SpaceStationMir> { | ||||
|    * Test the constructor parameters | ||||
|    */ | ||||
|   @Test | ||||
|   public void testConstructor() { | ||||
|   void testConstructor() { | ||||
|     final var mir = new SpaceStationMir(1, 2, 3, 4); | ||||
|     assertEquals(1, mir.getLeft()); | ||||
|     assertEquals(2, mir.getTop()); | ||||
| @@ -59,7 +59,7 @@ public class SpaceStationMirTest extends CollisionTest<SpaceStationMir> { | ||||
|    * Test what happens we collide with an asteroid | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideFlamingAsteroid() { | ||||
|   void testCollideFlamingAsteroid() { | ||||
|     testCollision( | ||||
|         new FlamingAsteroid(1, 1, 3, 4), | ||||
|         false, true, | ||||
| @@ -71,7 +71,7 @@ public class SpaceStationMirTest extends CollisionTest<SpaceStationMir> { | ||||
|    * Test what happens we collide with an meteoroid | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideMeteoroid() { | ||||
|   void testCollideMeteoroid() { | ||||
|     testCollision( | ||||
|         new Meteoroid(1, 1, 3, 4), | ||||
|         false, false, | ||||
| @@ -83,7 +83,7 @@ public class SpaceStationMirTest extends CollisionTest<SpaceStationMir> { | ||||
|    * Test what happens we collide with ISS | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideSpaceStationIss() { | ||||
|   void testCollideSpaceStationIss() { | ||||
|     testCollision( | ||||
|         new SpaceStationIss(1, 1, 3, 4), | ||||
|         true, false, | ||||
| @@ -95,7 +95,7 @@ public class SpaceStationMirTest extends CollisionTest<SpaceStationMir> { | ||||
|    * Test what happens we collide with MIR | ||||
|    */ | ||||
|   @Test | ||||
|   public void testCollideSpaceStationMir() { | ||||
|   void testCollideSpaceStationMir() { | ||||
|     testCollision( | ||||
|         new SpaceStationMir(1, 1, 3, 4), | ||||
|         true, false, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user