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

Commit a9d166e

Browse files
committed
Code style: imports, simplify and performance improvements
1 parent 33528aa commit a9d166e

36 files changed

+119
-202
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,8 @@ private boolean versionCheck() {
161161
}
162162

163163
Date now = new Date();
164-
if (previous != null && previous.getTime() + defaultUpdateInterval > now.getTime()) {
165-
return false;
166-
}
164+
return !(previous != null && previous.getTime() + defaultUpdateInterval > now.getTime()) && runAutoUpdate();
167165

168-
return runAutoUpdate();
169166
}
170167

171168
public boolean runAutoUpdate() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public int getAccountCount() {
7575
return this.accountArray.size();
7676
}
7777

78-
public List<Account> getAccountList() {
78+
private List<Account> getAccountList() {
7979
return Collections.unmodifiableList(this.accountArray);
8080
}
8181

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static CourseInfo load(Path courseInfoFile) {
4343
//Return null if file is not found, this is normal behaviour
4444
return null;
4545
}
46-
Reader reader = null;
46+
Reader reader;
4747
try {
4848
reader = Files.newBufferedReader(courseInfoFile, Charset.forName("UTF-8"));
4949
} catch (IOException e) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static boolean savePropertiesTo(HashMap<String, String> properties, Path
9494
* Get the correct directory in which our config files go
9595
* ie /home/user/.config/tmc-cli/.
9696
*/
97-
protected static Path getConfigDirectory() {
97+
static Path getConfigDirectory() {
9898
Path configPath;
9999
if (EnvironmentUtil.isWindows()) {
100100
String appdata = System.getenv("APPDATA");
@@ -123,7 +123,8 @@ private static Path getAccountsFile(Path configRoot) {
123123
if (!Files.exists(configRoot)) {
124124
try {
125125
Files.createDirectories(configRoot).getParent();
126-
} catch (Exception e) { }
126+
} catch (IOException e) {
127+
}
127128
try {
128129
Files.createFile(configRoot);
129130
} catch (Exception e) { }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static List<Course> listCourses(CliContext ctx) {
8282
return new ArrayList<>();
8383
}
8484

85-
public static Course getDetails(CliContext ctx, Course course) {
85+
private static Course getDetails(CliContext ctx, Course course) {
8686
try {
8787
TmcCore core = ctx.getTmcCore();
8888
return core.getCourseDetails(ProgressObserver.NULL_OBSERVER, course).call();
@@ -213,7 +213,7 @@ public static boolean sendFeedback(CliContext ctx, List<FeedbackAnswer> answers,
213213
}
214214
}
215215

216-
protected static void handleTmcExceptions(CliContext ctx, Exception exception) {
216+
private static void handleTmcExceptions(CliContext ctx, Exception exception) {
217217
Io io = ctx.getIo();
218218
Throwable cause = exception.getCause();
219219

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private String getExercisesAsString(String courseName, List<Exercise> exercises)
133133
for (Exercise exercise : exercises) {
134134
String deadline = getDeadline(exercise);
135135
if (!deadline.equals(prevDeadline)) {
136-
sb.append("\nDeadline: " + deadline + "\n");
136+
sb.append("\nDeadline: ").append(deadline).append("\n");
137137
prevDeadline = deadline;
138138
}
139139
sb.append(getExerciseStatus(exercise));

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ public void getOptions(Options options) {
3535

3636
@Override
3737
public void run(CliContext context, CommandLine args) {
38-
CliContext ctx = context;
39-
this.io = ctx.getIo();
40-
if (!ctx.loadBackend()) {
38+
this.io = context.getIo();
39+
if (!context.loadBackend()) {
4140
return;
4241
}
43-
WorkDir workdir = ctx.getWorkDir();
42+
WorkDir workdir = context.getWorkDir();
4443
String[] stringArgs = args.getArgs();
4544

4645
Boolean valid;
@@ -85,9 +84,9 @@ public void run(CliContext context, CommandLine args) {
8584
}
8685

8786
String exerciseName = exercisenames.get(0);
88-
CourseInfo info = ctx.getCourseInfo();
87+
CourseInfo info = context.getCourseInfo();
8988
Exercise exercise = info.getExercise(exerciseName);
90-
URI uri = TmcUtil.sendPaste(ctx, exercise, message);
89+
URI uri = TmcUtil.sendPaste(context, exercise, message);
9190
if (uri == null && exercise.hasDeadlinePassed()) {
9291
io.println("Unable to send the paste."
9392
+ " The deadline for submitting this exercise has passed");

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ public void getOptions(Options options) {
2828

2929
@Override
3030
public void run(CliContext context, CommandLine args) {
31-
CliContext ctx = context;
32-
this.io = ctx.getIo();
31+
this.io = context.getIo();
3332

3433
boolean unset = args.hasOption("u");
3534
String[] arguments = args.getArgs();
36-
HashMap<String, String> props = ctx.getProperties();
35+
HashMap<String, String> props = context.getProperties();
3736
if (arguments.length == 0) {
3837
printAllProps(props);
3938
return;
@@ -75,7 +74,7 @@ public void run(CliContext context, CommandLine args) {
7574
+ ", was " + last);
7675
}
7776
}
78-
ctx.saveProperties();
77+
context.saveProperties();
7978
}
8079

8180
private void printAllProps(HashMap<String, String> props) {
@@ -94,7 +93,7 @@ private void printAllProps(HashMap<String, String> props) {
9493

9594
for (String key : array) {
9695
sb = new StringBuilder();
97-
sb.append(key + ":");
96+
sb.append(key).append(":");
9897
for (int i = key.length() + 1; i < Math.max(longest + 1, 7); i++) {
9998
sb.append(" ");
10099
}

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,18 @@ public void getOptions(Options options) {
4141

4242
@Override
4343
public void run(CliContext context, CommandLine args) {
44-
CliContext ctx = context;
45-
Io io = ctx.getIo();
44+
Io io = context.getIo();
4645

4746
String[] exercisesFromArgs = parseArgs(args);
4847
if (exercisesFromArgs == null) {
4948
return;
5049
}
5150

52-
if (!ctx.loadBackendWithoutLogin()) {
51+
if (!context.loadBackendWithoutLogin()) {
5352
return;
5453
}
5554

56-
WorkDir workDir = ctx.getWorkDir();
55+
WorkDir workDir = context.getWorkDir();
5756
for (String exercise : exercisesFromArgs) {
5857
if (!workDir.addPath(exercise)) {
5958
io.println("Error: " + exercise + " is not a valid exercise.");
@@ -67,10 +66,10 @@ public void run(CliContext context, CommandLine args) {
6766
return;
6867
}
6968

70-
CourseInfo info = ctx.getCourseInfo();
69+
CourseInfo info = context.getCourseInfo();
7170

72-
Color passedColor = ctx.getApp().getColor("testresults-left");
73-
Color failedColor = ctx.getApp().getColor("testresults-right");
71+
Color passedColor = context.getApp().getColor("testresults-left");
72+
Color failedColor = context.getApp().getColor("testresults-right");
7473
ResultPrinter resultPrinter = new ResultPrinter(io, showDetails, showPassed,
7574
passedColor, failedColor);
7675

@@ -80,14 +79,14 @@ public void run(CliContext context, CommandLine args) {
8079
io.println(ColorUtil.colorString("Testing: " + name, Color.YELLOW));
8180
Exercise exercise = info.getExercise(name);
8281

83-
RunResult runResult = TmcUtil.runLocalTests(ctx, exercise);
82+
RunResult runResult = TmcUtil.runLocalTests(context, exercise);
8483
if (runResult == null) {
8584
io.println("Failed to run test");
8685
resultPrinter.addFailedExercise();
8786
continue;
8887
}
8988

90-
ValidationResult valResult = TmcUtil.runCheckStyle(ctx, exercise);
89+
ValidationResult valResult = TmcUtil.runCheckStyle(context, exercise);
9190
boolean testsPassed = resultPrinter.printLocalTestResult(
9291
runResult, valResult, isOnlyExercise);
9392

src/main/java/fi/helsinki/cs/tmc/cli/core/AbstractCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract class AbstractCommand {
2020
*
2121
* @return Description text
2222
*/
23-
public String getDescription() {
23+
protected String getDescription() {
2424
return null;
2525
}
2626

@@ -52,7 +52,7 @@ public void execute(CliContext context, String[] stringArgs) {
5252
}
5353
}
5454

55-
public CommandLine parseArgs(CliContext context, String[] stringArgs) {
55+
protected CommandLine parseArgs(CliContext context, String[] stringArgs) {
5656
GnuParser parser = new GnuParser();
5757
CommandLine args;
5858
Options options = getOptions();

0 commit comments

Comments
 (0)