Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit fb16358

Browse files
committed
Code style and format
1 parent a9d166e commit fb16358

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+588
-545
lines changed

src/main/java/fi/helsinki/cs/tmc/cli/Application.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private String[] parseArgs(String[] args) {
101101
runCommand("help", new String[0]);
102102
return null;
103103
}
104-
runCommand(commandName, new String[]{"-h"});
104+
runCommand(commandName, new String[] {"-h"});
105105
return null;
106106
}
107107
if (showVersion) {
@@ -161,15 +161,16 @@ private boolean versionCheck() {
161161
}
162162

163163
Date now = new Date();
164-
return !(previous != null && previous.getTime() + defaultUpdateInterval > now.getTime()) && runAutoUpdate();
165-
164+
return !(previous != null && previous.getTime() + defaultUpdateInterval > now.getTime())
165+
&& runAutoUpdate();
166166
}
167167

168168
public boolean runAutoUpdate() {
169169
Map<String, String> properties = context.getProperties();
170170
Date now = new Date();
171-
AutoUpdater update = AutoUpdater.createUpdater(io,
172-
EnvironmentUtil.getVersion(), EnvironmentUtil.isWindows());
171+
AutoUpdater update =
172+
AutoUpdater.createUpdater(
173+
io, EnvironmentUtil.getVersion(), EnvironmentUtil.isWindows());
173174
boolean updated = update.run();
174175

175176
long timestamp = now.getTime();
@@ -185,11 +186,16 @@ public Color getColor(String propertyName) {
185186
Color color = ColorUtil.getColor(propertyValue);
186187
if (color == null) {
187188
switch (propertyName) {
188-
case "progressbar-left": return Color.CYAN;
189-
case "progressbar-right": return Color.CYAN;
190-
case "testresults-left": return Color.GREEN;
191-
case "testresults-right": return Color.RED;
192-
default: return Color.NONE;
189+
case "progressbar-left":
190+
return Color.CYAN;
191+
case "progressbar-right":
192+
return Color.CYAN;
193+
case "testresults-left":
194+
return Color.GREEN;
195+
case "testresults-right":
196+
return Color.RED;
197+
default:
198+
return Color.NONE;
193199
}
194200
}
195201
return color;

src/main/java/fi/helsinki/cs/tmc/cli/backend/Account.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Account {
1212
private String password;
1313

1414
// for gson
15-
public Account() { }
15+
public Account() {}
1616

1717
public Account(String serverAddress, String username, String password) {
1818
this.serverAddress = serverAddress;

src/main/java/fi/helsinki/cs/tmc/cli/backend/CourseInfoIo.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ public static CourseInfo load(Path courseInfoFile) {
5454
}
5555

5656
public static void createNewCourse(Course course, Account account, Path parentDir) {
57-
Path configFile = parentDir
58-
.resolve(course.getName())
59-
.resolve(CourseInfoIo.COURSE_CONFIG);
57+
Path configFile = parentDir.resolve(course.getName()).resolve(CourseInfoIo.COURSE_CONFIG);
6058

6159
CourseInfo info = new CourseInfo(account, course);
6260
info.setExercises(course.getExercises());

src/main/java/fi/helsinki/cs/tmc/cli/backend/Settings.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@ public Path getConfigRoot() {
116116
}
117117

118118
@Override
119-
public void setCourse(Course course) {
120-
}
119+
public void setCourse(Course course) {}
121120

122121
@Override
123-
public void setConfigRoot(Path path) {
124-
}
122+
public void setConfigRoot(Path path) {}
125123
}

src/main/java/fi/helsinki/cs/tmc/cli/backend/SettingsIo.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ static Path getConfigDirectory() {
110110
if (configEnv != null && configEnv.length() > 0) {
111111
configPath = Paths.get(configEnv);
112112
} else {
113-
configPath = Paths.get(System.getProperty("user.home"))
114-
.resolve(".config");
113+
configPath = Paths.get(System.getProperty("user.home")).resolve(".config");
115114
}
116115
}
117116
return configPath.resolve(CONFIG_DIR);
@@ -127,7 +126,8 @@ private static Path getAccountsFile(Path configRoot) {
127126
}
128127
try {
129128
Files.createFile(configRoot);
130-
} catch (Exception e) { }
129+
} catch (Exception e) {
130+
}
131131
}
132132
return file;
133133
}
@@ -138,10 +138,12 @@ private static Path getPropertiesFile(Path configRoot) {
138138
if (!Files.exists(configRoot)) {
139139
try {
140140
Files.createDirectories(configRoot).getParent();
141-
} catch (Exception e) { }
141+
} catch (Exception e) {
142+
}
142143
try {
143144
Files.createFile(configRoot);
144-
} catch (Exception e) { }
145+
} catch (Exception e) {
146+
}
145147
}
146148
return file;
147149
}

src/main/java/fi/helsinki/cs/tmc/cli/backend/TmcUtil.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public static Exercise findExercise(Course course, String name) {
118118
return null;
119119
}
120120

121-
public static List<Exercise> downloadExercises(CliContext ctx, List<Exercise> exercises,
122-
ProgressObserver progobs) {
121+
public static List<Exercise> downloadExercises(
122+
CliContext ctx, List<Exercise> exercises, ProgressObserver progobs) {
123123
try {
124124
TmcCore core = ctx.getTmcCore();
125125
return core.downloadOrUpdateExercises(progobs, exercises).call();
@@ -130,8 +130,8 @@ public static List<Exercise> downloadExercises(CliContext ctx, List<Exercise> ex
130130
}
131131
}
132132

133-
public static List<Exercise> downloadAllExercises(CliContext ctx, Course course,
134-
ProgressObserver progobs) {
133+
public static List<Exercise> downloadAllExercises(
134+
CliContext ctx, Course course, ProgressObserver progobs) {
135135
if (!course.isExercisesLoaded()) {
136136
course = getDetails(ctx, course);
137137
}
@@ -150,12 +150,10 @@ public static SubmissionResult submitExercise(CliContext ctx, Exercise exercise)
150150
}
151151
}
152152

153-
public static UpdateResult getUpdatableExercises(
154-
CliContext ctx, Course course) {
153+
public static UpdateResult getUpdatableExercises(CliContext ctx, Course course) {
155154
try {
156155
TmcCore core = ctx.getTmcCore();
157-
return core.getExerciseUpdates(ProgressObserver.NULL_OBSERVER, course)
158-
.call();
156+
return core.getExerciseUpdates(ProgressObserver.NULL_OBSERVER, course).call();
159157
} catch (Exception e) {
160158
TmcUtil.handleTmcExceptions(ctx, e);
161159
logger.warn("Failed to get exercise updates.", e);
@@ -166,8 +164,7 @@ public static UpdateResult getUpdatableExercises(
166164
public static URI sendPaste(CliContext ctx, Exercise exercise, String message) {
167165
try {
168166
TmcCore core = ctx.getTmcCore();
169-
return core.pasteWithComment(ProgressObserver.NULL_OBSERVER,
170-
exercise, message).call();
167+
return core.pasteWithComment(ProgressObserver.NULL_OBSERVER, exercise, message).call();
171168

172169
} catch (Exception e) {
173170
TmcUtil.handleTmcExceptions(ctx, e);
@@ -199,12 +196,11 @@ public static ValidationResult runCheckStyle(CliContext ctx, Exercise exercise)
199196
}
200197
}
201198

202-
public static boolean sendFeedback(CliContext ctx, List<FeedbackAnswer> answers,
203-
URI feedbackUri) {
199+
public static boolean sendFeedback(
200+
CliContext ctx, List<FeedbackAnswer> answers, URI feedbackUri) {
204201
try {
205202
TmcCore core = ctx.getTmcCore();
206-
return core.sendFeedback(ProgressObserver.NULL_OBSERVER, answers,
207-
feedbackUri).call();
203+
return core.sendFeedback(ProgressObserver.NULL_OBSERVER, answers, feedbackUri).call();
208204

209205
} catch (Exception e) {
210206
TmcUtil.handleTmcExceptions(ctx, e);
@@ -244,8 +240,7 @@ private static void handleTmcExceptions(CliContext ctx, Exception exception) {
244240
private static boolean isAuthenticationError(Exception exception) {
245241
Throwable cause = exception.getCause();
246242
if (cause instanceof FailedHttpResponseException) {
247-
FailedHttpResponseException httpEx
248-
= (FailedHttpResponseException) cause;
243+
FailedHttpResponseException httpEx = (FailedHttpResponseException) cause;
249244
if (httpEx.getStatusCode() == 401) {
250245
return true;
251246
}

src/main/java/fi/helsinki/cs/tmc/cli/command/DocumentCommand.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
@Command(name = "document", desc = "Show lots of boring info about tmc-cli")
2020
public class DocumentCommand extends AbstractCommand {
2121

22-
private static final String ERROR_MESSAGE = ""
23-
+ "Exception in thread \"main\" java.lang.NullPointerException\n"
24-
+ "\tat fi.helsinki.cs.tmc.cli.command.EasterEggCommand.run("
25-
+ "DocumentCommand.java:78)\n"
26-
+ "\tat fi.helsinki.cs.tmc.cli.command.core.AbstractCommand.execute("
27-
+ "AbstractCommand.java:63)\n"
28-
+ "\tat fi.helsinki.cs.tmc.cli.Application.runCommand(Application.java:71)\n"
29-
+ "\tat fi.helsinki.cs.tmc.cli.Application.run(Application.java:129)\n"
30-
+ "\tat fi.helsinki.cs.tmc.cli.Application.main(Application.java:138)\n"
31-
+ "Exception in thread \"Thread-0\" java.lang.NullPointerException\n"
32-
+ "\tat fi.helsinki.cs.tmc.cli.io.ShutdownHandler.run(ShutdownHandler.java:18)";
22+
private static final String ERROR_MESSAGE =
23+
""
24+
+ "Exception in thread \"main\" java.lang.NullPointerException\n"
25+
+ "\tat fi.helsinki.cs.tmc.cli.command.EasterEggCommand.run("
26+
+ "DocumentCommand.java:78)\n"
27+
+ "\tat fi.helsinki.cs.tmc.cli.command.core.AbstractCommand.execute("
28+
+ "AbstractCommand.java:63)\n"
29+
+ "\tat fi.helsinki.cs.tmc.cli.Application.runCommand(Application.java:71)\n"
30+
+ "\tat fi.helsinki.cs.tmc.cli.Application.run(Application.java:129)\n"
31+
+ "\tat fi.helsinki.cs.tmc.cli.Application.main(Application.java:138)\n"
32+
+ "Exception in thread \"Thread-0\" java.lang.NullPointerException\n"
33+
+ "\tat fi.helsinki.cs.tmc.cli.io.ShutdownHandler.run(ShutdownHandler.java:18)";
3334
private Io io;
3435
private int width;
3536
private int height;
@@ -141,8 +142,10 @@ public void run(CliContext context, CommandLine args) {
141142
setCursor(0, 0);
142143
io.print("\u001B[0J");
143144

144-
blitter(ColorUtil.colorString("Original dev team", Color.BLUE),
145-
Math.max(centerX - 10, 0), centerY - 2);
145+
blitter(
146+
ColorUtil.colorString("Original dev team", Color.BLUE),
147+
Math.max(centerX - 10, 0),
148+
centerY - 2);
146149
blitter("Johannes L. (jclc)", centerX, centerY++);
147150
centerY++;
148151
blitter("Juha V. (juvester)", centerX, centerY++);
@@ -158,8 +161,10 @@ public void run(CliContext context, CommandLine args) {
158161
io.print("\u001B[0J");
159162

160163
centerY = height / 2 - 3;
161-
blitter(ColorUtil.colorString("Special thanks for", Color.CYAN),
162-
Math.max(centerX - 10, 0), centerY - 2);
164+
blitter(
165+
ColorUtil.colorString("Special thanks for", Color.CYAN),
166+
Math.max(centerX - 10, 0),
167+
centerY - 2);
163168
blitter("Jarmo Isotalo (Jamo)", centerX, centerY++);
164169
centerY++;
165170
blitter("Kati Kyllönen (kxkyll)", centerX, centerY++);
@@ -324,8 +329,7 @@ private String trim(String line, int start, int end) {
324329
}
325330
for (i++; i < line.length(); i++) {
326331
char lineChar = line.charAt(i);
327-
if ((lineChar >= 'a' && lineChar <= 'z')
328-
|| (lineChar >= 'A' && lineChar <= 'Z')) {
332+
if ((lineChar >= 'a' && lineChar <= 'z') || (lineChar >= 'A' && lineChar <= 'Z')) {
329333
break;
330334
}
331335
}
@@ -336,4 +340,4 @@ private String trim(String line, int start, int end) {
336340
}
337341
return line;
338342
}
339-
}
343+
}

src/main/java/fi/helsinki/cs/tmc/cli/command/DownloadExercisesCommand.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ public class DownloadExercisesCommand extends AbstractCommand {
2929

3030
@Override
3131
public void getOptions(Options options) {
32-
options.addOption("a", "all", false,
32+
options.addOption(
33+
"a",
34+
"all",
35+
false,
3336
"Download all available exercises, including previously completed");
3437

3538
// Download old submissions. Not implemented in tmc-core yet
@@ -84,8 +87,7 @@ public void run(CliContext context, CommandLine args) {
8487

8588
printStatistics(course, filtered.size(), exercises.size());
8689

87-
CourseInfoIo.createNewCourse(course, finder.getAccount(),
88-
workDir.getWorkingDirectory());
90+
CourseInfoIo.createNewCourse(course, finder.getAccount(), workDir.getWorkingDirectory());
8991
}
9092

9193
private List<Exercise> getFilteredExercises(Course course) {
@@ -112,19 +114,21 @@ private void printStatistics(Course course, int requestCount, int downloadCount)
112114
io.println("The '" + courseName + "' course doesn't have any exercises.");
113115
} else {
114116
int totalCount = course.getExercises().size();
115-
io.println("The '" + courseName + "' course has "
116-
+ totalCount + " exercises available");
117+
io.println(
118+
"The '" + courseName + "' course has " + totalCount + " exercises available");
117119

118120
int failedCount = (requestCount - downloadCount);
119121
if (failedCount > 0) {
120-
io.println(" of which " + (requestCount - failedCount)
121-
+ " exercises were succesfully downloaded");
122-
io.println(ColorUtil.colorString(" and of which " + failedCount + " failed.",
123-
Color.RED));
122+
io.println(
123+
" of which "
124+
+ (requestCount - failedCount)
125+
+ " exercises were succesfully downloaded");
126+
io.println(
127+
ColorUtil.colorString(
128+
" and of which " + failedCount + " failed.", Color.RED));
124129
//TODO we could print the names of the not downloaded exercises here
125130
} else {
126-
io.println(" of which "
127-
+ downloadCount + " exercises were downloaded.");
131+
io.println(" of which " + downloadCount + " exercises were downloaded.");
128132
}
129133
if (!showAll && totalCount != downloadCount) {
130134
io.println("Use -a/--all to download completed exercises as well.");

src/main/java/fi/helsinki/cs/tmc/cli/command/HelpCommand.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public class HelpCommand extends AbstractCommand {
2121
private Io io;
2222

2323
@Override
24-
public void getOptions(Options options) {
25-
}
24+
public void getOptions(Options options) {}
2625

2726
@Override
2827
public void run(CliContext context, CommandLine args) {
@@ -57,7 +56,7 @@ private List<String> getCommandStrings() {
5756

5857
@SuppressWarnings("unchecked")
5958
private Class<Command> castToCommandClass(Class klass) {
60-
return (Class<Command>)klass;
59+
return (Class<Command>) klass;
6160
}
6261

6362
private String createCommandString(Command command) {
@@ -78,4 +77,4 @@ private int longestName(Set<Class<Command>> commandList) {
7877
}
7978
return longest;
8079
}
81-
}
80+
}

src/main/java/fi/helsinki/cs/tmc/cli/command/InfoCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ private void printInfoFromInternet(String courseName) {
8080
private void printLocalInfo(String[] stringArgs) {
8181
info = ctx.getCourseInfo();
8282
if (info == null) {
83-
io.println("You have to be in a course directory"
84-
+ " or use the -i option with the course name "
85-
+ "to get the information from the server.");
83+
io.println(
84+
"You have to be in a course directory"
85+
+ " or use the -i option with the course name "
86+
+ "to get the information from the server.");
8687
return;
8788
}
8889

@@ -118,8 +119,7 @@ private void printInfoFromParameters(String pathName) {
118119
printCourse(course);
119120
} else {
120121
io.println("Not a course directory. ");
121-
io.println("Use the -i option to get course from "
122-
+ "server.");
122+
io.println("Use the -i option to get course from " + "server.");
123123
}
124124
}
125125

0 commit comments

Comments
 (0)