Skip to content

Commit 3013175

Browse files
authored
refactoring #1012: Format specifiers should be used instead of string 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
1 parent a82966f commit 3013175

File tree

9 files changed

+19
-19
lines changed

9 files changed

+19
-19
lines changed

Diff for: commander/src/main/java/com/iluwatar/commander/Commander.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ private void handlePaymentPossibleErrorMsgErrorIssue(Order order, Order o) {
477477
&& System.currentTimeMillis() - o.createdTime < messageTime) {
478478
var qt = new QueueTask(order, TaskType.MESSAGING, 1);
479479
updateQueue(qt);
480-
LOG.warn("Order " + order.id + ": Error in sending Payment Error message, "
481-
+ "trying to queue task and add to employee handle..");
480+
LOG.warn("Order {}: Error in sending Payment Error message, trying to queue task and add to employee handle..",
481+
order.id);
482482
employeeHandleIssue(o);
483483
}
484484
}

Diff for: extension-objects/src/main/java/App.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private static void checkExtensionsForUnit(Unit unit) {
6262
final var logger = LoggerFactory.getLogger(App.class);
6363

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

6767
var extension = "SoldierExtension";
6868
Optional.ofNullable(unit.getUnitExtension(extension))

Diff for: game-loop/src/main/java/com/iluwatar/gameloop/GameLoop.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ public abstract class GameLoop {
3939

4040
protected final GameController controller;
4141

42-
private Thread gameThread;
43-
4442
/**
4543
* Initialize game status to be stopped.
4644
*/
47-
public GameLoop() {
45+
protected GameLoop() {
4846
controller = new GameController();
4947
status = GameStatus.STOPPED;
5048
}
@@ -54,7 +52,7 @@ public GameLoop() {
5452
*/
5553
public void run() {
5654
status = GameStatus.RUNNING;
57-
gameThread = new Thread(this::processGameLoop);
55+
Thread gameThread = new Thread(this::processGameLoop);
5856
gameThread.start();
5957
}
6058

@@ -85,6 +83,8 @@ protected void processInput() {
8583
Thread.sleep(lag);
8684
} catch (InterruptedException e) {
8785
logger.error(e.getMessage());
86+
/* Clean up whatever needs to be handled before interrupting */
87+
Thread.currentThread().interrupt();
8888
}
8989
}
9090

@@ -94,7 +94,7 @@ protected void processInput() {
9494
*/
9595
protected void render() {
9696
var position = controller.getBulletPosition();
97-
logger.info("Current bullet position: " + position);
97+
logger.info("Current bullet position: {}", position);
9898
}
9999

100100
/**

Diff for: special-case/src/main/java/com/iluwatar/specialcase/InvalidUser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public InvalidUser(String userName) {
4242

4343
@Override
4444
public void show() {
45-
LOGGER.info("Invalid user: " + userName);
45+
LOGGER.info(String.format("Invalid user: %s", userName));
4646
}
4747
}

Diff for: special-case/src/main/java/com/iluwatar/specialcase/MaintenanceLock.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ public boolean isLock() {
5555

5656
public void setLock(boolean lock) {
5757
this.lock = lock;
58-
LOGGER.info("Maintenance lock is set to: ", lock);
58+
LOGGER.info("Maintenance lock is set to: {}", lock);
5959
}
6060
}

Diff for: special-case/src/main/java/com/iluwatar/specialcase/OutOfStock.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public class OutOfStock implements ReceiptViewModel {
3434

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

37-
private String userName;
38-
private String itemName;
37+
private final String userName;
38+
private final String itemName;
3939

4040
public OutOfStock(String userName, String itemName) {
4141
this.userName = userName;
@@ -44,6 +44,6 @@ public OutOfStock(String userName, String itemName) {
4444

4545
@Override
4646
public void show() {
47-
LOGGER.info("Out of stock: " + itemName + " for user = " + userName + " to buy");
47+
LOGGER.info(String.format("Out of stock: %s for user = %s to buy", itemName, userName));
4848
}
4949
}

Diff for: special-case/src/main/java/com/iluwatar/specialcase/ReceiptDto.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ReceiptDto implements ReceiptViewModel {
3434

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

37-
private Double price;
37+
private final Double price;
3838

3939
public ReceiptDto(Double price) {
4040
this.price = price;
@@ -46,6 +46,6 @@ public Double getPrice() {
4646

4747
@Override
4848
public void show() {
49-
LOGGER.info("Receipt: " + price + " paid");
49+
LOGGER.info(String.format("Receipt: %s paid", price));
5050
}
5151
}

Diff for: subclass-sandbox/src/main/java/com/iluwatar/subclasssandbox/Superpower.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public abstract class Superpower {
4747
* @param z Z coordinate.
4848
*/
4949
protected void move(double x, double y, double z) {
50-
logger.info("Move to ( " + x + ", " + y + ", " + z + " )");
50+
logger.info("Move to ( {}, {}, {} )", x, y, z);
5151
}
5252

5353
/**
@@ -56,7 +56,7 @@ protected void move(double x, double y, double z) {
5656
* @param volume Value of volume.
5757
*/
5858
protected void playSound(String soundName, int volume) {
59-
logger.info("Play " + soundName + " with volume " + volume);
59+
logger.info("Play {} with volume {}", soundName, volume);
6060
}
6161

6262
/**
@@ -65,6 +65,6 @@ protected void playSound(String soundName, int volume) {
6565
* @param count Count of particles to be spawned.
6666
*/
6767
protected void spawnParticles(String particleType, int count) {
68-
logger.info("Spawn " + count + " particle with type " + particleType);
68+
logger.info("Spawn {} particle with type {}", count, particleType);
6969
}
7070
}

Diff for: update-method/src/main/java/com/iluwatar/updatemethod/Statue.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ public void update() {
6565
}
6666

6767
private void shootLightning() {
68-
logger.info("Statue " + id + " shoots lightning!");
68+
logger.info("Statue {} shoots lightning!", id);
6969
}
7070
}

0 commit comments

Comments
 (0)