replaced enum comparison from equals to ==

This commit is contained in:
igoudt 2017-01-11 09:53:16 +01:00
parent 1c4bf298eb
commit ac8962cb29
31 changed files with 264 additions and 318 deletions

View file

@ -35,6 +35,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.server.util.SystemUtil;
@ -44,7 +45,6 @@ import mage.view.ChatMessage.SoundToPlay;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ChatManager {
@ -116,9 +116,9 @@ public class ChatManager {
}
return false;
}
final Pattern cardNamePattern = Pattern.compile("\\[(.*?)\\]");
public void broadcast(UUID chatId, String userName, String message, MessageColor color, boolean withTime, MessageType messageType, SoundToPlay soundToPlay) {
ChatSession chatSession = chatSessions.get(chatId);
if (chatSession != null) {
@ -132,7 +132,7 @@ public class ChatManager {
}
}
if (!messageType.equals(MessageType.GAME)) {
if (messageType != MessageType.GAME) {
User user = UserManager.getInstance().getUserByName(userName);
if (message != null && userName != null && !userName.equals("")) {
@ -177,7 +177,7 @@ public class ChatManager {
}
}
if (messageType.equals(MessageType.TALK)) {
if (messageType == MessageType.TALK) {
if (user != null) {
if (user.getChatLockedUntil() != null) {
if (user.getChatLockedUntil().compareTo(Calendar.getInstance().getTime()) > 0) {
@ -249,7 +249,6 @@ public class ChatManager {
}
/**
*
* use mainly for announcing that a user connection was lost or that a user
* has reconnected
*

View file

@ -27,12 +27,6 @@
*/
package mage.server;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.interfaces.callback.ClientCallback;
import mage.view.ChatMessage;
import mage.view.ChatMessage.MessageColor;
@ -40,8 +34,14 @@ import mage.view.ChatMessage.MessageType;
import mage.view.ChatMessage.SoundToPlay;
import org.apache.log4j.Logger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ChatSession {
@ -79,7 +79,7 @@ public class ChatSession {
}
if (userId != null && clients.containsKey(userId)) {
String userName = clients.get(userId);
if (!reason.equals(DisconnectReason.LostConnection)) { // for lost connection the user will be reconnected or session expire so no remove of chat yet
if (reason != DisconnectReason.LostConnection) { // for lost connection the user will be reconnected or session expire so no remove of chat yet
clients.remove(userId);
logger.debug(userName + "(" + reason.toString() + ")" + " removed from chatId " + chatId);
}

View file

@ -580,7 +580,7 @@ public class MageServerImpl implements MageServer {
@Override
public boolean leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
TableState tableState = TableManager.getInstance().getController(tableId).getTableState();
if (!tableState.equals(TableState.WAITING) && !tableState.equals(TableState.READY_TO_START)) {
if (tableState!=TableState.WAITING && tableState!=TableState.READY_TO_START) {
// table was already started, so player can't leave anymore now
return false;
}

View file

@ -30,13 +30,13 @@ package mage.server;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import mage.MageException;
import mage.players.net.UserData;
import org.apache.log4j.Logger;
import org.jboss.remoting.callback.InvokerCallbackHandler;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class SessionManager {
@ -47,6 +47,7 @@ public class SessionManager {
public static SessionManager getInstance() {
return INSTANCE;
}
private final ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<>();
public Session getSession(String sessionId) {
@ -127,7 +128,7 @@ public class SessionManager {
public void disconnect(String sessionId, DisconnectReason reason) {
Session session = sessions.get(sessionId);
if (session != null) {
if (!reason.equals(DisconnectReason.AdminDisconnect)) {
if (reason != DisconnectReason.AdminDisconnect) {
if (!sessions.containsKey(sessionId)) {
// session was removed meanwhile by another thread so we can return
return;

View file

@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import mage.MageException;
import mage.cards.decks.Deck;
import mage.cards.decks.DeckCardLists;
@ -72,7 +73,6 @@ import mage.view.ChatMessage;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TableController {
@ -294,14 +294,14 @@ public class TableController {
user.showUserMessage("Join Table", message);
return false;
}
// Check power level for table (currently only used for EDH/Commander table)
int edhPowerLevel = table.getMatch().getOptions().getEdhPowerLevel();
if (edhPowerLevel > 0 && table.getValidator().getName().toLowerCase().equals("commander")) {
int deckEdhPowerLevel = table.getValidator().getEdhPowerLevel(deck);
if (deckEdhPowerLevel > edhPowerLevel) {
String message = new StringBuilder("Your deck appears to be too powerful for this table.\n\nReduce the number of extra turn cards, infect, counters, fogs, reconsider your commander. ")
.append("\nThe table requirement has a maximum power level of ").append(edhPowerLevel).append (" whilst your deck has a calculated power level of ")
.append("\nThe table requirement has a maximum power level of ").append(edhPowerLevel).append(" whilst your deck has a calculated power level of ")
.append(deckEdhPowerLevel).toString();
user.showUserMessage("Join Table", message);
return false;
@ -412,7 +412,7 @@ public class TableController {
} else {
logger.fatal("Tournament == null table: " + table.getId() + " userId: " + userId);
}
} else if (TableState.SIDEBOARDING.equals(table.getState())) {
} else if (TableState.SIDEBOARDING == table.getState()) {
match.updateDeck(playerId, deck);
} else {
// deck was meanwhile submitted so the autoupdate can be ignored
@ -438,7 +438,7 @@ public class TableController {
}
}
// public boolean replayTable(UUID userId) {
// public boolean replayTable(UUID userId) {
// if (table.getState() != TableState.FINISHED) {
// return false;
// }
@ -476,8 +476,8 @@ public class TableController {
}
if (table != null
&& this.userId != null && this.userId.equals(userId) // tourn. sub tables have no creator user
&& (table.getState().equals(TableState.WAITING)
|| table.getState().equals(TableState.READY_TO_START))) {
&& (table.getState() == TableState.WAITING
|| table.getState() == TableState.READY_TO_START)) {
// table not started yet and user is the owner, remove the table
TableManager.getInstance().removeTable(table.getId());
} else {
@ -500,7 +500,7 @@ public class TableController {
logger.debug("User not found - userId: " + userId + " tableId:" + table.getId());
}
userPlayerMap.remove(userId);
} else if (!table.getState().equals(TableState.FINISHED)) {
} else if (table.getState() != TableState.FINISHED) {
if (table.isTournament()) {
logger.debug("Quit tournament sub tables for userId: " + userId);
TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId);
@ -517,7 +517,7 @@ public class TableController {
}
match.quitMatch(playerId);
} else {
if (table.getState().equals(TableState.SIDEBOARDING)) {
if (table.getState() == TableState.SIDEBOARDING) {
if (!matchPlayer.isDoneSideboarding()) {
// submit deck to finish sideboarding and trigger match start / end
matchPlayer.submitDeck(matchPlayer.getDeck());
@ -546,7 +546,7 @@ public class TableController {
}
public synchronized void startMatch() {
if (table.getState().equals(TableState.STARTING)) {
if (table.getState() == TableState.STARTING) {
try {
if (table.isTournamentSubTable()) {
logger.info("Tourn. match started id:" + match.getId() + " tournId: " + table.getTournament().getId());
@ -630,7 +630,7 @@ public class TableController {
public synchronized void startTournament(UUID userId) {
try {
if (userId.equals(this.userId) && table.getState().equals(TableState.STARTING)) {
if (userId.equals(this.userId) && table.getState() == TableState.STARTING) {
tournament.setStartTime();
TournamentManager.getInstance().createTournamentSession(tournament, userPlayerMap, table.getId());
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
@ -762,7 +762,6 @@ public class TableController {
/**
* Tables of normal matches or tournament sub tables are no longer needed,
* if the match ends.
*
*/
private void closeTable() {
this.matchEnd();
@ -778,7 +777,7 @@ public class TableController {
if (!matchPlayer.hasQuit()) {
User user = UserManager.getInstance().getUser(entry.getKey());
if (user != null) {
if (table.getState().equals(TableState.SIDEBOARDING)) {
if (table.getState()==TableState.SIDEBOARDING) {
StringBuilder sb = new StringBuilder();
if (table.isTournamentSubTable()) {
sb.append("Your tournament match of round ");
@ -843,7 +842,7 @@ public class TableController {
}
public void swapSeats(int seatNum1, int seatNum2) {
if (table.getState().equals(TableState.READY_TO_START)) {
if (table.getState()==TableState.READY_TO_START) {
if (seatNum1 >= 0 && seatNum2 >= 0 && seatNum1 < table.getSeats().length && seatNum2 < table.getSeats().length) {
Player swapPlayer = table.getSeats()[seatNum1].getPlayer();
String swapType = table.getSeats()[seatNum1].getPlayerType();
@ -876,7 +875,7 @@ public class TableController {
public boolean isTournamentStillValid() {
if (table.getTournament() != null) {
if (!table.getState().equals(TableState.WAITING) && !table.getState().equals(TableState.READY_TO_START) && !table.getState().equals(TableState.STARTING)) {
if (table.getState() != TableState.WAITING && table.getState() != TableState.READY_TO_START && table.getState() != TableState.STARTING) {
TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(table.getTournament().getId());
if (tournamentController != null) {
return tournamentController.isTournamentStillValid(table.getState());
@ -923,7 +922,7 @@ public class TableController {
int humanPlayers = 0;
int aiPlayers = 0;
int validHumanPlayers = 0;
if (!(table.getState().equals(TableState.WAITING) || table.getState().equals(TableState.STARTING) || table.getState().equals(TableState.READY_TO_START))) {
if (!(table.getState() == TableState.WAITING || table.getState() == TableState.STARTING || table.getState() == TableState.READY_TO_START)) {
if (match == null) {
logger.debug("- Match table with no match:");
logger.debug("-- matchId:" + match.getId() + " [" + match.getName() + "]");
@ -947,9 +946,9 @@ public class TableController {
}
if (matchPlayer.getPlayer().isHuman()) {
humanPlayers++;
if ((table.getState().equals(TableState.WAITING)
|| table.getState().equals(TableState.STARTING)
|| table.getState().equals(TableState.READY_TO_START))
if ((table.getState() == TableState.WAITING
|| table.getState() == TableState.STARTING
|| table.getState() == TableState.READY_TO_START)
|| !match.isDoneSideboarding()
|| (!matchPlayer.hasQuit() && match.getGame() != null && matchPlayer.getPlayer().isInGame())) {
User user = UserManager.getInstance().getUser(userPlayerEntry.getKey());
@ -990,7 +989,7 @@ public class TableController {
}
public synchronized boolean changeTableStateToStarting() {
if (!getTable().getState().equals(TableState.READY_TO_START)) {
if (getTable().getState() != TableState.READY_TO_START) {
// tournament is not ready, can't start
return false;
}

View file

@ -344,7 +344,7 @@ public class TableManager {
}
// If table is not finished, the table has to be removed completly because it's not a normal state (if finished it will be removed in GamesRoomImpl.Update())
if (!table.getState().equals(TableState.FINISHED)) {
if (table.getState()!=TableState.FINISHED) {
if (game != null) {
GameManager.getInstance().removeGame(game.getId());
}
@ -395,7 +395,7 @@ public class TableManager {
tableCopy.addAll(tables.values());
for (Table table : tableCopy) {
try {
if (!table.getState().equals(TableState.FINISHED)) {
if (table.getState()!=TableState.FINISHED) {
// remove tables and games not valid anymore
logger.debug(table.getId() + " [" + table.getName()+ "] " + formatter.format(table.getStartTime() == null ? table.getCreateTime() : table.getCreateTime()) +" (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament":""));
TableController tableController = getController(table.getId());

View file

@ -37,6 +37,7 @@ import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import mage.cards.decks.Deck;
import mage.constants.ManaType;
import mage.constants.TableState;
@ -61,7 +62,6 @@ import mage.view.TableClientMessage;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class User {
@ -199,7 +199,7 @@ public class User {
public void lostConnection() {
// Because watched games don't get restored after reconnection call stop watching
for (Iterator<UUID> iterator = watchedGames.iterator(); iterator.hasNext();) {
for (Iterator<UUID> iterator = watchedGames.iterator(); iterator.hasNext(); ) {
UUID gameId = iterator.next();
GameManager.getInstance().stopWatching(gameId, userId);
iterator.remove();
@ -208,7 +208,7 @@ public class User {
}
public boolean isConnected() {
return userState.equals(UserState.Connected) || userState.equals(UserState.Reconnected);
return userState == UserState.Connected || userState == UserState.Reconnected;
}
public String getDisconnectDuration() {
@ -762,7 +762,7 @@ public class User {
public int getNumberOfNotStartedTables() {
int number = 0;
for (Table table : tables.values()) {
if (table.getState().equals(TableState.WAITING) || table.getState().equals(TableState.STARTING)) {
if (table.getState() == TableState.WAITING || table.getState() == TableState.STARTING) {
number++;
}
}
@ -772,7 +772,7 @@ public class User {
public int getNumberOfNotFinishedTables() {
int number = 0;
for (Table table : tables.values()) {
if (table.getState().equals(TableState.FINISHED)) {
if (table.getState() == TableState.FINISHED) {
number++;
} else {
TableController tableController = TableManager.getInstance().getController(table.getId());

View file

@ -37,6 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import mage.MageException;
import mage.cards.decks.DeckCardLists;
import mage.constants.TableState;
@ -58,7 +59,6 @@ import mage.view.UsersView;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
@ -232,11 +232,11 @@ class TableListSorter implements Comparator<Table> {
@Override
public int compare(Table one, Table two) {
if (one.getState() != null && two.getState() != null) {
if (!TableState.SIDEBOARDING.equals(one.getState()) && !TableState.DUELING.equals(one.getState())) {
if (TableState.SIDEBOARDING != one.getState() && TableState.DUELING != one.getState()) {
if (one.getState().compareTo(two.getState()) != 0) {
return one.getState().compareTo(two.getState());
}
} else if (!TableState.SIDEBOARDING.equals(two.getState()) && !TableState.DUELING.equals(two.getState())) {
} else if (TableState.SIDEBOARDING != two.getState() && TableState.DUELING != two.getState()) {
if (one.getState().compareTo(two.getState()) != 0) {
return one.getState().compareTo(two.getState());
}

View file

@ -302,7 +302,7 @@ public class TournamentController {
}
private void initTournament() {
if (!TableManager.getInstance().getTable(tableId).getState().equals(TableState.DUELING)) {
if (TableManager.getInstance().getTable(tableId).getState()!=TableState.DUELING) {
TableManager.getInstance().initTournament(tableId);
}
}
@ -385,7 +385,7 @@ public class TournamentController {
// quit active matches of that tournament
TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId);
status = TourneyQuitStatus.DURING_ROUND;
} else if (tournamentPlayer.getState().equals(TournamentPlayerState.DRAFTING)) {
} else if (tournamentPlayer.getState()==TournamentPlayerState.DRAFTING) {
info = "during Draft phase";
if (!checkToReplaceDraftPlayerByAi(userId, tournamentPlayer)) {
this.abortDraftTournament();
@ -399,7 +399,7 @@ public class TournamentController {
}
}
status = TourneyQuitStatus.DURING_DRAFTING;
} else if (tournamentPlayer.getState().equals(TournamentPlayerState.CONSTRUCTING)) {
} else if (tournamentPlayer.getState()==TournamentPlayerState.CONSTRUCTING) {
info = "during Construction phase";
status = TourneyQuitStatus.DURING_CONSTRUCTION;
} else {
@ -523,7 +523,7 @@ public class TournamentController {
}
}
}
if (activePlayers < 2 && !tableState.equals(TableState.WAITING)) {
if (activePlayers < 2 && tableState!=TableState.WAITING) {
logger.debug("Tournament has less than 2 active players - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
return false;
}

View file

@ -1,16 +1,5 @@
package mage.server.util;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mage.cards.Card;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
@ -19,6 +8,14 @@ import mage.game.Game;
import mage.players.Player;
import mage.util.RandomUtil;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author nantuko
*/
@ -129,14 +126,17 @@ public class SystemUtil {
// Put the card in Exile to start. Otherwise the game doesn't know where to remove the card from.
game.getExile().getPermanentExile().add(card);
game.setZone(card.getId(), Zone.EXILED);
if (zone.equals(Zone.BATTLEFIELD)) {
card.putOntoBattlefield(game, Zone.EXILED, null, player.getId());
} else if (zone.equals(Zone.LIBRARY)) {
card.setZone(Zone.LIBRARY, game);
game.getExile().getPermanentExile().remove(card);
player.getLibrary().putOnTop(card, game);
} else {
card.moveToZone(zone, null, game, false);
switch (zone) {
case BATTLEFIELD:
card.putOntoBattlefield(game, Zone.EXILED, null, player.getId());
break;
case LIBRARY:
card.setZone(Zone.LIBRARY, game);
game.getExile().getPermanentExile().remove(card);
player.getLibrary().putOnTop(card, game);
break;
default:
card.moveToZone(zone, null, game, false);
}
logger.info("Added card to player's " + zone.toString() + ": " + card.getName() + ", player = " + player.getName());
}
@ -176,8 +176,8 @@ public class SystemUtil {
/**
* Get a diff between two dates
*
* @param date1 the oldest date
* @param date2 the newest date
* @param date1 the oldest date
* @param date2 the newest date
* @param timeUnit the unit in which you want the diff
* @return the diff value, in the provided unit
*/