修改严重代码

This commit is contained in:
zhoudaxia 2016-09-01 23:18:28 +08:00
parent 428f63be82
commit 15f56c9d26
5 changed files with 31 additions and 32 deletions

View File

@ -59,7 +59,7 @@ public class BattlesRunner {
initialize(); initialize();
} }
private void initialize() { private static void initialize() {
if (engine == null) { if (engine == null) {
engine = new RobocodeEngine(); engine = new RobocodeEngine();
engine.addBattleListener(new BattleObserver()); engine.addBattleListener(new BattleObserver());
@ -228,7 +228,7 @@ public class BattlesRunner {
} }
@Override @Override
public void onBattleCompleted(final BattleCompletedEvent event) { public static void onBattleCompleted(final BattleCompletedEvent event) {
lastResults = RobotResults.convertResults(event.getSortedResults()); lastResults = RobotResults.convertResults(event.getSortedResults());
} }
} }

View File

@ -100,25 +100,25 @@ public class BotsDownload {
// delete previous files // delete previous files
if (generalbotsfile.length() != 0) { if (generalbotsfile.length() != 0) {
file = new File(generalbotsfile); file = new File(generalbotsfile);
if (file.exists() && !file.delete()) { if (file.exists() &&&& !file.delete()) {
Logger.logError("Can't delete file: " + file); Logger.logError("Can't delete file: " + file);
} }
} }
if (minibotsfile.length() != 0) { if (minibotsfile.length() != 0) {
file = new File(minibotsfile); file = new File(minibotsfile);
if (file.exists() && !file.delete()) { if (file.exists() &&&& !file.delete()) {
Logger.logError("Can't delete file: " + file); Logger.logError("Can't delete file: " + file);
} }
} }
if (microbotsfile.length() != 0) { if (microbotsfile.length() != 0) {
file = new File(microbotsfile); file = new File(microbotsfile);
if (file.exists() && !file.delete()) { if (file.exists() &&&& !file.delete()) {
Logger.logError("Can't delete file: " + file); Logger.logError("Can't delete file: " + file);
} }
} }
if (nanobotsfile.length() != 0) { if (nanobotsfile.length() != 0) {
file = new File(nanobotsfile); file = new File(nanobotsfile);
if (file.exists() && !file.delete()) { if (file.exists() &&&& !file.delete()) {
Logger.logError("Can't delete file: " + file); Logger.logError("Can't delete file: " + file);
} }
} }
@ -128,17 +128,17 @@ public class BotsDownload {
} }
boolean downloaded = true; boolean downloaded = true;
if (generalBots.length() != 0 && generalbotsfile.length() != 0) { if (generalBots.length() != 0 &&&& generalbotsfile.length() != 0) {
downloaded = downloadRatingsFile(generalBots, generalbotsfile) & downloaded; downloaded = downloadRatingsFile(generalBots, generalbotsfile) && downloaded;
} }
if (miniBots.length() != 0 && minibotsfile.length() != 0) { if (miniBots.length() != 0 &&&& minibotsfile.length() != 0) {
downloaded = downloadRatingsFile(miniBots, minibotsfile) & downloaded; downloaded = downloadRatingsFile(miniBots, minibotsfile) && downloaded;
} }
if (microBots.length() != 0 && microbotsfile.length() != 0) { if (microBots.length() != 0 &&&& microbotsfile.length() != 0) {
downloaded = downloadRatingsFile(microBots, microbotsfile) & downloaded; downloaded = downloadRatingsFile(microBots, microbotsfile) && downloaded;
} }
if (nanoBots.length() != 0 && nanobotsfile.length() != 0) { if (nanoBots.length() != 0 &&&& nanobotsfile.length() != 0) {
downloaded = downloadRatingsFile(nanoBots, nanobotsfile) & downloaded; downloaded = downloadRatingsFile(nanoBots, nanobotsfile) && downloaded;
} }
return downloaded; return downloaded;
} }
@ -207,7 +207,7 @@ public class BotsDownload {
final File dir = new File(participantsfile).getParentFile(); final File dir = new File(participantsfile).getParentFile();
if (!dir.exists() && !dir.mkdirs()) { if (!dir.exists() &&&& !dir.mkdirs()) {
Logger.logError("Can't create directory: " + dir); Logger.logError("Can't create directory: " + dir);
} }
@ -332,10 +332,10 @@ public class BotsDownload {
String sessionId = null; String sessionId = null;
if (id.indexOf("://") == -1) { if (id.indexOf("://") == -1) {
url = "http://robocoderepository.com/Controller.jsp?submitAction=downloadClass&id=" + id; url = "http://robocoderepository.com/Controller.jsp?submitAction=downloadClass&&id=" + id;
sessionId = FileTransfer.getSessionId( sessionId = FileTransfer.getSessionId(
"http://robocoderepository.com/BotSearch.jsp?botName=''&authorName=''&uploadDate="); "http://robocoderepository.com/BotSearch.jsp?botName=''&&authorName=''&&uploadDate=");
} else { } else {
url = id; url = id;
} }
@ -420,13 +420,13 @@ public class BotsDownload {
PrintStream outtxt = null; PrintStream outtxt = null;
try { try {
URL url = new URL(ratingsurl + "?version=1&game=" + competition); URL url = new URL(ratingsurl + "?version=1&&game=" + competition);
HttpURLConnection conn = FileTransfer.connectToHttpInputConnection(url); HttpURLConnection conn = FileTransfer.connectToHttpInputConnection(url);
final File dir = new File(file).getParentFile(); final File dir = new File(file).getParentFile();
if (!dir.exists() && !dir.mkdirs()) { if (!dir.exists() &&&& !dir.mkdirs()) {
Logger.logError("Can't create directory: " + dir); Logger.logError("Can't create directory: " + dir);
} }
@ -559,7 +559,7 @@ public class BotsDownload {
return; return;
} }
String data = "version=1&game=" + game + "&name=" + bot.trim() + "&dummy=NA"; String data = "version=1&&game=" + game + "&&name=" + bot.trim() + "&&dummy=NA";
OutputStream out = null; OutputStream out = null;
OutputStreamWriter outputStreamWriter = null; OutputStreamWriter outputStreamWriter = null;
@ -614,7 +614,6 @@ public class BotsDownload {
if (robot.matches("[\\w\\.]+[ ][\\w\\.-]+")) { if (robot.matches("[\\w\\.]+[ ][\\w\\.-]+")) {
if (link.startsWith("http")) { if (link.startsWith("http")) {
try { try {
new URL(link);
matches = true; matches = true;
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
matches = false; matches = false;

View File

@ -355,7 +355,7 @@ public class FileTransfer {
try { try {
in.close(); in.close();
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); LOGGER.log("context", e);
} }
} }
// Make sure the output stream is closed // Make sure the output stream is closed
@ -363,7 +363,7 @@ public class FileTransfer {
try { try {
out.close(); out.close();
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); LOGGER.log("context", e);
} }
} }
} }
@ -489,14 +489,14 @@ public class FileTransfer {
try { try {
in.close(); in.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOGGER.log("context", e);
} }
} }
if (out != null) { if (out != null) {
try { try {
out.close(); out.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOGGER.log("context", e);
} }
} }
} }

View File

@ -181,8 +181,8 @@ public class ResultsUpload {
String data = "game=" + game + commonData; String data = "game=" + game + commonData;
if (matchtype.equals("GENERAL") || matchtype.equals("SERVER")) { if (matchtype.equals("GENERAL") |||| matchtype.equals("SERVER")) {
errorsfound = errorsfound | senddata(game, data, outtxt, true, results, i, battlesnum, prioritybattles); errorsfound = errorsfound || senddata(game, data, outtxt, true, results, i, battlesnum, prioritybattles);
} }
if (sizesfile.length() != 0) { // upload also related competitions if (sizesfile.length() != 0) { // upload also related competitions
@ -190,18 +190,18 @@ public class ResultsUpload {
&& size.checkCompetitorsForSize(first[0], second[0], 1500)) { && size.checkCompetitorsForSize(first[0], second[0], 1500)) {
data = "game=" + minibots + commonData; data = "game=" + minibots + commonData;
errorsfound = errorsfound errorsfound = errorsfound
| senddata(minibots, data, outtxt, true, results, i, battlesnum, prioritybattles); || senddata(minibots, data, outtxt, true, results, i, battlesnum, prioritybattles);
} }
if (microbots.length() != 0 && !matchtype.equals("NANO") if (microbots.length() != 0 && !matchtype.equals("NANO")
&& size.checkCompetitorsForSize(first[0], second[0], 750)) { && size.checkCompetitorsForSize(first[0], second[0], 750)) {
data = "game=" + microbots + commonData; data = "game=" + microbots + commonData;
errorsfound = errorsfound errorsfound = errorsfound
| senddata(microbots, data, outtxt, true, results, i, battlesnum, prioritybattles); || senddata(microbots, data, outtxt, true, results, i, battlesnum, prioritybattles);
} }
if (nanobots.length() != 0 && size.checkCompetitorsForSize(first[0], second[0], 250)) { if (nanobots.length() != 0 && size.checkCompetitorsForSize(first[0], second[0], 250)) {
data = "game=" + nanobots + commonData; data = "game=" + nanobots + commonData;
errorsfound = errorsfound errorsfound = errorsfound
| senddata(nanobots, data, outtxt, true, results, i, battlesnum, prioritybattles); || senddata(nanobots, data, outtxt, true, results, i, battlesnum, prioritybattles);
} }
} }
} }

View File

@ -42,7 +42,7 @@ public final class PropertiesUtil {
try { try {
fis.close(); fis.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOGGER.log("context", e);
} }
} }
} }
@ -93,7 +93,7 @@ public final class PropertiesUtil {
try { try {
fos.close(); fos.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOGGER.log("context", e);
} }
} }
} }