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

@ -23,7 +23,7 @@ public class EntityManagerTest {
System.out.print(" arguments=[ ");
if (log.getArguments() != null) {
for (String argument : log.getArguments()) {
System.out.print("arg=" + argument + " ");
System.out.print("arg=" + argument + ' ');
}
}
System.out.println("]");

View file

@ -94,7 +94,7 @@ public class Connection {
@Override
public String toString() {
return host + ":" + Integer.toString(port) + "/" + serialization + parameter;
return host + ':' + Integer.toString(port) + '/' + serialization + parameter;
}
public String getURI() {
@ -102,13 +102,13 @@ public class Connection {
try {
InetAddress inet = getLocalAddress();
if (inet != null) {
return transport + "://" + inet.getHostAddress() + ":" + port + "/" + serialization + parameter;
return transport + "://" + inet.getHostAddress() + ':' + port + '/' + serialization + parameter;
}
} catch (SocketException ex) {
// just use localhost if can't find local ip
}
}
return transport + "://" + host + ":" + port + "/" + serialization + parameter;
return transport + "://" + host + ':' + port + '/' + serialization + parameter;
}
public ProxyType getProxyType() {

View file

@ -158,7 +158,7 @@ public class SessionImpl implements Session {
StringBuilder sb = new StringBuilder();
sb.append("Unable to connect to server.\n");
for (StackTraceElement element : t.getStackTrace()) {
sb.append(element.toString()).append("\n");
sb.append(element.toString()).append('\n');
}
client.showMessage(sb.toString());
}
@ -171,11 +171,11 @@ public class SessionImpl implements Session {
return establishJBossRemotingConnection(connection) && handleRemotingTaskExceptions(new RemotingTask() {
@Override
public boolean run() throws Throwable {
logger.info("Trying to register as " + getUserName() + " to XMAGE server at " + connection.getHost() + ":" + connection.getPort());
logger.info("Trying to register as " + getUserName() + " to XMAGE server at " + connection.getHost() + ':' + connection.getPort());
boolean registerResult = server.registerUser(sessionId, connection.getUsername(),
connection.getPassword(), connection.getEmail());
if (registerResult) {
logger.info("Registered as " + getUserName() + " to MAGE server at " + connection.getHost() + ":" + connection.getPort());
logger.info("Registered as " + getUserName() + " to MAGE server at " + connection.getHost() + ':' + connection.getPort());
}
return registerResult;
}
@ -187,10 +187,10 @@ public class SessionImpl implements Session {
return establishJBossRemotingConnection(connection) && handleRemotingTaskExceptions(new RemotingTask() {
@Override
public boolean run() throws Throwable {
logger.info("Trying to ask for an auth token to " + getEmail() + " to XMAGE server at " + connection.getHost() + ":" + connection.getPort());
logger.info("Trying to ask for an auth token to " + getEmail() + " to XMAGE server at " + connection.getHost() + ':' + connection.getPort());
boolean result = server.emailAuthToken(sessionId, connection.getEmail());
if (result) {
logger.info("An auth token is emailed to " + getEmail() + " from MAGE server at " + connection.getHost() + ":" + connection.getPort());
logger.info("An auth token is emailed to " + getEmail() + " from MAGE server at " + connection.getHost() + ':' + connection.getPort());
}
return result;
}
@ -202,10 +202,10 @@ public class SessionImpl implements Session {
return establishJBossRemotingConnection(connection) && handleRemotingTaskExceptions(new RemotingTask() {
@Override
public boolean run() throws Throwable {
logger.info("Trying reset the password in XMAGE server at " + connection.getHost() + ":" + connection.getPort());
logger.info("Trying reset the password in XMAGE server at " + connection.getHost() + ':' + connection.getPort());
boolean result = server.resetPassword(sessionId, connection.getEmail(), connection.getAuthToken(), connection.getPassword());
if (result) {
logger.info("Password is successfully reset in MAGE server at " + connection.getHost() + ":" + connection.getPort());
logger.info("Password is successfully reset in MAGE server at " + connection.getHost() + ':' + connection.getPort());
}
return result;
}
@ -218,7 +218,7 @@ public class SessionImpl implements Session {
&& handleRemotingTaskExceptions(new RemotingTask() {
@Override
public boolean run() throws Throwable {
logger.info("Trying to log-in as " + getUserName() + " to XMAGE server at " + connection.getHost() + ":" + connection.getPort());
logger.info("Trying to log-in as " + getUserName() + " to XMAGE server at " + connection.getHost() + ':' + connection.getPort());
boolean registerResult;
if (connection.getAdminPassword() == null) {
// for backward compatibility. don't remove twice call - first one does nothing but for version checking
@ -234,8 +234,8 @@ public class SessionImpl implements Session {
if (!connection.getUsername().equals("Admin")) {
updateDatabase(connection.isForceDBComparison(), serverState);
}
logger.info("Logged-in as " + getUserName() + " to MAGE server at " + connection.getHost() + ":" + connection.getPort());
client.connected(getUserName() + "@" + connection.getHost() + ":" + connection.getPort() + " ");
logger.info("Logged-in as " + getUserName() + " to MAGE server at " + connection.getHost() + ':' + connection.getPort());
client.connected(getUserName() + '@' + connection.getHost() + ':' + connection.getPort() + ' ');
return true;
}
disconnect(false);
@ -260,7 +260,7 @@ public class SessionImpl implements Session {
boolean result = handleRemotingTaskExceptions(new RemotingTask() {
@Override
public boolean run() throws Throwable {
logger.info("Trying to connect to XMAGE server at " + connection.getHost() + ":" + connection.getPort());
logger.info("Trying to connect to XMAGE server at " + connection.getHost() + ':' + connection.getPort());
System.setProperty("http.nonProxyHosts", "code.google.com");
System.setProperty("socksNonProxyHosts", "code.google.com");
@ -391,14 +391,14 @@ public class SessionImpl implements Session {
Set callbackConnectors = callbackClient.getCallbackConnectors(callbackHandler);
if (callbackConnectors.size() != 1) {
logger.warn("There should be one callback Connector (number existing = " + callbackConnectors.size() + ")");
logger.warn("There should be one callback Connector (number existing = " + callbackConnectors.size() + ')');
}
callbackClient.invoke(null);
sessionId = callbackClient.getSessionId();
sessionState = SessionState.CONNECTED;
logger.info("Connected to MAGE server at " + connection.getHost() + ":" + connection.getPort());
logger.info("Connected to MAGE server at " + connection.getHost() + ':' + connection.getPort());
return true;
}
});
@ -451,7 +451,7 @@ public class SessionImpl implements Session {
break;
}
if (t.getCause() != null && logger.isDebugEnabled()) {
message = "\n" + t.getCause().getMessage() + message;
message = '\n' + t.getCause().getMessage() + message;
logger.debug(t.getCause().getMessage());
}
@ -1434,7 +1434,7 @@ public class SessionImpl implements Session {
@Override
public boolean endUserSession(String userSessionId) {
try {
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to mute userSessionId " + userSessionId + "?", "WARNING",
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to mute userSessionId " + userSessionId + '?', "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
if (isConnected()) {
server.endUserSession(sessionId, userSessionId);
@ -1470,7 +1470,7 @@ public class SessionImpl implements Session {
@Override
public boolean setActivation(String userName, boolean active) {
try {
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to set active to " + active + " for user: " + userName + "?", "WARNING",
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to set active to " + active + " for user: " + userName + '?', "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
if (isConnected()) {
server.setActivation(sessionId, userName, active);
@ -1496,7 +1496,7 @@ public class SessionImpl implements Session {
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
return setActivation(userName, false);
}
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to toggle activation for user: " + userName + "?", "WARNING",
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to toggle activation for user: " + userName + '?', "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
if (isConnected()) {
server.toggleActivation(sessionId, userName);
@ -1542,8 +1542,8 @@ public class SessionImpl implements Session {
}
private void handleInvalidDeckException(InvalidDeckException iex) {
logger.warn(iex.getMessage() + "\n" + iex.getInvalid());
client.showError(iex.getMessage() + "\n" + iex.getInvalid());
logger.warn(iex.getMessage() + '\n' + iex.getInvalid());
client.showError(iex.getMessage() + '\n' + iex.getInvalid());
}
private void handleGameException(GameException ex) {
@ -1588,7 +1588,7 @@ public class SessionImpl implements Session {
if (isConnected()) {
long startTime = System.nanoTime();
if (!server.ping(sessionId, pingInfo)) {
logger.error("Ping failed: " + this.getUserName() + " Session: " + sessionId + " to MAGE server at " + connection.getHost() + ":" + connection.getPort());
logger.error("Ping failed: " + this.getUserName() + " Session: " + sessionId + " to MAGE server at " + connection.getHost() + ':' + connection.getPort());
throw new MageException("Ping failed");
}
pingTime.add(System.nanoTime() - startTime);
@ -1602,7 +1602,7 @@ public class SessionImpl implements Session {
sum += time;
}
milliSeconds = TimeUnit.MILLISECONDS.convert(sum / pingTime.size(), TimeUnit.NANOSECONDS);
pingInfo = lastPing + " (Av: " + (milliSeconds > 0 ? milliSeconds + "ms" : "<1ms") + ")";
pingInfo = lastPing + " (Av: " + (milliSeconds > 0 ? milliSeconds + "ms" : "<1ms") + ')';
}
return true;
} catch (MageException ex) {

View file

@ -77,7 +77,7 @@ public class MageVersion implements Serializable, Comparable<MageVersion> {
@Override
public String toString() {
return major + "." + minor + "." + patch + info + minorPatch;
return major + "." + minor + '.' + patch + info + minorPatch;
}
@Override

View file

@ -732,7 +732,7 @@ public class CardView extends SimpleCardView {
@Override
public String toString() {
return getName() + " [" + getId() + "]";
return getName() + " [" + getId() + ']';
}
public boolean isFaceDown() {

View file

@ -79,11 +79,11 @@ public class GameEndView implements Serializable {
}
if (you != null) {
if (you.hasWon()) {
gameInfo = new StringBuilder("You won the game on turn ").append(game.getTurnNum()).append(".").toString();
gameInfo = new StringBuilder("You won the game on turn ").append(game.getTurnNum()).append('.').toString();
} else if (winner > 0) {
gameInfo = new StringBuilder("You lost the game on turn ").append(game.getTurnNum()).append(".").toString();
gameInfo = new StringBuilder("You lost the game on turn ").append(game.getTurnNum()).append('.').toString();
} else {
gameInfo = new StringBuilder("Game is a draw on Turn ").append(game.getTurnNum()).append(".").toString();
gameInfo = new StringBuilder("Game is a draw on Turn ").append(game.getTurnNum()).append('.').toString();
}
}
matchView = new MatchView(table);

View file

@ -138,7 +138,7 @@ public class GameView implements Serializable {
if (designation != null) {
stack.put(stackObject.getId(), new CardView(designation, (StackAbility) stackObject));
} else {
LOGGER.fatal("Designation object not found: " + object.getName() + " " + object.toString() + " " + object.getClass().toString());
LOGGER.fatal("Designation object not found: " + object.getName() + ' ' + object.toString() + ' ' + object.getClass().toString());
}
} else if (object instanceof StackAbility) {
@ -147,7 +147,7 @@ public class GameView implements Serializable {
stack.put(stackObject.getId(), new CardView(((StackAbility) stackObject)));
checkPaid(stackObject.getId(), ((StackAbility) stackObject));
} else {
LOGGER.fatal("Object can't be cast to StackAbility: " + object.getName() + " " + object.toString() + " " + object.getClass().toString());
LOGGER.fatal("Object can't be cast to StackAbility: " + object.getName() + ' ' + object.toString() + ' ' + object.getClass().toString());
}
} else {
// can happen if a player times out while ability is on the stack

View file

@ -78,7 +78,7 @@ public class MatchView implements Serializable {
this.gameType = match.getOptions().getGameType();
if (table.getName() != null && !table.getName().isEmpty()) {
this.deckType = match.getOptions().getDeckType() + " [" + table.getName() + "]";
this.deckType = match.getOptions().getDeckType() + " [" + table.getName() + ']';
} else {
this.deckType = match.getOptions().getDeckType();
}
@ -102,9 +102,9 @@ public class MatchView implements Serializable {
int lostGames = match.getNumGames() - (matchPlayer.getWins() + match.getDraws());
sb1.append(", ");
sb2.append(matchPlayer.getName()).append(" [");
sb2.append(matchPlayer.getWins()).append("-");
sb2.append(matchPlayer.getWins()).append('-');
if (match.getDraws() > 0) {
sb2.append(match.getDraws()).append("-");
sb2.append(match.getDraws()).append('-');
}
sb2.append(lostGames).append("], ");
}
@ -127,14 +127,14 @@ public class MatchView implements Serializable {
this.matchName = table.getName();
this.gameType = table.getGameType();
if (table.getTournament().getOptions().getNumberRounds() > 0) {
this.gameType = new StringBuilder(this.gameType).append(" ").append(table.getTournament().getOptions().getNumberRounds()).append(" Rounds").toString();
this.gameType = new StringBuilder(this.gameType).append(' ').append(table.getTournament().getOptions().getNumberRounds()).append(" Rounds").toString();
}
StringBuilder sbDeckType = new StringBuilder(table.getDeckType());
if (!table.getTournament().getBoosterInfo().isEmpty()) {
sbDeckType.append(" ").append(table.getTournament().getBoosterInfo());
sbDeckType.append(' ').append(table.getTournament().getBoosterInfo());
}
if (table.getName() != null && !table.getName().isEmpty()) {
sbDeckType.append(table.getDeckType()).append(" [").append(table.getName()).append("]");
sbDeckType.append(table.getDeckType()).append(" [").append(table.getName()).append(']');
}
this.deckType = sbDeckType.toString();
StringBuilder sb1 = new StringBuilder();
@ -145,7 +145,7 @@ public class MatchView implements Serializable {
StringBuilder sb2 = new StringBuilder();
if (table.getTournament().getRounds().size() > 0) {
for (TournamentPlayer tPlayer : table.getTournament().getPlayers()) {
sb2.append(tPlayer.getPlayer().getName()).append(": ").append(tPlayer.getResults()).append(" ");
sb2.append(tPlayer.getPlayer().getName()).append(": ").append(tPlayer.getResults()).append(' ');
}
} else {
sb2.append("Canceled");

View file

@ -73,7 +73,7 @@ public class TableView implements Serializable {
this.tableName = table.getName();
String tableNameInfo = null;
if (tableName != null && !tableName.isEmpty()) {
tableNameInfo = " [" + table.getName() + "]";
tableNameInfo = " [" + table.getName() + ']';
}
this.controllerName = table.getControllerName();
this.tableState = table.getState();
@ -95,7 +95,7 @@ public class TableView implements Serializable {
if (!table.isTournament()) {
// MATCH
if (table.getState()==TableState.WAITING || table.getState()==TableState.READY_TO_START) {
tableStateText = table.getState().toString() + " (" + table.getMatch().getPlayers().size() + "/" + table.getSeats().length + ")";
tableStateText = table.getState().toString() + " (" + table.getMatch().getPlayers().size() + '/' + table.getSeats().length + ')';
} else {
tableStateText = table.getState().toString();
}
@ -107,10 +107,10 @@ public class TableView implements Serializable {
for (MatchPlayer matchPlayer : table.getMatch().getPlayers()) {
if (matchPlayer.getPlayer() == null) {
sb.append(", ").append("[unknown]");
sbScore.append("-").append(matchPlayer.getWins());
sbScore.append('-').append(matchPlayer.getWins());
} else if (!matchPlayer.getName().equals(table.getControllerName())) {
sb.append(", ").append(matchPlayer.getName());
sbScore.append("-").append(matchPlayer.getWins());
sbScore.append('-').append(matchPlayer.getWins());
} else {
sbScore.insert(0, matchPlayer.getWins()).insert(0, " Score: ");
}
@ -140,7 +140,7 @@ public class TableView implements Serializable {
} else {
// TOURNAMENT
if (table.getTournament().getOptions().getNumberRounds() > 0) {
this.gameType = new StringBuilder(this.gameType).append(" ").append(table.getTournament().getOptions().getNumberRounds()).append(" Rounds").toString();
this.gameType = new StringBuilder(this.gameType).append(' ').append(table.getTournament().getOptions().getNumberRounds()).append(" Rounds").toString();
}
StringBuilder sb1 = new StringBuilder();
for (TournamentPlayer tp : table.getTournament().getPlayers()) {
@ -152,10 +152,10 @@ public class TableView implements Serializable {
StringBuilder infoText = new StringBuilder();
StringBuilder stateText = new StringBuilder(table.getState().toString());
infoText.append("Wins:").append(table.getTournament().getOptions().getMatchOptions().getWinsNeeded());
infoText.append(" Seats: ").append(table.getTournament().getPlayers().size()).append("/").append(table.getNumberOfSeats());
infoText.append(" Seats: ").append(table.getTournament().getPlayers().size()).append('/').append(table.getNumberOfSeats());
switch (table.getState()) {
case WAITING:
stateText.append(" (").append(table.getTournament().getPlayers().size()).append("/").append(table.getNumberOfSeats()).append(")");
stateText.append(" (").append(table.getTournament().getPlayers().size()).append('/').append(table.getNumberOfSeats()).append(')');
case READY_TO_START:
case STARTING:
infoText.append(" Time: ").append(table.getTournament().getOptions().getMatchOptions().getMatchTimeLimit().toString());
@ -172,13 +172,13 @@ public class TableView implements Serializable {
case DRAFTING:
Draft draft = table.getTournament().getDraft();
if (draft != null) {
stateText.append(" ").append(draft.getBoosterNum()).append("/").append(draft.getCardNum() - 1);
stateText.append(' ').append(draft.getBoosterNum()).append('/').append(draft.getCardNum() - 1);
}
default:
}
this.additionalInfo = infoText.toString();
this.tableStateText = stateText.toString();
this.deckType = table.getDeckType() + " " + table.getTournament().getBoosterInfo() + (tableNameInfo != null ? tableNameInfo : "");
this.deckType = table.getDeckType() + ' ' + table.getTournament().getBoosterInfo() + (tableNameInfo != null ? tableNameInfo : "");
this.skillLevel = table.getTournament().getOptions().getMatchOptions().getSkillLevel();
this.quitRatio = Integer.toString(table.getTournament().getOptions().getQuitRatio());
this.limited = table.getTournament().getOptions().getMatchOptions().isLimited();

View file

@ -70,14 +70,14 @@ public class TournamentGameView implements Serializable {
if (game.hasEnded()) {
if (game.getEndTime() != null) {
duelingTime = " (" + DateFormat.getDuration((game.getEndTime().getTime() - game.getStartTime().getTime())/1000) + ")";
duelingTime = " (" + DateFormat.getDuration((game.getEndTime().getTime() - game.getStartTime().getTime())/1000) + ')';
}
this.state = "Finished" + duelingTime;
this.result = game.getWinner();
}
else {
if (game.getStartTime() != null) {
duelingTime = " (" + DateFormat.getDuration((new Date().getTime() - game.getStartTime().getTime())/1000) + ")";
duelingTime = " (" + DateFormat.getDuration((new Date().getTime() - game.getStartTime().getTime())/1000) + ')';
}
this.state = "Dueling" + duelingTime;
this.result = "";

View file

@ -51,7 +51,7 @@ public class TournamentPlayerView implements Serializable, Comparable {
StringBuilder sb = new StringBuilder(tournamentPlayer.getState().toString());
String stateInfo = tournamentPlayer.getStateInfo();
if (!stateInfo.isEmpty()) {
sb.append(" (").append(stateInfo).append(")");
sb.append(" (").append(stateInfo).append(')');
}
sb.append(tournamentPlayer.getDisconnectInfo());
this.state = sb.toString();

View file

@ -67,7 +67,7 @@ public class TournamentView implements Serializable {
typeText.append(" / ").append(tournament.getOptions().getMatchOptions().getDeckType());
}
if (tournament.getNumberRounds() > 0) {
typeText.append(" ").append(tournament.getNumberRounds()).append(" rounds");
typeText.append(' ').append(tournament.getNumberRounds()).append(" rounds");
}
tournamentType = typeText.toString();
startTime = tournament.getStartTime();
@ -79,7 +79,7 @@ public class TournamentView implements Serializable {
tournamentState = tournament.getTournamentState();
if (tournament.getTournamentState().equals("Drafting") && tournament.getDraft() != null) {
runningInfo = "booster/card: " + tournament.getDraft().getBoosterNum() +"/" + (tournament.getDraft().getCardNum() -1);
runningInfo = "booster/card: " + tournament.getDraft().getBoosterNum() + '/' + (tournament.getDraft().getCardNum() -1);
} else {
runningInfo = "";
}