mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-28 12:22:28 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -32,17 +32,15 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* improve performance by increasing data locality — keeping data in contiguous memory in the order
|
||||
* that you process it.
|
||||
*
|
||||
* <p>Example: Game loop that processes a bunch of game entities. Those entities are decomposed
|
||||
* into different domains — AI, physics, and rendering — using the Component pattern.
|
||||
* <p>Example: Game loop that processes a bunch of game entities. Those entities are decomposed into
|
||||
* different domains — AI, physics, and rendering — using the Component pattern.
|
||||
*/
|
||||
@Slf4j
|
||||
public class Application {
|
||||
|
||||
private static final int NUM_ENTITIES = 5;
|
||||
|
||||
/**
|
||||
* Start game loop with each component have NUM_ENTITIES instance.
|
||||
*/
|
||||
/** Start game loop with each component have NUM_ENTITIES instance. */
|
||||
public static void main(String[] args) {
|
||||
LOGGER.info("Start Game Application using Data-Locality pattern");
|
||||
var gameEntity = new GameEntity(NUM_ENTITIES);
|
||||
|
||||
@@ -46,9 +46,7 @@ public class GameEntity {
|
||||
private final PhysicsComponentManager physicsComponentManager;
|
||||
private final RenderComponentManager renderComponentManager;
|
||||
|
||||
/**
|
||||
* Init components.
|
||||
*/
|
||||
/** Init components. */
|
||||
public GameEntity(int numEntities) {
|
||||
LOGGER.info("Init Game with #Entity : {}", numEntities);
|
||||
aiComponentManager = new AiComponentManager(numEntities);
|
||||
@@ -56,9 +54,7 @@ public class GameEntity {
|
||||
renderComponentManager = new RenderComponentManager(numEntities);
|
||||
}
|
||||
|
||||
/**
|
||||
* start all component.
|
||||
*/
|
||||
/** start all component. */
|
||||
public void start() {
|
||||
LOGGER.info("Start Game");
|
||||
aiComponentManager.start();
|
||||
@@ -66,9 +62,7 @@ public class GameEntity {
|
||||
renderComponentManager.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* update all component.
|
||||
*/
|
||||
/** update all component. */
|
||||
public void update() {
|
||||
LOGGER.info("Update Game Component");
|
||||
// Process AI.
|
||||
@@ -80,5 +74,4 @@ public class GameEntity {
|
||||
// Draw to screen.
|
||||
renderComponentManager.render();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-6
@@ -26,15 +26,11 @@ package com.iluwatar.data.locality.game.component;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Implementation of AI component for Game.
|
||||
*/
|
||||
/** Implementation of AI component for Game. */
|
||||
@Slf4j
|
||||
public class AiComponent implements Component {
|
||||
|
||||
/**
|
||||
* Update ai component.
|
||||
*/
|
||||
/** Update ai component. */
|
||||
@Override
|
||||
public void update() {
|
||||
LOGGER.info("update AI component");
|
||||
|
||||
+1
-3
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.data.locality.game.component;
|
||||
|
||||
/**
|
||||
* Implement different Game component update and render process.
|
||||
*/
|
||||
/** Implement different Game component update and render process. */
|
||||
public interface Component {
|
||||
|
||||
void update();
|
||||
|
||||
+2
-6
@@ -26,15 +26,11 @@ package com.iluwatar.data.locality.game.component;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Implementation of Physics Component of Game.
|
||||
*/
|
||||
/** Implementation of Physics Component of Game. */
|
||||
@Slf4j
|
||||
public class PhysicsComponent implements Component {
|
||||
|
||||
/**
|
||||
* update physics component of game.
|
||||
*/
|
||||
/** update physics component of game. */
|
||||
@Override
|
||||
public void update() {
|
||||
LOGGER.info("Update physics component of game");
|
||||
|
||||
+2
-6
@@ -26,9 +26,7 @@ package com.iluwatar.data.locality.game.component;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Implementation of Render Component of Game.
|
||||
*/
|
||||
/** Implementation of Render Component of Game. */
|
||||
@Slf4j
|
||||
public class RenderComponent implements Component {
|
||||
|
||||
@@ -37,9 +35,7 @@ public class RenderComponent implements Component {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* render.
|
||||
*/
|
||||
/** render. */
|
||||
@Override
|
||||
public void render() {
|
||||
LOGGER.info("Render Component");
|
||||
|
||||
+3
-9
@@ -29,9 +29,7 @@ import com.iluwatar.data.locality.game.component.Component;
|
||||
import java.util.stream.IntStream;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* AI component manager for Game.
|
||||
*/
|
||||
/** AI component manager for Game. */
|
||||
@Slf4j
|
||||
public class AiComponentManager {
|
||||
|
||||
@@ -45,17 +43,13 @@ public class AiComponentManager {
|
||||
this.numEntities = numEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* start AI component of Game.
|
||||
*/
|
||||
/** start AI component of Game. */
|
||||
public void start() {
|
||||
LOGGER.info("Start AI Game Component");
|
||||
IntStream.range(0, numEntities).forEach(i -> aiComponents[i] = new AiComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update AI component of Game.
|
||||
*/
|
||||
/** Update AI component of Game. */
|
||||
public void update() {
|
||||
LOGGER.info("Update AI Game Component");
|
||||
IntStream.range(0, numEntities)
|
||||
|
||||
+3
-10
@@ -29,9 +29,7 @@ import com.iluwatar.data.locality.game.component.PhysicsComponent;
|
||||
import java.util.stream.IntStream;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Physics component Manager for Game.
|
||||
*/
|
||||
/** Physics component Manager for Game. */
|
||||
@Slf4j
|
||||
public class PhysicsComponentManager {
|
||||
|
||||
@@ -45,18 +43,13 @@ public class PhysicsComponentManager {
|
||||
this.numEntities = numEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start physics component of Game.
|
||||
*/
|
||||
/** Start physics component of Game. */
|
||||
public void start() {
|
||||
LOGGER.info("Start Physics Game Component ");
|
||||
IntStream.range(0, numEntities).forEach(i -> physicsComponents[i] = new PhysicsComponent());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update physics component of Game.
|
||||
*/
|
||||
/** Update physics component of Game. */
|
||||
public void update() {
|
||||
LOGGER.info("Update Physics Game Component ");
|
||||
// Process physics.
|
||||
|
||||
+3
-10
@@ -29,9 +29,7 @@ import com.iluwatar.data.locality.game.component.RenderComponent;
|
||||
import java.util.stream.IntStream;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Render component manager for Game.
|
||||
*/
|
||||
/** Render component manager for Game. */
|
||||
@Slf4j
|
||||
public class RenderComponentManager {
|
||||
|
||||
@@ -45,18 +43,13 @@ public class RenderComponentManager {
|
||||
this.numEntities = numEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start render component.
|
||||
*/
|
||||
/** Start render component. */
|
||||
public void start() {
|
||||
LOGGER.info("Start Render Game Component ");
|
||||
IntStream.range(0, numEntities).forEach(i -> renderComponents[i] = new RenderComponent());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* render component.
|
||||
*/
|
||||
/** render component. */
|
||||
public void render() {
|
||||
LOGGER.info("Update Render Game Component ");
|
||||
// Process Render.
|
||||
|
||||
@@ -24,24 +24,20 @@
|
||||
*/
|
||||
package com.iluwatar.data.locality;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
/**
|
||||
* Test Game Application
|
||||
*/
|
||||
/** Test Game Application */
|
||||
class ApplicationTest {
|
||||
|
||||
/**
|
||||
* Issue: Add at least one assertion to this test case.
|
||||
* Solution: Inserted assertion to check whether the execution of the main method in {@link Application#main(String[])}
|
||||
* throws an exception.
|
||||
* Issue: Add at least one assertion to this test case. Solution: Inserted assertion to check
|
||||
* whether the execution of the main method in {@link Application#main(String[])} throws an
|
||||
* exception.
|
||||
*/
|
||||
|
||||
@Test
|
||||
void shouldExecuteGameApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> Application.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> Application.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user