All 1-character strings converted to primitives

"b" + "r" now changed to 'b' + 'w'.  It's more straight-forward, and may cause perfomance improvements - character primitives allocation is faster and less expensive than string creation.
This commit is contained in:
vraskulin 2017-01-27 15:57:10 +03:00
parent 31589778ca
commit f60ebfbb1f
451 changed files with 989 additions and 978 deletions

View file

@ -154,7 +154,7 @@ public class ChatManager {
colour = "green";
}
messageToCheck = messageToCheck.replaceFirst("\\[" + cardName + "\\]", "card");
String displayCardName = "<font bgcolor=orange color=" + colour + ">" + cardName + "</font>";
String displayCardName = "<font bgcolor=orange color=" + colour + '>' + cardName + "</font>";
message = message.replaceFirst("\\[" + cardName + "\\]", displayCardName);
}
}
@ -209,7 +209,7 @@ public class ChatManager {
}
if (command.startsWith("W ") || command.startsWith("WHISPER ")) {
String rest = message.substring(command.startsWith("W ") ? 3 : 9);
int first = rest.indexOf(" ");
int first = rest.indexOf(' ');
if (first > 1) {
String userToName = rest.substring(0, first);
rest = rest.substring(first + 1).trim();

View file

@ -67,7 +67,7 @@ public class ChatSession {
if (!clients.containsKey(userId)) {
String userName = user.getName();
clients.put(userId, userName);
broadcast(null, userName + " has joined (" + user.getClientVersion() + ")", MessageColor.BLUE, true, MessageType.STATUS, null);
broadcast(null, userName + " has joined (" + user.getClientVersion() + ')', MessageColor.BLUE, true, MessageType.STATUS, null);
logger.trace(userName + " joined chat " + chatId);
}
});
@ -84,7 +84,7 @@ public class ChatSession {
String userName = clients.get(userId);
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);
logger.debug(userName + '(' + reason.toString() + ')' + " removed from chatId " + chatId);
}
String message;
switch (reason) {
@ -107,7 +107,7 @@ public class ChatSession {
message = null;
break;
default:
message = " left (" + reason.toString() + ")";
message = " left (" + reason.toString() + ')';
}
if (message != null) {
broadcast(null, userName + message, MessageColor.BLUE, true, MessageType.STATUS, null);

View file

@ -118,7 +118,7 @@ public class MageServerImpl implements MageServer {
String authToken = generateAuthToken();
activeAuthTokens.put(email, authToken);
String subject = "XMage Password Reset Auth Token";
String text = "Use this auth token to reset " + authorizedUser.name + "'s password: " + authToken + "\n"
String text = "Use this auth token to reset " + authorizedUser.name + "'s password: " + authToken + '\n'
+ "It's valid until the next server restart.";
boolean success;
if (!ConfigSettings.getInstance().getMailUser().isEmpty()) {
@ -221,13 +221,13 @@ public class MageServerImpl implements MageServer {
// check if the user itself satisfies the quitRatio requirement.
int quitRatio = options.getQuitRatio();
if (quitRatio < user.getMatchQuitRatio()) {
user.showUserMessage("Create table", "Your quit ratio " + user.getMatchQuitRatio() + "% is higher than the table requirement " + quitRatio + "%");
user.showUserMessage("Create table", "Your quit ratio " + user.getMatchQuitRatio() + "% is higher than the table requirement " + quitRatio + '%');
throw new MageException("No message");
}
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(userId, options);
if (logger.isDebugEnabled()) {
logger.debug("TABLE created - tableId: " + table.getTableId() + " " + table.getTableName());
logger.debug("TABLE created - tableId: " + table.getTableId() + ' ' + table.getTableName());
logger.debug("- " + user.getName() + " userId: " + user.getId());
logger.debug("- chatId: " + TableManager.getInstance().getChatId(table.getTableId()));
}
@ -274,7 +274,7 @@ public class MageServerImpl implements MageServer {
int quitRatio = options.getQuitRatio();
if (quitRatio < user.getTourneyQuitRatio()) {
String message = new StringBuilder("Your quit ratio ").append(user.getTourneyQuitRatio())
.append("% is higher than the table requirement ").append(quitRatio).append("%").toString();
.append("% is higher than the table requirement ").append(quitRatio).append('%').toString();
user.showUserMessage("Create tournament", message);
throw new MageException("No message");
}
@ -323,7 +323,7 @@ public class MageServerImpl implements MageServer {
if (logger.isTraceEnabled()) {
Optional<User> user = UserManager.getInstance().getUser(userId);
if (user.isPresent()) {
logger.trace("join tourn. tableId: " + tableId + " " + name);
logger.trace("join tourn. tableId: " + tableId + ' ' + name);
}
}
if (userId == null) {
@ -963,7 +963,7 @@ public class MageServerImpl implements MageServer {
User user = UserManager.getInstance().getUserByName(userName);
if (user != null) {
Date muteUntil = new Date(Calendar.getInstance().getTimeInMillis() + (durationMinutes * Timer.ONE_MINUTE));
user.showUserMessage("Admin info", "You were muted for chat messages until " + SystemUtil.dateFormat.format(muteUntil) + ".");
user.showUserMessage("Admin info", "You were muted for chat messages until " + SystemUtil.dateFormat.format(muteUntil) + '.');
user.setChatLockedUntil(muteUntil);
}
@ -976,7 +976,7 @@ public class MageServerImpl implements MageServer {
User user = UserManager.getInstance().getUserByName(userName);
if (user != null) {
Date lockUntil = new Date(Calendar.getInstance().getTimeInMillis() + (durationMinutes * Timer.ONE_MINUTE));
user.showUserMessage("Admin info", "Your user profile was locked until " + SystemUtil.dateFormat.format(lockUntil) + ".");
user.showUserMessage("Admin info", "Your user profile was locked until " + SystemUtil.dateFormat.format(lockUntil) + '.');
user.setLockedUntil(lockUntil);
if (user.isConnected()) {
SessionManager.getInstance().disconnectUser(sessionId, user.getSessionId());

View file

@ -23,7 +23,7 @@ public class MailgunClient {
String domain = ConfigSettings.getInstance().getMailgunDomain();
WebResource webResource = client.resource("https://api.mailgun.net/v3/" + domain + "/messages");
MultivaluedMapImpl formData = new MultivaluedMapImpl();
formData.add("from", "XMage <postmaster@" + domain + ">");
formData.add("from", "XMage <postmaster@" + domain + '>');
formData.add("to", email);
formData.add("subject", subject);
formData.add("text", text);

View file

@ -130,7 +130,7 @@ public class Main {
logger.info(" - Loading extension from " + f);
extensions.add(ExtensionPackageLoader.loadExtension(f));
} catch (IOException e) {
logger.error("Could not load extension in " + f + "!", e);
logger.error("Could not load extension in " + f + '!', e);
}
}
}
@ -141,7 +141,7 @@ public class Main {
logger.info("Registering custom sets...");
for (ExtensionPackage pkg : extensions) {
for (ExpansionSet set : pkg.getSets()) {
logger.info("- Loading " + set.getName() + " (" + set.getCode() + ")");
logger.info("- Loading " + set.getName() + " (" + set.getCode() + ')');
Sets.getInstance().addSet(set);
}
PluginClassloaderRegistery.registerPluginClassloader(pkg.getClassLoader());
@ -268,7 +268,7 @@ public class Main {
StringBuilder sessionInfo = new StringBuilder();
Optional<User> user = UserManager.getInstance().getUser(session.getUserId());
if (user.isPresent()) {
sessionInfo.append(user.get().getName()).append(" [").append(user.get().getGameInfo()).append("]");
sessionInfo.append(user.get().getName()).append(" [").append(user.get().getGameInfo()).append(']');
} else {
sessionInfo.append("[user missing] ");
}

View file

@ -102,7 +102,7 @@ public class Session {
}
AuthorizedUserRepository.instance.add(userName, password, email);
String subject = "XMage Registration Completed";
String text = "You are successfully registered as " + userName + ".";
String text = "You are successfully registered as " + userName + '.';
text += " Your initial, generated password is: " + password;
boolean success;

View file

@ -179,7 +179,7 @@ public class TableController {
if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
StringBuilder sb = new StringBuilder("You (").append(name).append(") have an invalid deck for the selected ").append(table.getValidator().getName()).append(" Format. \n\n");
for (Map.Entry<String, String> entry : table.getValidator().getInvalid().entrySet()) {
sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
sb.append(entry.getKey()).append(": ").append(entry.getValue()).append('\n');
}
sb.append("\n\nSelect a deck that is appropriate for the selected format and try again!");
user.showUserMessage("Join Table", sb.toString());
@ -194,7 +194,7 @@ public class TableController {
int quitRatio = table.getTournament().getOptions().getQuitRatio();
if (quitRatio < user.getTourneyQuitRatio()) {
String message = new StringBuilder("Your quit ratio ").append(user.getTourneyQuitRatio())
.append("% is higher than the table requirement ").append(quitRatio).append("%").toString();
.append("% is higher than the table requirement ").append(quitRatio).append('%').toString();
user.showUserMessage("Join Table", message);
return false;
}
@ -278,7 +278,7 @@ public class TableController {
if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
StringBuilder sb = new StringBuilder("You (").append(name).append(") have an invalid deck for the selected ").append(table.getValidator().getName()).append(" Format. \n\n");
for (Map.Entry<String, String> entry : table.getValidator().getInvalid().entrySet()) {
sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
sb.append(entry.getKey()).append(": ").append(entry.getValue()).append('\n');
}
sb.append("\n\nSelect a deck that is appropriate for the selected format and try again!");
user.showUserMessage("Join Table", sb.toString());
@ -292,7 +292,7 @@ public class TableController {
int quitRatio = table.getMatch().getOptions().getQuitRatio();
if (quitRatio < user.getMatchQuitRatio()) {
String message = new StringBuilder("Your quit ratio ").append(user.getMatchQuitRatio())
.append("% is higher than the table requirement ").append(quitRatio).append("%").toString();
.append("% is higher than the table requirement ").append(quitRatio).append('%').toString();
user.showUserMessage("Join Table", message);
return false;
}
@ -317,7 +317,7 @@ public class TableController {
user.showUserMessage("Join Table", message);
return false;
}
logger.debug("DECK validated: " + table.getValidator().getName() + " " + player.getName() + " " + deck.getName());
logger.debug("DECK validated: " + table.getValidator().getName() + ' ' + player.getName() + ' ' + deck.getName());
if (!player.canJoinTable(table)) {
user.showUserMessage("Join Table", new StringBuilder("A ").append(seat.getPlayerType()).append(" player can't join this table.").toString());
return false;
@ -505,7 +505,7 @@ public class TableController {
if (table.isTournament()) {
logger.debug("Quit tournament sub tables for userId: " + userId);
TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId);
logger.debug("Quit tournament Id: " + table.getTournament().getId() + "(" + table.getTournament().getTournamentState() + ")");
logger.debug("Quit tournament Id: " + table.getTournament().getId() + '(' + table.getTournament().getTournamentState() + ')');
TournamentManager.getInstance().quit(tournament.getId(), userId);
} else {
MatchPlayer matchPlayer = match.getPlayer(playerId);
@ -553,7 +553,7 @@ public class TableController {
logger.info("Tourn. match started id:" + match.getId() + " tournId: " + table.getTournament().getId());
} else {
UserManager.getInstance().getUser(userId).ifPresent(user -> {
logger.info("MATCH started [" + match.getName() + "] " + match.getId() + "(" + user.getName() + ")");
logger.info("MATCH started [" + match.getName() + "] " + match.getId() + '(' + user.getName() + ')');
logger.debug("- " + match.getOptions().getGameType() + " - " + match.getOptions().getDeckType());
});
}
@ -613,7 +613,7 @@ public class TableController {
// log about game started
logger.info("GAME started " + (match.getGame() != null ? match.getGame().getId() : "no Game") + " [" + match.getName() + "] " + creator + " - " + opponent.toString());
logger.debug("- matchId: " + match.getId() + " [" + match.getName() + "]");
logger.debug("- matchId: " + match.getId() + " [" + match.getName() + ']');
if (match.getGame() != null) {
logger.debug("- chatId: " + GameManager.getInstance().getChatId(match.getGame().getId()));
}
@ -926,12 +926,12 @@ public class TableController {
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() + "]");
logger.debug("-- matchId:" + match.getId() + " [" + match.getName() + ']');
// return false;
} else if (match.isDoneSideboarding() && match.getGame() == null) {
// no sideboarding and not active game -> match seems to hang (maybe the Draw bug)
logger.debug("- Match with no active game and not in sideboard state:");
logger.debug("-- matchId:" + match.getId() + " [" + match.getName() + "]");
logger.debug("-- matchId:" + match.getId() + " [" + match.getName() + ']');
// return false;
}
}

View file

@ -368,12 +368,12 @@ public class TableManager {
logger.debug(user.getId()
+ " | " + formatter.format(user.getConnectionTime())
+ " | " + sessionState
+ " | " + user.getName() + " (" + user.getUserState().toString() + " - " + user.getPingInfo() + ")");
+ " | " + user.getName() + " (" + user.getUserState().toString() + " - " + user.getPingInfo() + ')');
}
ArrayList<ChatSession> chatSessions = ChatManager.getInstance().getChatSessions();
logger.debug("------- ChatSessions: " + chatSessions.size() + " ----------------------------------");
for (ChatSession chatSession : chatSessions) {
logger.debug(chatSession.getChatId() + " " + formatter.format(chatSession.getCreateTime()) + " " + chatSession.getInfo() + " " + chatSession.getClients().values().toString());
logger.debug(chatSession.getChatId() + " " + formatter.format(chatSession.getCreateTime()) + ' ' + chatSession.getInfo() + ' ' + chatSession.getClients().values().toString());
}
logger.debug("------- Games: " + GameManager.getInstance().getNumberActiveGames() + " --------------------------------------------");
logger.debug(" Active Game Worker: " + ThreadExecutor.getInstance().getActiveThreads(ThreadExecutor.getInstance().getGameExecutor()));

View file

@ -234,7 +234,7 @@ public class User {
int minutes = (int) secondsLeft / 60;
int seconds = (int) secondsLeft % 60;
return new StringBuilder(sign).append(Integer.toString(minutes)).append(":").append(seconds > 9 ? seconds : "0" + Integer.toString(seconds)).toString();
return new StringBuilder(sign).append(Integer.toString(minutes)).append(':').append(seconds > 9 ? seconds : '0' + Integer.toString(seconds)).toString();
}
public long getSecondsDisconnected() {
@ -509,7 +509,7 @@ public class User {
}
if (!isConnected()) {
tournamentPlayer.setDisconnectInfo(" (discon. " + getDisconnectDuration() + ")");
tournamentPlayer.setDisconnectInfo(" (discon. " + getDisconnectDuration() + ')');
} else {
tournamentPlayer.setDisconnectInfo("");
}
@ -547,25 +547,25 @@ public class User {
tablesToDelete.clear();
}
if (waiting > 0) {
sb.append("Wait: ").append(waiting).append(" ");
sb.append("Wait: ").append(waiting).append(' ');
}
if (match > 0) {
sb.append("Match: ").append(match).append(" ");
sb.append("Match: ").append(match).append(' ');
}
if (sideboard > 0) {
sb.append("Sideb: ").append(sideboard).append(" ");
sb.append("Sideb: ").append(sideboard).append(' ');
}
if (draft > 0) {
sb.append("Draft: ").append(draft).append(" ");
sb.append("Draft: ").append(draft).append(' ');
}
if (construct > 0) {
sb.append("Const: ").append(construct).append(" ");
sb.append("Const: ").append(construct).append(' ');
}
if (tournament > 0) {
sb.append("Tourn: ").append(tournament).append(" ");
sb.append("Tourn: ").append(tournament).append(' ');
}
if (watchedGames.size() > 0) {
sb.append("Watch: ").append(watchedGames.size()).append(" ");
sb.append("Watch: ").append(watchedGames.size()).append(' ');
}
return sb.toString();
}
@ -586,7 +586,7 @@ public class User {
if (isConnected()) {
return pingInfo;
} else {
return " (discon. " + getDisconnectDuration() + ")";
return " (discon. " + getDisconnectDuration() + ')';
}
}
@ -668,7 +668,7 @@ public class User {
if (quit.size() > 0) {
builder.append(" (");
joinStrings(builder, quit, " ");
builder.append(")");
builder.append(')');
}
return builder.toString();
}
@ -700,7 +700,7 @@ public class User {
if (quit.size() > 0) {
builder.append(" (");
joinStrings(builder, quit, " ");
builder.append(")");
builder.append(')');
}
return builder.toString();
}

View file

@ -133,7 +133,7 @@ public class UserManager {
USER_EXECUTOR.execute(
() -> {
try {
LOGGER.info("USER REMOVE - " + user.getName() + " (" + reason.toString() + ") userId: " + userId + " [" + user.getGameInfo() + "]");
LOGGER.info("USER REMOVE - " + user.getName() + " (" + reason.toString() + ") userId: " + userId + " [" + user.getGameInfo() + ']');
user.remove(reason);
LOGGER.debug("USER REMOVE END - " + user.getName());
} catch (Exception ex) {

View file

@ -331,7 +331,7 @@ public class GameController implements GameCallback {
joinType = "rejoined";
}
user.get().addGame(playerId, gameSession);
logger.debug("Player " + player.getName() + " " + playerId + " has " + joinType + " gameId: " + game.getId());
logger.debug("Player " + player.getName() + ' ' + playerId + " has " + joinType + " gameId: " + game.getId());
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getLogName() + " has " + joinType + " the game", MessageColor.ORANGE, true, MessageType.GAME, null);
checkStart();
}
@ -613,7 +613,7 @@ public class GameController implements GameCallback {
} else {
// user can already see the cards
UserManager.getInstance().getUser(userIdRequester).ifPresent(requester -> {
requester.showUserMessage("Request to show hand cards", "You can see already the hand cards of player " + grantingPlayer.getName() + "!");
requester.showUserMessage("Request to show hand cards", "You can see already the hand cards of player " + grantingPlayer.getName() + '!');
});
}
@ -848,9 +848,9 @@ public class GameController implements GameCallback {
StringBuilder sb = new StringBuilder();
sb.append(message).append(ex.toString());
sb.append("\nServer version: ").append(Main.getVersion().toString());
sb.append("\n");
sb.append('\n');
for (StackTraceElement e : ex.getStackTrace()) {
sb.append(e.toString()).append("\n");
sb.append(e.toString()).append('\n');
}
for (final Entry<UUID, GameSessionPlayer> entry : gameSessions.entrySet()) {
entry.getValue().gameError(sb.toString());
@ -1004,9 +1004,9 @@ public class GameController implements GameCallback {
if (player != null) {
sb.append(player.getName()).append("(Left=").append(player.hasLeft() ? "Y" : "N").append(") ");
} else {
sb.append("player missing: ").append(playerId).append(" ");
sb.append("player missing: ").append(playerId).append(' ');
}
}
return sb.append("]").toString();
return sb.append(']').toString();
}
}

View file

@ -424,7 +424,7 @@ public class TournamentController {
TableController tableController = TableManager.getInstance().getController(tableId);
if (tableController != null) {
if (user.isPresent()) {
replacePlayerName = "Draftbot (" + user.get().getName() + ")";
replacePlayerName = "Draftbot (" + user.get().getName() + ')';
}
tableController.replaceDraftPlayer(leavingPlayer.getPlayer(), replacePlayerName, "Computer - draftbot", 5);
if (user.isPresent()) {

View file

@ -92,13 +92,13 @@ public class TournamentFactory {
StringBuilder rv = new StringBuilder( "Random Draft using sets: ");
for (Map.Entry<String, Integer> entry: setInfo.entrySet()){
rv.append(entry.getKey());
rv.append(";");
rv.append(';');
}
tournament.setBoosterInfo(rv.toString());
} else {
StringBuilder sb = new StringBuilder();
for (Map.Entry<String,Integer> entry:setInfo.entrySet()) {
sb.append(entry.getValue().toString()).append("x").append(entry.getKey()).append(" ");
sb.append(entry.getValue().toString()).append('x').append(entry.getKey()).append(' ');
}
tournament.setBoosterInfo(sb.toString());
}
@ -110,7 +110,7 @@ public class TournamentFactory {
logger.fatal("TournamentFactory error ", ex);
return null;
}
logger.debug("Tournament created: " + tournamentType + " " + tournament.getId());
logger.debug("Tournament created: " + tournamentType + ' ' + tournament.getId());
return tournament;
}

View file

@ -119,7 +119,7 @@ class XMageThreadFactory implements ThreadFactory {
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setName(prefix + " " + thread.getThreadGroup().getName() + "-" + thread.getId());
thread.setName(prefix + ' ' + thread.getThreadGroup().getName() + '-' + thread.getId());
return thread;
}