diff --git a/pom.xml b/pom.xml index 06688cf..471b413 100644 --- a/pom.xml +++ b/pom.xml @@ -4,18 +4,18 @@ com.tvd12 - ezyfox-server - 1.0.3 + ezyfox + 1.0.4 game-box - 1.1.3 + 1.1.4 game-box https://youngmonkeys.org/ - 1.2.2 + 1.2.3 diff --git a/src/main/java/com/tvd12/gamebox/constant/Commands.java b/src/main/java/com/tvd12/gamebox/constant/Commands.java index 4e79518..3caf82b 100644 --- a/src/main/java/com/tvd12/gamebox/constant/Commands.java +++ b/src/main/java/com/tvd12/gamebox/constant/Commands.java @@ -4,6 +4,5 @@ public final class Commands { public static final String SYNC_POSITION = "s"; - private Commands() { - } + private Commands() {} } diff --git a/src/main/java/com/tvd12/gamebox/constant/IPlayerRole.java b/src/main/java/com/tvd12/gamebox/constant/IPlayerRole.java index c1a220d..9e38f44 100644 --- a/src/main/java/com/tvd12/gamebox/constant/IPlayerRole.java +++ b/src/main/java/com/tvd12/gamebox/constant/IPlayerRole.java @@ -2,6 +2,4 @@ import com.tvd12.ezyfox.constant.EzyConstant; -@SuppressWarnings("AbbreviationAsWordInName") -public interface IPlayerRole extends EzyConstant { -} +public interface IPlayerRole extends EzyConstant {} diff --git a/src/main/java/com/tvd12/gamebox/constant/IPlayerStatus.java b/src/main/java/com/tvd12/gamebox/constant/IPlayerStatus.java index 75b8437..c5cf740 100644 --- a/src/main/java/com/tvd12/gamebox/constant/IPlayerStatus.java +++ b/src/main/java/com/tvd12/gamebox/constant/IPlayerStatus.java @@ -2,6 +2,4 @@ import com.tvd12.ezyfox.constant.EzyConstant; -@SuppressWarnings("AbbreviationAsWordInName") -public interface IPlayerStatus extends EzyConstant { -} +public interface IPlayerStatus extends EzyConstant {} diff --git a/src/main/java/com/tvd12/gamebox/constant/IRoomStatus.java b/src/main/java/com/tvd12/gamebox/constant/IRoomStatus.java index 98e7fc0..f6e6762 100644 --- a/src/main/java/com/tvd12/gamebox/constant/IRoomStatus.java +++ b/src/main/java/com/tvd12/gamebox/constant/IRoomStatus.java @@ -2,6 +2,4 @@ import com.tvd12.ezyfox.constant.EzyConstant; -@SuppressWarnings("AbbreviationAsWordInName") -public interface IRoomStatus extends EzyConstant { -} +public interface IRoomStatus extends EzyConstant {} diff --git a/src/main/java/com/tvd12/gamebox/constant/PlayerRole.java b/src/main/java/com/tvd12/gamebox/constant/PlayerRole.java index a5c5ace..0352b99 100644 --- a/src/main/java/com/tvd12/gamebox/constant/PlayerRole.java +++ b/src/main/java/com/tvd12/gamebox/constant/PlayerRole.java @@ -13,17 +13,18 @@ public enum PlayerRole implements IPlayerRole { PLAYER(3), NPC(4); + @Getter + private final int id; + private static final Map ROLE_BY_ID = EzyEnums.enumMapInt(PlayerRole.class); - @Getter - private int id; - private PlayerRole(int id) { + PlayerRole(int id) { this.id = id; } public static PlayerRole valueOf(int id) { - return ROLE_BY_ID.getOrDefault(Integer.valueOf(id), NULL); + return ROLE_BY_ID.getOrDefault(id, NULL); } @Override diff --git a/src/main/java/com/tvd12/gamebox/constant/PlayerStatus.java b/src/main/java/com/tvd12/gamebox/constant/PlayerStatus.java index cdd608e..13aa074 100644 --- a/src/main/java/com/tvd12/gamebox/constant/PlayerStatus.java +++ b/src/main/java/com/tvd12/gamebox/constant/PlayerStatus.java @@ -12,17 +12,18 @@ public enum PlayerStatus implements IPlayerStatus { PLAYING(2), SPEAKING(3); + @Getter + private final int id; + private static final Map STATUS_BY_ID = EzyEnums.enumMapInt(PlayerStatus.class); - @Getter - private int id; - private PlayerStatus(int id) { + PlayerStatus(int id) { this.id = id; } public static PlayerStatus valueOf(int id) { - return STATUS_BY_ID.getOrDefault(Integer.valueOf(id), NULL); + return STATUS_BY_ID.getOrDefault(id, NULL); } @Override diff --git a/src/main/java/com/tvd12/gamebox/constant/RoomStatus.java b/src/main/java/com/tvd12/gamebox/constant/RoomStatus.java index 9e7f29c..6b4342c 100644 --- a/src/main/java/com/tvd12/gamebox/constant/RoomStatus.java +++ b/src/main/java/com/tvd12/gamebox/constant/RoomStatus.java @@ -13,17 +13,18 @@ public enum RoomStatus implements IRoomStatus { FINISHING(4), FINISHED(5); + @Getter + private final int id; + private static final Map STATUS_BY_ID = EzyEnums.enumMapInt(RoomStatus.class); - @Getter - private int id; - private RoomStatus(int id) { + RoomStatus(int id) { this.id = id; } public static RoomStatus valueOf(int id) { - return STATUS_BY_ID.get(Integer.valueOf(id)); + return STATUS_BY_ID.get(id); } @Override diff --git a/src/main/java/com/tvd12/gamebox/entity/LocatedPlayer.java b/src/main/java/com/tvd12/gamebox/entity/LocatedPlayer.java index b585d55..84691fe 100644 --- a/src/main/java/com/tvd12/gamebox/entity/LocatedPlayer.java +++ b/src/main/java/com/tvd12/gamebox/entity/LocatedPlayer.java @@ -32,7 +32,5 @@ protected Player newProduct() { public LocatedPlayer build() { return (LocatedPlayer) super.build(); } - } - } diff --git a/src/main/java/com/tvd12/gamebox/entity/LocatedRoom.java b/src/main/java/com/tvd12/gamebox/entity/LocatedRoom.java index acb81ee..24231f1 100644 --- a/src/main/java/com/tvd12/gamebox/entity/LocatedRoom.java +++ b/src/main/java/com/tvd12/gamebox/entity/LocatedRoom.java @@ -88,5 +88,4 @@ protected LocatedRoom newProduct() { return new LocatedRoom(this); } } - } diff --git a/src/main/java/com/tvd12/gamebox/entity/MMOPlayer.java b/src/main/java/com/tvd12/gamebox/entity/MMOPlayer.java index 206464d..6972819 100644 --- a/src/main/java/com/tvd12/gamebox/entity/MMOPlayer.java +++ b/src/main/java/com/tvd12/gamebox/entity/MMOPlayer.java @@ -12,18 +12,21 @@ import java.util.concurrent.atomic.AtomicBoolean; @Getter -@SuppressWarnings("AbbreviationAsWordInName") public class MMOPlayer extends Player { - @Getter(AccessLevel.NONE) - protected final Map nearbyPlayers = new ConcurrentHashMap<>(); protected Vec3 position = new Vec3(); protected Vec3 rotation = new Vec3(); - @Getter(AccessLevel.NONE) - protected AtomicBoolean stateChanged = new AtomicBoolean(false); @Setter protected int clientTimeTick; + @Getter(AccessLevel.NONE) + protected final AtomicBoolean stateChanged + = new AtomicBoolean(false); + + @Getter(AccessLevel.NONE) + protected final Map nearbyPlayers + = new ConcurrentHashMap<>(); + public MMOPlayer(String name) { super(name); } @@ -84,7 +87,7 @@ public void getNearbyPlayerNames(List buffer) { } public List getNearbyPlayerNames() { - return new ArrayList(nearbyPlayers.keySet()); + return new ArrayList<>(nearbyPlayers.keySet()); } public static class Builder extends Player.Builder { diff --git a/src/main/java/com/tvd12/gamebox/entity/MMORoom.java b/src/main/java/com/tvd12/gamebox/entity/MMORoom.java index c8dbe7f..6cc59c6 100644 --- a/src/main/java/com/tvd12/gamebox/entity/MMORoom.java +++ b/src/main/java/com/tvd12/gamebox/entity/MMORoom.java @@ -9,16 +9,15 @@ import java.util.ArrayList; import java.util.List; -@SuppressWarnings("AbbreviationAsWordInName") public class MMORoom extends NormalRoom { + @Getter + @Setter + protected MMOPlayer master; @Getter protected final double distanceOfInterest; protected final List playerBuffer; protected final List roomUpdatedHandlers; - @Getter - @Setter - protected MMOPlayer master; public MMORoom(Builder builder) { super(builder); diff --git a/src/main/java/com/tvd12/gamebox/entity/MMORoomGroup.java b/src/main/java/com/tvd12/gamebox/entity/MMORoomGroup.java index ad99a68..e7dc625 100644 --- a/src/main/java/com/tvd12/gamebox/entity/MMORoomGroup.java +++ b/src/main/java/com/tvd12/gamebox/entity/MMORoomGroup.java @@ -9,13 +9,14 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -@SuppressWarnings("AbbreviationAsWordInName") class MMORoomGroup extends EzyLoggable { - private static final AtomicInteger COUNTER = new AtomicInteger(); + private volatile boolean active; private final long timeTickMillis; private final RoomManager roomManager; - private volatile boolean active; + + private static final AtomicInteger COUNTER + = new AtomicInteger(); protected MMORoomGroup(Builder builder) { this.timeTickMillis = builder.timeTickMillis; @@ -43,6 +44,7 @@ private void loop() { long end = System.currentTimeMillis(); long timeElapsed = end - start; if (timeElapsed < timeTickMillis) { + //noinspection BusyWait Thread.sleep(timeTickMillis - timeElapsed); } } catch (Exception e) { diff --git a/src/main/java/com/tvd12/gamebox/entity/MMOVirtualWorld.java b/src/main/java/com/tvd12/gamebox/entity/MMOVirtualWorld.java index bc53166..d7cf755 100644 --- a/src/main/java/com/tvd12/gamebox/entity/MMOVirtualWorld.java +++ b/src/main/java/com/tvd12/gamebox/entity/MMOVirtualWorld.java @@ -6,7 +6,6 @@ import java.util.Arrays; -@SuppressWarnings("AbbreviationAsWordInName") public class MMOVirtualWorld extends EzyLoggable { private final MMORoomGroup[] roomGroups; @@ -89,6 +88,5 @@ public Builder timeTickMillis(int timeTickMillis) { public MMOVirtualWorld build() { return new MMOVirtualWorld(this); } - } } diff --git a/src/main/java/com/tvd12/gamebox/entity/Player.java b/src/main/java/com/tvd12/gamebox/entity/Player.java index b0f996d..f3eedb7 100644 --- a/src/main/java/com/tvd12/gamebox/entity/Player.java +++ b/src/main/java/com/tvd12/gamebox/entity/Player.java @@ -68,13 +68,10 @@ public Player build() { return newProduct(); } - protected void preBuild() { - } + protected void preBuild() {} protected Player newProduct() { return new Player(this); } - } - } diff --git a/src/main/java/com/tvd12/gamebox/entity/Room.java b/src/main/java/com/tvd12/gamebox/entity/Room.java index ce05af4..907170a 100644 --- a/src/main/java/com/tvd12/gamebox/entity/Room.java +++ b/src/main/java/com/tvd12/gamebox/entity/Room.java @@ -11,7 +11,6 @@ @Getter public class Room { - protected static final String NAME_PREFIX = "Room#"; protected final long id; protected final String name; @Setter @@ -19,6 +18,8 @@ public class Room { @Setter protected IRoomStatus status = RoomStatus.WAITING; + protected static final String NAME_PREFIX = "Room#"; + protected Room(Builder builder) { this.id = builder.id; this.name = builder.name; @@ -46,12 +47,10 @@ public int hashCode() { @Override public String toString() { - return new StringBuilder() - .append("(") - .append("name = ").append(name) - .append(", id = ").append(id) - .append(")") - .toString(); + return "(" + + "name = " + name + + ", id = " + id + + ")"; } @SuppressWarnings("unchecked") @@ -83,8 +82,7 @@ public Room build() { return newProduct(); } - protected void preBuild() { - } + protected void preBuild() {} protected Room newProduct() { return new Room(this); diff --git a/src/main/java/com/tvd12/gamebox/exception/LocationNotAvailableException.java b/src/main/java/com/tvd12/gamebox/exception/LocationNotAvailableException.java index 6c85c1b..1893917 100644 --- a/src/main/java/com/tvd12/gamebox/exception/LocationNotAvailableException.java +++ b/src/main/java/com/tvd12/gamebox/exception/LocationNotAvailableException.java @@ -6,5 +6,4 @@ public class LocationNotAvailableException extends IllegalArgumentException { public LocationNotAvailableException(String msg) { super(msg); } - } diff --git a/src/main/java/com/tvd12/gamebox/exception/MaxPlayerException.java b/src/main/java/com/tvd12/gamebox/exception/MaxPlayerException.java index edc4cd3..5f99179 100644 --- a/src/main/java/com/tvd12/gamebox/exception/MaxPlayerException.java +++ b/src/main/java/com/tvd12/gamebox/exception/MaxPlayerException.java @@ -7,20 +7,27 @@ public MaxPlayerException(String msg) { super(msg); } - public MaxPlayerException(String player, int currentPlayerCount, int maxPlayerCount) { - this(new StringBuilder() - .append("can not add new player: ").append(player) - .append(", current player count is: ").append(currentPlayerCount) - .append(" when max player count is: ").append(maxPlayerCount) - .toString()); + public MaxPlayerException( + String player, + int currentPlayerCount, + int maxPlayerCount + ) { + this( + "can not add new player: " + player + + ", current player count is: " + currentPlayerCount + + " when max player count is: " + maxPlayerCount + ); } - public MaxPlayerException(int numberOfPlayer, int currentPlayerCount, int maxPlayerCount) { - this(new StringBuilder() - .append("can not add ").append(numberOfPlayer).append(" new players") - .append(", current player count is: ").append(currentPlayerCount) - .append(" when max player count is: ").append(maxPlayerCount) - .toString()); + public MaxPlayerException( + int numberOfPlayer, + int currentPlayerCount, + int maxPlayerCount + ) { + this( + "can not add " + numberOfPlayer + " new players" + + ", current player count is: " + currentPlayerCount + + " when max player count is: " + maxPlayerCount + ); } - } diff --git a/src/main/java/com/tvd12/gamebox/exception/MaxRoomException.java b/src/main/java/com/tvd12/gamebox/exception/MaxRoomException.java index 0b49204..b24dcbd 100644 --- a/src/main/java/com/tvd12/gamebox/exception/MaxRoomException.java +++ b/src/main/java/com/tvd12/gamebox/exception/MaxRoomException.java @@ -7,20 +7,27 @@ public MaxRoomException(String msg) { super(msg); } - public MaxRoomException(String room, int currentRoomCount, int maxRoomCount) { - this(new StringBuilder() - .append("can not add new room: ").append(room) - .append(", current room count is: ").append(currentRoomCount) - .append(" when max room count is: ").append(maxRoomCount) - .toString()); + public MaxRoomException( + String room, + int currentRoomCount, + int maxRoomCount + ) { + this( + "can not add new room: " + room + + ", current room count is: " + currentRoomCount + + " when max room count is: " + maxRoomCount + ); } - public MaxRoomException(int numberOfRoom, int currentRoomCount, int maxRoomCount) { - this(new StringBuilder() - .append("can not add ").append(numberOfRoom).append(" new rooms") - .append(", current room count is: ").append(currentRoomCount) - .append(" when max room count is: ").append(maxRoomCount) - .toString()); + public MaxRoomException( + int numberOfRoom, + int currentRoomCount, + int maxRoomCount + ) { + this( + "can not add " + numberOfRoom + " new rooms" + + ", current room count is: " + currentRoomCount + + " when max room count is: " + maxRoomCount + ); } - } diff --git a/src/main/java/com/tvd12/gamebox/exception/NoSlotException.java b/src/main/java/com/tvd12/gamebox/exception/NoSlotException.java index a5106d0..de4a876 100644 --- a/src/main/java/com/tvd12/gamebox/exception/NoSlotException.java +++ b/src/main/java/com/tvd12/gamebox/exception/NoSlotException.java @@ -6,5 +6,4 @@ public class NoSlotException extends RuntimeException { public NoSlotException(String msg) { super(msg); } - } diff --git a/src/main/java/com/tvd12/gamebox/exception/PlayerExistsException.java b/src/main/java/com/tvd12/gamebox/exception/PlayerExistsException.java index eada872..6fa7ccf 100644 --- a/src/main/java/com/tvd12/gamebox/exception/PlayerExistsException.java +++ b/src/main/java/com/tvd12/gamebox/exception/PlayerExistsException.java @@ -6,5 +6,4 @@ public class PlayerExistsException extends IllegalArgumentException { public PlayerExistsException(String username) { super("player: " + username + " has added"); } - } diff --git a/src/main/java/com/tvd12/gamebox/exception/PlayerNotExistsException.java b/src/main/java/com/tvd12/gamebox/exception/PlayerNotExistsException.java index 39f4b5a..221cd4c 100644 --- a/src/main/java/com/tvd12/gamebox/exception/PlayerNotExistsException.java +++ b/src/main/java/com/tvd12/gamebox/exception/PlayerNotExistsException.java @@ -6,5 +6,4 @@ public class PlayerNotExistsException extends IllegalArgumentException { public PlayerNotExistsException(String message) { super(message); } - } diff --git a/src/main/java/com/tvd12/gamebox/exception/RoomExistsException.java b/src/main/java/com/tvd12/gamebox/exception/RoomExistsException.java index 6aaa9fe..10fa423 100644 --- a/src/main/java/com/tvd12/gamebox/exception/RoomExistsException.java +++ b/src/main/java/com/tvd12/gamebox/exception/RoomExistsException.java @@ -6,5 +6,4 @@ public class RoomExistsException extends IllegalArgumentException { public RoomExistsException(String roomName) { super("room: " + roomName + " has added"); } - } diff --git a/src/main/java/com/tvd12/gamebox/exception/RoomNotExistsException.java b/src/main/java/com/tvd12/gamebox/exception/RoomNotExistsException.java index 11f903c..f49eb9a 100644 --- a/src/main/java/com/tvd12/gamebox/exception/RoomNotExistsException.java +++ b/src/main/java/com/tvd12/gamebox/exception/RoomNotExistsException.java @@ -6,5 +6,4 @@ public class RoomNotExistsException extends IllegalArgumentException { public RoomNotExistsException(String message) { super(message); } - } diff --git a/src/main/java/com/tvd12/gamebox/handler/MMORoomUpdatedHandler.java b/src/main/java/com/tvd12/gamebox/handler/MMORoomUpdatedHandler.java index 9d303ef..333d2f5 100644 --- a/src/main/java/com/tvd12/gamebox/handler/MMORoomUpdatedHandler.java +++ b/src/main/java/com/tvd12/gamebox/handler/MMORoomUpdatedHandler.java @@ -5,7 +5,6 @@ import java.util.List; -@SuppressWarnings("AbbreviationAsWordInName") public interface MMORoomUpdatedHandler { void onRoomUpdated(MMORoom room, List players); diff --git a/src/main/java/com/tvd12/gamebox/manager/AbstractPlayerManager.java b/src/main/java/com/tvd12/gamebox/manager/AbstractPlayerManager.java index b49b088..9ba21fa 100644 --- a/src/main/java/com/tvd12/gamebox/manager/AbstractPlayerManager.java +++ b/src/main/java/com/tvd12/gamebox/manager/AbstractPlayerManager.java @@ -36,8 +36,7 @@ protected AbstractPlayerManager(Builder builder) { @Override public P getPlayer(String username) { - P player = playersByName.get(username); - return player; + return playersByName.get(username); } @Override @@ -75,8 +74,7 @@ public List getPlayerNames() { @Override public boolean containsPlayer(String username) { - boolean contains = playersByName.containsKey(username); - return contains; + return playersByName.containsKey(username); } @Override @@ -176,19 +174,20 @@ protected void removePlayers0(Collection

players) { @Override public int getPlayerCount() { - int count = playersByName.size(); - return count; + return playersByName.size(); } @Override public boolean available() { - boolean available = playersByName.size() < maxPlayer; - return available; + return playersByName.size() < maxPlayer; } @Override public Lock getLock(String username) { - return locks.computeIfAbsent(username, EzyFunctions.NEW_REENTRANT_LOCK_FUNC); + return locks.computeIfAbsent( + username, + EzyFunctions.NEW_REENTRANT_LOCK_FUNC + ); } @Override @@ -203,8 +202,11 @@ public boolean isEmpty() { @Override public int countPlayers(Predicate

tester) { - int count = (int) playersByName.values().stream().filter(tester).count(); - return count; + return (int) playersByName + .values() + .stream() + .filter(tester) + .count(); } @Override @@ -221,7 +223,7 @@ public void clear() { protected void unlockAll() { for (Lock lock : locks.values()) { - EzyProcessor.processSilently(() -> lock.unlock()); + EzyProcessor.processSilently(lock::unlock); } } @@ -254,10 +256,8 @@ public final PlayerManager build() { return newProduct(); } - protected void preBuild() { - } + protected void preBuild() {} protected abstract PlayerManager newProduct(); } - } diff --git a/src/main/java/com/tvd12/gamebox/manager/AbstractRoomManager.java b/src/main/java/com/tvd12/gamebox/manager/AbstractRoomManager.java index de11adf..73d6132 100644 --- a/src/main/java/com/tvd12/gamebox/manager/AbstractRoomManager.java +++ b/src/main/java/com/tvd12/gamebox/manager/AbstractRoomManager.java @@ -100,26 +100,22 @@ protected void addRooms0(Iterable rooms, boolean failIfAdded) { @Override public boolean containsRoom(long id) { - boolean contains = roomsById.containsKey(id); - return contains; + return roomsById.containsKey(id); } @Override public boolean containsRoom(String name) { - boolean contains = roomsByName.containsKey(name); - return contains; + return roomsByName.containsKey(name); } @Override public R getRoom(long id) { - R room = roomsById.get(id); - return room; + return roomsById.get(id); } @Override public R getRoom(String name) { - R room = roomsByName.get(name); - return room; + return roomsByName.get(name); } @Override @@ -134,7 +130,7 @@ public R getRoom(Predicate predicate) { @Override public List getRoomList() { - return new ArrayList(roomsByName.values()); + return new ArrayList<>(roomsByName.values()); } @Override @@ -153,8 +149,7 @@ public void getRoomList(List buffer) { @Override public int getRoomCount() { - int count = roomsByName.size(); - return count; + return roomsByName.size(); } @Override @@ -210,8 +205,7 @@ protected void removeRoom1(R room) { @Override public boolean available() { - boolean answer = roomsById.size() < maxRoom; - return answer; + return roomsById.size() < maxRoom; } public void clear() { diff --git a/src/main/java/com/tvd12/gamebox/manager/DefaultLocatedPlayerManager.java b/src/main/java/com/tvd12/gamebox/manager/DefaultLocatedPlayerManager.java index 73d318a..722b7cd 100644 --- a/src/main/java/com/tvd12/gamebox/manager/DefaultLocatedPlayerManager.java +++ b/src/main/java/com/tvd12/gamebox/manager/DefaultLocatedPlayerManager.java @@ -17,7 +17,8 @@ public class DefaultLocatedPlayerManager extends EzyLoggable implements LocatedPlayerManager { - protected final Map playersByName = newPlayersByNameMap(); + protected final Map playersByName + = newPlayersByNameMap(); protected final NavigableMap playersByLocation = newPlayersByLocationsMap(); @Getter @@ -29,8 +30,7 @@ public class DefaultLocatedPlayerManager @Override public LocatedPlayer getPlayer(int location) { - LocatedPlayer player = playersByLocation.get(location); - return player; + return playersByLocation.get(location); } @Override @@ -206,12 +206,10 @@ protected NavigableMap newPlayersByLocationsMap() { @Override public String toString() { - return new StringBuilder() - .append("(") - .append("master: ").append(master).append(", ") - .append("speakinger: ").append(speakinger).append(", ") - .append("playersByLocation: ").append(playersByLocation) - .append(")") - .toString(); + return "(" + + "master: " + master + ", " + + "speakinger: " + speakinger + ", " + + "playersByLocation: " + playersByLocation + + ")"; } } diff --git a/src/main/java/com/tvd12/gamebox/manager/DefaultPlayerManager.java b/src/main/java/com/tvd12/gamebox/manager/DefaultPlayerManager.java index 7813a81..4b3ac36 100644 --- a/src/main/java/com/tvd12/gamebox/manager/DefaultPlayerManager.java +++ b/src/main/java/com/tvd12/gamebox/manager/DefaultPlayerManager.java @@ -28,5 +28,4 @@ protected PlayerManager newProduct() { return new DefaultPlayerManager<>(this); } } - } diff --git a/src/main/java/com/tvd12/gamebox/manager/DefaultRoomManager.java b/src/main/java/com/tvd12/gamebox/manager/DefaultRoomManager.java index 7290259..55b4ce9 100644 --- a/src/main/java/com/tvd12/gamebox/manager/DefaultRoomManager.java +++ b/src/main/java/com/tvd12/gamebox/manager/DefaultRoomManager.java @@ -27,7 +27,5 @@ public static class Builder> public DefaultRoomManager build() { return new DefaultRoomManager<>(this); } - } - } diff --git a/src/main/java/com/tvd12/gamebox/manager/LocatedPlayerManager.java b/src/main/java/com/tvd12/gamebox/manager/LocatedPlayerManager.java index 390346c..c7eec25 100644 --- a/src/main/java/com/tvd12/gamebox/manager/LocatedPlayerManager.java +++ b/src/main/java/com/tvd12/gamebox/manager/LocatedPlayerManager.java @@ -27,19 +27,19 @@ public interface LocatedPlayerManager { LocatedPlayer nextOf(LocatedPlayer player, Predicate condition); default LocatedPlayer nextOf(LocatedPlayer player) { - return nextOf(player, EzyPredicates.alwayTrue()); + return nextOf(player, EzyPredicates.alwaysTrue()); } LocatedPlayer rightOf(LocatedPlayer player, Predicate condition); default LocatedPlayer rightOf(LocatedPlayer player) { - return rightOf(player, EzyPredicates.alwayTrue()); + return rightOf(player, EzyPredicates.alwaysTrue()); } LocatedPlayer leftOf(LocatedPlayer player, Predicate condition); default LocatedPlayer leftOf(LocatedPlayer player) { - return leftOf(player, EzyPredicates.alwayTrue()); + return leftOf(player, EzyPredicates.alwaysTrue()); } List getPlayerNames(); diff --git a/src/main/java/com/tvd12/gamebox/manager/PlayerManager.java b/src/main/java/com/tvd12/gamebox/manager/PlayerManager.java index e4994fb..3a89af4 100644 --- a/src/main/java/com/tvd12/gamebox/manager/PlayerManager.java +++ b/src/main/java/com/tvd12/gamebox/manager/PlayerManager.java @@ -204,5 +204,5 @@ default P removePlayer(String username) { * * @return empty or not */ - public boolean isEmpty(); + boolean isEmpty(); } diff --git a/src/main/java/com/tvd12/gamebox/manager/SimplePlayerManager.java b/src/main/java/com/tvd12/gamebox/manager/SimplePlayerManager.java index 01d930e..aca72e0 100644 --- a/src/main/java/com/tvd12/gamebox/manager/SimplePlayerManager.java +++ b/src/main/java/com/tvd12/gamebox/manager/SimplePlayerManager.java @@ -36,5 +36,4 @@ protected PlayerManager newProduct() { return new SimplePlayerManager<>(this); } } - } diff --git a/src/main/java/com/tvd12/gamebox/manager/SimpleRoomManager.java b/src/main/java/com/tvd12/gamebox/manager/SimpleRoomManager.java index d805711..799a698 100644 --- a/src/main/java/com/tvd12/gamebox/manager/SimpleRoomManager.java +++ b/src/main/java/com/tvd12/gamebox/manager/SimpleRoomManager.java @@ -40,7 +40,5 @@ public static class Builder> public SimpleRoomManager build() { return new SimpleRoomManager<>(this); } - } - } diff --git a/src/main/java/com/tvd12/gamebox/manager/SynchronizedPlayerManager.java b/src/main/java/com/tvd12/gamebox/manager/SynchronizedPlayerManager.java index b27ec83..5847834 100644 --- a/src/main/java/com/tvd12/gamebox/manager/SynchronizedPlayerManager.java +++ b/src/main/java/com/tvd12/gamebox/manager/SynchronizedPlayerManager.java @@ -201,5 +201,4 @@ protected PlayerManager newProduct() { return new SynchronizedPlayerManager<>(this); } } - } diff --git a/src/main/java/com/tvd12/gamebox/manager/SynchronizedRoomManager.java b/src/main/java/com/tvd12/gamebox/manager/SynchronizedRoomManager.java index d835b93..d1326c9 100644 --- a/src/main/java/com/tvd12/gamebox/manager/SynchronizedRoomManager.java +++ b/src/main/java/com/tvd12/gamebox/manager/SynchronizedRoomManager.java @@ -189,6 +189,5 @@ public static class Builder> public RoomManager build() { return new SynchronizedRoomManager<>(this); } - } } diff --git a/src/main/java/com/tvd12/gamebox/math/Numbers.java b/src/main/java/com/tvd12/gamebox/math/Numbers.java index 6a4ea92..9c94382 100644 --- a/src/main/java/com/tvd12/gamebox/math/Numbers.java +++ b/src/main/java/com/tvd12/gamebox/math/Numbers.java @@ -32,8 +32,7 @@ public final class Numbers { */ private static final int NEGATIVE_ZERO_FLOAT_BITS = Float.floatToRawIntBits(-0.0f); - private Numbers() { - } + private Numbers() {} /** * Returns true if they are equal as defined by diff --git a/src/main/java/com/tvd12/gamebox/math/Rect.java b/src/main/java/com/tvd12/gamebox/math/Rect.java index d435d0c..5a6b84f 100644 --- a/src/main/java/com/tvd12/gamebox/math/Rect.java +++ b/src/main/java/com/tvd12/gamebox/math/Rect.java @@ -8,8 +8,7 @@ public class Rect { public float width; public float height; - public Rect() { - } + public Rect() {} public Rect(Rect r) { this.x = r.x; @@ -162,15 +161,6 @@ public Rect unionWithRect(Rect rect) { @Override public String toString() { - return new StringBuilder().append("(") - .append(x) - .append(", ") - .append(y) - .append(" | ") - .append(width) - .append(", ") - .append(height) - .append(")") - .toString(); + return "(" + x + ", " + y + " | " + width + ", " + height + ")"; } } diff --git a/src/main/java/com/tvd12/gamebox/math/Vec2.java b/src/main/java/com/tvd12/gamebox/math/Vec2.java index 4a9328b..d1b642a 100644 --- a/src/main/java/com/tvd12/gamebox/math/Vec2.java +++ b/src/main/java/com/tvd12/gamebox/math/Vec2.java @@ -8,13 +8,14 @@ @SuppressWarnings("MemberName") public class Vec2 { + public float x; + public float y; + public static final Vec2 ZERO = new Vec2(); public static final Vec2 LEFT = new Vec2(-1, 0); public static final Vec2 UP = new Vec2(0, 1); public static final Vec2 RIGHT = new Vec2(1, 0); public static final Vec2 DOWN = new Vec2(0, -1); - public float x; - public float y; public Vec2() { this(0.0F, 0.0F); @@ -103,6 +104,7 @@ public float distanceSquare(Vec2 v) { @Override public boolean equals(Object obj) { Vec2 other = (Vec2) obj; + //noinspection SuspiciousNameCombination return Numbers.equals(x, other.x) && Numbers.equals(y, other.y); } @@ -124,11 +126,6 @@ public EzyArray toArray() { @Override public String toString() { - return new StringBuilder() - .append("(") - .append(x).append(", ") - .append(y) - .append(")") - .toString(); + return "(" + x + ", " + y + ")"; } } diff --git a/src/main/java/com/tvd12/gamebox/math/Vec3.java b/src/main/java/com/tvd12/gamebox/math/Vec3.java index 668ee5a..c0961d7 100644 --- a/src/main/java/com/tvd12/gamebox/math/Vec3.java +++ b/src/main/java/com/tvd12/gamebox/math/Vec3.java @@ -7,6 +7,11 @@ @Getter @SuppressWarnings("MemberName") public class Vec3 { + + public float x; + public float y; + public float z; + public static final Vec3 ZERO = new Vec3(); public static final Vec3 up = new Vec3(0.0f, 1f, 0.0f); public static final Vec3 down = new Vec3(0.0f, -1f, 0.0f); @@ -14,9 +19,6 @@ public class Vec3 { public static final Vec3 right = new Vec3(1f, 0.0f, 0.0f); public static final Vec3 forward = new Vec3(0.0f, 0.0f, 1f); public static final Vec3 backward = new Vec3(0.0f, 0.0f, -1f); - public float x; - public float y; - public float z; public Vec3() { this(0.0f, 0.0f, 0.0f); @@ -105,6 +107,7 @@ public float distanceSquare(Vec3 v) { @Override public boolean equals(Object obj) { Vec3 other = (Vec3) obj; + //noinspection SuspiciousNameCombination return Numbers.equals(x, other.x) && Numbers.equals(y, other.y) && Numbers.equals(z, other.z); @@ -128,12 +131,6 @@ public EzyArray toArray() { @Override public String toString() { - return new StringBuilder() - .append("(") - .append(x).append(", ") - .append(y).append(", ") - .append(z) - .append(")") - .toString(); + return "(" + x + ", " + y + ", " + z + ")"; } } diff --git a/src/test/java/com/tvd12/gamebox/entity/MMOIntergrationTest.java b/src/test/java/com/tvd12/gamebox/entity/MMOIntegrationTest.java similarity index 95% rename from src/test/java/com/tvd12/gamebox/entity/MMOIntergrationTest.java rename to src/test/java/com/tvd12/gamebox/entity/MMOIntegrationTest.java index 85f32f9..2fa6b87 100644 --- a/src/test/java/com/tvd12/gamebox/entity/MMOIntergrationTest.java +++ b/src/test/java/com/tvd12/gamebox/entity/MMOIntegrationTest.java @@ -14,7 +14,7 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicInteger; -public class MMOIntergrationTest { +public class MMOIntegrationTest { private final MMOVirtualWorld world; private final ExecutorService executorService; @@ -24,7 +24,7 @@ public class MMOIntergrationTest { private final AtomicInteger totalPlayers; private final RoomManager roomManager; - public MMOIntergrationTest() { + public MMOIntegrationTest() { this.world = MMOVirtualWorld.builder() .maxRoomCount(1000) .roomGroupCount(16) @@ -39,18 +39,19 @@ public MMOIntergrationTest() { } public static void main(String[] args) throws Exception { - new MMOIntergrationTest().test(); + new MMOIntegrationTest().test(); } public void test() throws Exception { long testTime = 5 * 60 * 1000; long startTime = System.currentTimeMillis(); - long endtime = startTime + testTime; + long endTime = startTime + testTime; while (true) { long currentTime = System.currentTimeMillis(); - if (currentTime > endtime) { + if (currentTime > endTime) { break; } + //noinspection BusyWait Thread.sleep(300); addPlayers(); addPlayerToRooms(); diff --git a/src/test/java/com/tvd12/gamebox/entity/MMORoomTest.java b/src/test/java/com/tvd12/gamebox/entity/MMORoomTest.java index 2513c9f..683ff04 100644 --- a/src/test/java/com/tvd12/gamebox/entity/MMORoomTest.java +++ b/src/test/java/com/tvd12/gamebox/entity/MMORoomTest.java @@ -7,6 +7,7 @@ import org.testng.annotations.Test; import java.util.Arrays; +import java.util.Collections; public class MMORoomTest { @@ -54,13 +55,29 @@ public void test() { Asserts.assertEmpty(player1.getNearbyPlayerNames()); Asserts.assertEmpty(player2.getNearbyPlayerNames()); sut.update(); - Asserts.assertEquals(player1.getNearbyPlayerNames(), Arrays.asList(player1.getName()), false); - Asserts.assertEquals(player2.getNearbyPlayerNames(), Arrays.asList(player2.getName()), false); + Asserts.assertEquals( + player1.getNearbyPlayerNames(), + Collections.singletonList(player1.getName()), + false + ); + Asserts.assertEquals( + player2.getNearbyPlayerNames(), + Collections.singletonList(player2.getName()), + false + ); player2.setPosition(new Vec3(1, 1, 1)); sut.update(); - Asserts.assertEquals(player1.getNearbyPlayerNames(), Arrays.asList(player1.getName(), player2.getName()), false); - Asserts.assertEquals(player2.getNearbyPlayerNames(), Arrays.asList(player1.getName(), player2.getName()), false); + Asserts.assertEquals( + player1.getNearbyPlayerNames(), + Arrays.asList(player1.getName(), player2.getName()), + false + ); + Asserts.assertEquals( + player2.getNearbyPlayerNames(), + Arrays.asList(player1.getName(), player2.getName()), + false + ); } @Test @@ -70,7 +87,7 @@ public void buildFailedDueToDistanceOfInterest() { .playerManager(new SynchronizedPlayerManager<>()); // when - Throwable e = Asserts.assertThrows(() -> builder.build()); + Throwable e = Asserts.assertThrows(builder::build); // then Asserts.assertEqualsType(e, IllegalArgumentException.class); diff --git a/src/test/java/com/tvd12/gamebox/entity/PlayerTest.java b/src/test/java/com/tvd12/gamebox/entity/PlayerTest.java index e2a1189..f2a605e 100644 --- a/src/test/java/com/tvd12/gamebox/entity/PlayerTest.java +++ b/src/test/java/com/tvd12/gamebox/entity/PlayerTest.java @@ -24,7 +24,9 @@ public void test() { Asserts.assertEquals(sut.getRole(), PlayerRole.MASTER); Asserts.assertEquals(sut.getStatus(), PlayerStatus.PLAYING); Asserts.assertEquals(sut.getCurrentRoomId(), 1L); + //noinspection EqualsWithItself Asserts.assertTrue(sut.equals(sut)); + //noinspection ConstantConditions Asserts.assertFalse(sut.equals(null)); Player me = Player.builder() diff --git a/src/test/java/com/tvd12/gamebox/entity/RoomTest.java b/src/test/java/com/tvd12/gamebox/entity/RoomTest.java index 0e269a8..dfdb5f3 100644 --- a/src/test/java/com/tvd12/gamebox/entity/RoomTest.java +++ b/src/test/java/com/tvd12/gamebox/entity/RoomTest.java @@ -21,7 +21,9 @@ public void test() { // then Asserts.assertEquals(sut.getPassword(), "123456"); Asserts.assertEquals(sut.getStatus(), RoomStatus.FINISHED); + //noinspection EqualsWithItself Asserts.assertTrue(sut.equals(sut)); + //noinspection ConstantConditions Asserts.assertFalse(sut.equals(null)); Room me = Room.builder() diff --git a/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager1Test.java b/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager1Test.java index 6e061f1..674d5ec 100644 --- a/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager1Test.java +++ b/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager1Test.java @@ -40,7 +40,5 @@ public void justOne() { System.out.println(manager); Asserts.assertEquals(manager.nextOf(a), null); - } - } diff --git a/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager2Test.java b/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager2Test.java index 1d5f5e7..cc83b22 100644 --- a/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager2Test.java +++ b/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager2Test.java @@ -19,7 +19,5 @@ public void test() { manager.setNewMaster(); System.out.println(manager); - } - } diff --git a/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager3Test.java b/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager3Test.java index 85a68c9..7f3131b 100644 --- a/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager3Test.java +++ b/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager3Test.java @@ -33,7 +33,5 @@ public void test() { System.out.println(manager.nextOf(binh4, p -> p != huongntm2 && p != havm)); System.out.println(manager.nextOf(binh5, p -> p != huongntm2 && p != havm)); System.out.println(manager.nextOf(huongntm3, p -> p != huongntm2 && p != havm)); - } - } diff --git a/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager4Test.java b/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager4Test.java index 430b406..74e8b88 100644 --- a/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager4Test.java +++ b/src/test/java/com/tvd12/gamebox/testing/DefaultLocatedPlayerManager4Test.java @@ -41,5 +41,4 @@ public void test() { Asserts.assertEquals(manager.rightOf(huongntm3, p -> p != huongntm2 && p != havm), binh4); Asserts.assertEquals(manager.rightOf(binh4, p -> p != binh5 && p != havm), huongntm3); } - } diff --git a/src/test/java/com/tvd12/gamebox/testing/IteratorTest.java b/src/test/java/com/tvd12/gamebox/testing/IteratorTest.java index 1efee15..302f6f8 100644 --- a/src/test/java/com/tvd12/gamebox/testing/IteratorTest.java +++ b/src/test/java/com/tvd12/gamebox/testing/IteratorTest.java @@ -7,5 +7,4 @@ public class IteratorTest { public static void main(String[] args) { System.out.println(Lists.newArrayList(1, 2, 3).iterator()); } - } diff --git a/src/test/java/com/tvd12/gamebox/testing/LocatedRoomTest.java b/src/test/java/com/tvd12/gamebox/testing/LocatedRoomTest.java index cc5a08c..d4efb57 100644 --- a/src/test/java/com/tvd12/gamebox/testing/LocatedRoomTest.java +++ b/src/test/java/com/tvd12/gamebox/testing/LocatedRoomTest.java @@ -25,5 +25,4 @@ public void masterTest() { System.out.println("\n\nnext master is: " + room.getPlayerManager().setNewMaster() + "\n\n"); } - } diff --git a/src/test/java/com/tvd12/gamebox/testing/MMORoomTest.java b/src/test/java/com/tvd12/gamebox/testing/MMORoomTest.java index 41810ef..a12ec66 100644 --- a/src/test/java/com/tvd12/gamebox/testing/MMORoomTest.java +++ b/src/test/java/com/tvd12/gamebox/testing/MMORoomTest.java @@ -120,9 +120,8 @@ public void maxPlayerTest() { Asserts.assertEquals(MaxPlayerException.class.toString(), e.getClass().toString()); } - public class A implements MMORoomUpdatedHandler { + public static class A implements MMORoomUpdatedHandler { @Override - public void onRoomUpdated(MMORoom room, List players) { - } + public void onRoomUpdated(MMORoom room, List players) {} } } diff --git a/src/test/java/com/tvd12/gamebox/testing/SyncPositionRoomUpdatedHandlerTest.java b/src/test/java/com/tvd12/gamebox/testing/SyncPositionRoomUpdatedHandlerTest.java index cb6d8cc..8e91376 100644 --- a/src/test/java/com/tvd12/gamebox/testing/SyncPositionRoomUpdatedHandlerTest.java +++ b/src/test/java/com/tvd12/gamebox/testing/SyncPositionRoomUpdatedHandlerTest.java @@ -85,5 +85,4 @@ public void casePlayerChangeStateTest() { verify(arrayResponse, times(1)).usernames(nearbyPlayerNameList); verify(arrayResponse, times(1)).execute(); } - } diff --git a/src/test/java/com/tvd12/gamebox/testing/TestHelper.java b/src/test/java/com/tvd12/gamebox/testing/TestHelper.java index 2112d53..eccd3b7 100644 --- a/src/test/java/com/tvd12/gamebox/testing/TestHelper.java +++ b/src/test/java/com/tvd12/gamebox/testing/TestHelper.java @@ -5,8 +5,7 @@ public class TestHelper { - private TestHelper() { - } + private TestHelper() {} public static Vec3 randomVec3() { return new Vec3( diff --git a/src/test/java/com/tvd12/gamebox/testing/manager/AbstractRoomManagerTest.java b/src/test/java/com/tvd12/gamebox/testing/manager/AbstractRoomManagerTest.java index f117423..3e5d5ff 100644 --- a/src/test/java/com/tvd12/gamebox/testing/manager/AbstractRoomManagerTest.java +++ b/src/test/java/com/tvd12/gamebox/testing/manager/AbstractRoomManagerTest.java @@ -17,6 +17,5 @@ public void test() { Asserts.assertEquals(sut.getMaxRoom(), 10000); } - private static class InternalRoomManager extends AbstractRoomManager { - } + private static class InternalRoomManager extends AbstractRoomManager {} } diff --git a/src/test/java/com/tvd12/gamebox/testing/manager/DefaultRoomManagerTest.java b/src/test/java/com/tvd12/gamebox/testing/manager/DefaultRoomManagerTest.java index 2adf25a..34e32c2 100644 --- a/src/test/java/com/tvd12/gamebox/testing/manager/DefaultRoomManagerTest.java +++ b/src/test/java/com/tvd12/gamebox/testing/manager/DefaultRoomManagerTest.java @@ -6,7 +6,7 @@ import com.tvd12.test.assertion.Asserts; import org.testng.annotations.Test; -import java.util.Arrays; +import java.util.Collections; public class DefaultRoomManagerTest { @@ -29,7 +29,7 @@ public void test() { // when sut.addRooms(new Room[]{room1}); - sut.addRooms(Arrays.asList(room2)); + sut.addRooms(Collections.singletonList(room2)); // then Asserts.assertEquals(sut.getMaxRoom(), 100); diff --git a/src/test/java/com/tvd12/gamebox/testing/manager/SynchronizedPlayerManagerTest.java b/src/test/java/com/tvd12/gamebox/testing/manager/SynchronizedPlayerManagerTest.java index da3eaea..219db96 100644 --- a/src/test/java/com/tvd12/gamebox/testing/manager/SynchronizedPlayerManagerTest.java +++ b/src/test/java/com/tvd12/gamebox/testing/manager/SynchronizedPlayerManagerTest.java @@ -8,6 +8,7 @@ import org.testng.annotations.Test; import java.util.Arrays; +import java.util.Collections; import java.util.concurrent.locks.Lock; public class SynchronizedPlayerManagerTest { @@ -42,9 +43,17 @@ public void test() { Asserts.assertNull(sut.getPlayer("unknown")); Asserts.assertEquals(sut.getPlayer("test", () -> null), player1); Asserts.assertEquals(sut.getFirstPlayer(), player1); - Asserts.assertEquals(sut.getPlayerList(it -> true), Arrays.asList(player1), false); + Asserts.assertEquals( + sut.getPlayerList(it -> true), + Collections.singletonList(player1), + false + ); Asserts.assertEmpty(sut.getPlayerList(it -> it.getName().equals("unknown"))); - Asserts.assertEquals(sut.getPlayerNames(), Arrays.asList("test"), false); + Asserts.assertEquals( + sut.getPlayerNames(), + Collections.singletonList("test"), + false + ); Asserts.assertEquals(sut.removePlayer(player1), player1); sut.addPlayer(player1, true); @@ -60,23 +69,29 @@ public void test() { Asserts.assertNotNull(sut.getLock("test")); sut.removeLock("test"); - sut.removePlayers(Arrays.asList(player1)); + sut.removePlayers(Collections.singletonList(player1)); Asserts.assertEquals(sut.getPlayerCount(), 1); sut.clear(); Asserts.assertNull(sut.getFirstPlayer()); Asserts.assertEquals(sut.getPlayer("unknown", () -> playerx), playerx); sut.clear(); - sut.addPlayers(Arrays.asList(player1), false); + sut.addPlayers(Collections.singletonList(player1), false); Asserts.assertEquals(sut.getPlayerCount(), 1); - sut.addPlayers(Arrays.asList(player1), false); - Throwable e3 = Asserts.assertThrows(() -> sut.addPlayers(Arrays.asList(player1), true)); + sut.addPlayers(Collections.singletonList(player1), false); + Throwable e3 = Asserts.assertThrows( + () -> sut.addPlayers(Collections.singletonList(player1), true) + ); Asserts.assertEqualsType(e3, PlayerExistsException.class); Throwable e4 = Asserts.assertThrows(() -> sut.addPlayers(Arrays.asList(player2, playerx), false)); Asserts.assertEqualsType(e4, MaxPlayerException.class); Asserts.assertEquals(sut.countPlayers(it -> it.getName().equals("test")), 1); - Asserts.assertEquals(sut.filterPlayers(it -> it.getName().equals("test")), Arrays.asList(player1), false); + Asserts.assertEquals( + sut.filterPlayers(it -> it.getName().equals("test")), + Collections.singletonList(player1), + false + ); Lock lock = sut.getLock("test"); lock.lock(); diff --git a/src/test/java/com/tvd12/gamebox/testing/manager/SynchronizedRoomManagerTest.java b/src/test/java/com/tvd12/gamebox/testing/manager/SynchronizedRoomManagerTest.java index 5877ae7..70df52b 100644 --- a/src/test/java/com/tvd12/gamebox/testing/manager/SynchronizedRoomManagerTest.java +++ b/src/test/java/com/tvd12/gamebox/testing/manager/SynchronizedRoomManagerTest.java @@ -8,6 +8,7 @@ import org.testng.annotations.Test; import java.util.Arrays; +import java.util.Collections; public class SynchronizedRoomManagerTest { @@ -44,11 +45,15 @@ public void test() { Asserts.assertEqualsType(e2, MaxRoomException.class); sut.clear(); - sut.addRooms(Arrays.asList(room1), false); - Throwable e3 = Asserts.assertThrows(() -> sut.addRooms(Arrays.asList(room1), true)); + sut.addRooms(Collections.singletonList(room1), false); + Throwable e3 = Asserts.assertThrows( + () -> sut.addRooms(Collections.singletonList(room1), true) + ); Asserts.assertEqualsType(e3, RoomExistsException.class); - sut.addRooms(Arrays.asList(room2), true); - Throwable e4 = Asserts.assertThrows(() -> sut.addRooms(Arrays.asList(roomx), true)); + sut.addRooms(Collections.singletonList(room2), true); + Throwable e4 = Asserts.assertThrows( + () -> sut.addRooms(Collections.singletonList(roomx), true) + ); Asserts.assertEqualsType(e4, MaxRoomException.class); Asserts.assertEquals(sut.getRoom("room1"), room1); @@ -73,7 +78,11 @@ public void test() { Asserts.assertEquals(sut.getRoom(it -> it.getName().equals("room1")), room1); Asserts.assertNull(sut.getRoom(it -> it.getName().equals("unknown"))); - Asserts.assertEquals(sut.getRoomList(it -> it.getName().equals("room1")), Arrays.asList(room1), false); + Asserts.assertEquals( + sut.getRoomList(it -> it.getName().equals("room1")), + Collections.singletonList(room1), + false + ); sut.clear(); sut.addRooms(new LocatedRoom[]{room1}, false); diff --git a/src/test/java/com/tvd12/gamebox/testing/math/NumbersTest.java b/src/test/java/com/tvd12/gamebox/testing/math/NumbersTest.java index d366134..34fe3fd 100644 --- a/src/test/java/com/tvd12/gamebox/testing/math/NumbersTest.java +++ b/src/test/java/com/tvd12/gamebox/testing/math/NumbersTest.java @@ -28,7 +28,9 @@ public void test() { Asserts.assertTrue(Numbers.equals(-2147483648.0F, Float.MIN_VALUE, 1325400065)); + //noinspection divzero Asserts.assertFalse(Numbers.equals(0.0F / 0.0F, 1.0F, 1)); + //noinspection divzero Asserts.assertFalse(Numbers.equals(1.0F, 0.0F / 0.0F, 1)); } }