Skip to content

Commit

Permalink
refactoring #1012: Format specifiers should be used instead of string…
Browse files Browse the repository at this point in the history
… concatenation. (#2715)

* refactoring #1012: Format specifiers should be used instead of string concatenation.

* refactoring #1012: Format specifiers should be used instead of string concatenation.

* refactoring #1012: Remove isInfoEnabled check
  • Loading branch information
kongleong86 committed Dec 2, 2023
1 parent a82966f commit 3013175
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions commander/src/main/java/com/iluwatar/commander/Commander.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ private void handlePaymentPossibleErrorMsgErrorIssue(Order order, Order o) {
&& System.currentTimeMillis() - o.createdTime < messageTime) {
var qt = new QueueTask(order, TaskType.MESSAGING, 1);
updateQueue(qt);
LOG.warn("Order " + order.id + ": Error in sending Payment Error message, "
+ "trying to queue task and add to employee handle..");
LOG.warn("Order {}: Error in sending Payment Error message, trying to queue task and add to employee handle..",
order.id);
employeeHandleIssue(o);
}
}
Expand Down
2 changes: 1 addition & 1 deletion extension-objects/src/main/java/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static void checkExtensionsForUnit(Unit unit) {
final var logger = LoggerFactory.getLogger(App.class);

var name = unit.getName();
Function<String, Runnable> func = (e) -> () -> logger.info(name + " without " + e);
Function<String, Runnable> func = e -> () -> logger.info("{} without {}", name, e);

var extension = "SoldierExtension";
Optional.ofNullable(unit.getUnitExtension(extension))
Expand Down
10 changes: 5 additions & 5 deletions game-loop/src/main/java/com/iluwatar/gameloop/GameLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ public abstract class GameLoop {

protected final GameController controller;

private Thread gameThread;

/**
* Initialize game status to be stopped.
*/
public GameLoop() {
protected GameLoop() {
controller = new GameController();
status = GameStatus.STOPPED;
}
Expand All @@ -54,7 +52,7 @@ public GameLoop() {
*/
public void run() {
status = GameStatus.RUNNING;
gameThread = new Thread(this::processGameLoop);
Thread gameThread = new Thread(this::processGameLoop);
gameThread.start();
}

Expand Down Expand Up @@ -85,6 +83,8 @@ protected void processInput() {
Thread.sleep(lag);
} catch (InterruptedException e) {
logger.error(e.getMessage());
/* Clean up whatever needs to be handled before interrupting */
Thread.currentThread().interrupt();
}
}

Expand All @@ -94,7 +94,7 @@ protected void processInput() {
*/
protected void render() {
var position = controller.getBulletPosition();
logger.info("Current bullet position: " + position);
logger.info("Current bullet position: {}", position);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public InvalidUser(String userName) {

@Override
public void show() {
LOGGER.info("Invalid user: " + userName);
LOGGER.info(String.format("Invalid user: %s", userName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ public boolean isLock() {

public void setLock(boolean lock) {
this.lock = lock;
LOGGER.info("Maintenance lock is set to: ", lock);
LOGGER.info("Maintenance lock is set to: {}", lock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class OutOfStock implements ReceiptViewModel {

private static final Logger LOGGER = LoggerFactory.getLogger(OutOfStock.class);

private String userName;
private String itemName;
private final String userName;
private final String itemName;

public OutOfStock(String userName, String itemName) {
this.userName = userName;
Expand All @@ -44,6 +44,6 @@ public OutOfStock(String userName, String itemName) {

@Override
public void show() {
LOGGER.info("Out of stock: " + itemName + " for user = " + userName + " to buy");
LOGGER.info(String.format("Out of stock: %s for user = %s to buy", itemName, userName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ReceiptDto implements ReceiptViewModel {

private static final Logger LOGGER = LoggerFactory.getLogger(ReceiptDto.class);

private Double price;
private final Double price;

public ReceiptDto(Double price) {
this.price = price;
Expand All @@ -46,6 +46,6 @@ public Double getPrice() {

@Override
public void show() {
LOGGER.info("Receipt: " + price + " paid");
LOGGER.info(String.format("Receipt: %s paid", price));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public abstract class Superpower {
* @param z Z coordinate.
*/
protected void move(double x, double y, double z) {
logger.info("Move to ( " + x + ", " + y + ", " + z + " )");
logger.info("Move to ( {}, {}, {} )", x, y, z);
}

/**
Expand All @@ -56,7 +56,7 @@ protected void move(double x, double y, double z) {
* @param volume Value of volume.
*/
protected void playSound(String soundName, int volume) {
logger.info("Play " + soundName + " with volume " + volume);
logger.info("Play {} with volume {}", soundName, volume);
}

/**
Expand All @@ -65,6 +65,6 @@ protected void playSound(String soundName, int volume) {
* @param count Count of particles to be spawned.
*/
protected void spawnParticles(String particleType, int count) {
logger.info("Spawn " + count + " particle with type " + particleType);
logger.info("Spawn {} particle with type {}", count, particleType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ public void update() {
}

private void shootLightning() {
logger.info("Statue " + id + " shoots lightning!");
logger.info("Statue {} shoots lightning!", id);
}
}

0 comments on commit 3013175

Please sign in to comment.