Remove redundant boxing

See gh-39259
This commit is contained in:
Tobias Lippert 2024-01-21 18:49:51 +01:00 committed by Phillip Webb
parent e40f49d173
commit 74a7fbea9d
9 changed files with 21 additions and 21 deletions

View File

@ -136,12 +136,12 @@ public class Snake {
public String getLocationsJson() {
synchronized (this.monitor) {
StringBuilder sb = new StringBuilder();
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y)));
sb.append(String.format("{x: %d, y: %d}", this.head.x, this.head.y));
for (Location location : this.tail) {
sb.append(',');
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y)));
sb.append(String.format("{x: %d, y: %d}", location.x, location.y));
}
return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb);
return String.format("{'id':%d,'body':[%s]}", this.id, sb);
}
}

View File

@ -50,7 +50,7 @@ public final class SnakeTimer {
if (snakes.isEmpty()) {
startTimer();
}
snakes.put(Integer.valueOf(snake.getId()), snake);
snakes.put(snake.getId(), snake);
}
}
@ -60,7 +60,7 @@ public final class SnakeTimer {
public static void removeSnake(Snake snake) {
synchronized (MONITOR) {
snakes.remove(Integer.valueOf(snake.getId()));
snakes.remove(snake.getId());
if (snakes.isEmpty()) {
stopTimer();
}

View File

@ -69,7 +69,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
StringBuilder sb = new StringBuilder();
for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) {
Snake snake = iterator.next();
sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor()));
sb.append(String.format("{id: %d, color: '%s'}", snake.getId(), snake.getHexColor()));
if (iterator.hasNext()) {
sb.append(',');
}
@ -97,7 +97,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
SnakeTimer.removeSnake(this.snake);
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id)));
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", this.id));
}
}

View File

@ -136,12 +136,12 @@ public class Snake {
public String getLocationsJson() {
synchronized (this.monitor) {
StringBuilder sb = new StringBuilder();
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y)));
sb.append(String.format("{x: %d, y: %d}", this.head.x, this.head.y));
for (Location location : this.tail) {
sb.append(',');
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y)));
sb.append(String.format("{x: %d, y: %d}", location.x, location.y));
}
return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb);
return String.format("{'id':%d,'body':[%s]}", this.id, sb);
}
}

View File

@ -50,7 +50,7 @@ public final class SnakeTimer {
if (snakes.isEmpty()) {
startTimer();
}
snakes.put(Integer.valueOf(snake.getId()), snake);
snakes.put(snake.getId(), snake);
}
}
@ -60,7 +60,7 @@ public final class SnakeTimer {
public static void removeSnake(Snake snake) {
synchronized (MONITOR) {
snakes.remove(Integer.valueOf(snake.getId()));
snakes.remove(snake.getId());
if (snakes.isEmpty()) {
stopTimer();
}

View File

@ -69,7 +69,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
StringBuilder sb = new StringBuilder();
for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) {
Snake snake = iterator.next();
sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor()));
sb.append(String.format("{id: %d, color: '%s'}", snake.getId(), snake.getHexColor()));
if (iterator.hasNext()) {
sb.append(',');
}
@ -97,7 +97,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
SnakeTimer.removeSnake(this.snake);
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id)));
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", this.id));
}
}

View File

@ -136,12 +136,12 @@ public class Snake {
public String getLocationsJson() {
synchronized (this.monitor) {
StringBuilder sb = new StringBuilder();
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y)));
sb.append(String.format("{x: %d, y: %d}", this.head.x, this.head.y));
for (Location location : this.tail) {
sb.append(',');
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y)));
sb.append(String.format("{x: %d, y: %d}", location.x, location.y));
}
return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb);
return String.format("{'id':%d,'body':[%s]}", this.id, sb);
}
}

View File

@ -50,7 +50,7 @@ public final class SnakeTimer {
if (snakes.isEmpty()) {
startTimer();
}
snakes.put(Integer.valueOf(snake.getId()), snake);
snakes.put(snake.getId(), snake);
}
}
@ -60,7 +60,7 @@ public final class SnakeTimer {
public static void removeSnake(Snake snake) {
synchronized (MONITOR) {
snakes.remove(Integer.valueOf(snake.getId()));
snakes.remove(snake.getId());
if (snakes.isEmpty()) {
stopTimer();
}

View File

@ -69,7 +69,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
StringBuilder sb = new StringBuilder();
for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) {
Snake snake = iterator.next();
sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor()));
sb.append(String.format("{id: %d, color: '%s'}", snake.getId(), snake.getHexColor()));
if (iterator.hasNext()) {
sb.append(',');
}
@ -97,7 +97,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
SnakeTimer.removeSnake(this.snake);
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id)));
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", this.id));
}
}