Use Collections.isEmpty() instead of .size() == 0
Ensure that Collections.isEmpty() is used to check if there are no elements in a collections. This is more explicit and can be faster than calling .size(). Closes gh-4783
This commit is contained in:
committed by
Phillip Webb
parent
6113643cbe
commit
786aacf2e9
@@ -42,7 +42,7 @@ public class SnakeTimer {
|
||||
private static final ConcurrentHashMap<Integer, Snake> snakes = new ConcurrentHashMap<Integer, Snake>();
|
||||
|
||||
public static synchronized void addSnake(Snake snake) {
|
||||
if (snakes.size() == 0) {
|
||||
if (snakes.isEmpty()) {
|
||||
startTimer();
|
||||
}
|
||||
snakes.put(Integer.valueOf(snake.getId()), snake);
|
||||
@@ -54,7 +54,7 @@ public class SnakeTimer {
|
||||
|
||||
public static synchronized void removeSnake(Snake snake) {
|
||||
snakes.remove(Integer.valueOf(snake.getId()));
|
||||
if (snakes.size() == 0) {
|
||||
if (snakes.isEmpty()) {
|
||||
stopTimer();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user