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

Commit 7a1f66e

Browse files
author
Aleksi Salmela
committed
Some minor improvements to WorkDir.
1 parent 6847ea5 commit 7a1f66e

1 file changed

Lines changed: 26 additions & 17 deletions

File tree

src/main/java/fi/helsinki/cs/tmc/cli/io/WorkDir.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,13 @@ public List<String> getExerciseNames() {
7373

7474
/**
7575
* Go through directories and return matching exercises.
76+
* @param exists Returns only exercises that aren't removed
77+
* @param onlyTested Return only exercises that are already tested
78+
* @param filterCompleted Remove the ones that are already completed
7679
* @return: return names of exercises as List
7780
*/
7881
public List<String> getExerciseNames(
79-
Boolean exists, Boolean onlyTested, Boolean filterCompleted) {
82+
boolean exists, boolean onlyTested, boolean filterCompleted) {
8083
if (this.directories.isEmpty() && getConfigFile() == null) {
8184
return new ArrayList<>();
8285
}
@@ -126,16 +129,25 @@ public List<String> getExerciseNames(
126129
return filteredExerciseNames;
127130
}
128131

129-
private Boolean filterExercise(Exercise exercise, List<String> tested,
130-
Boolean exists, Boolean onlyTested, Boolean filterCompleted) {
131-
if (!onlyTested || tested.contains(exercise.getName())) {
132-
if (!filterCompleted || !exercise.isCompleted()) {
133-
if (!exists || Files.exists(getCourseDirectory().resolve(exercise.getName()))) {
134-
return true;
135-
}
136-
}
132+
private boolean filterExercise(Exercise exercise, List<String> tested,
133+
boolean exists, boolean onlyTested, boolean filterCompleted) {
134+
if (onlyTested && !tested.contains(exercise.getName())) {
135+
return false;
137136
}
138-
return false;
137+
if (filterCompleted && exercise.isCompleted()) {
138+
return false;
139+
}
140+
if (exists && !Files.exists(getCourseDirectory().resolve(exercise.getName()))) {
141+
return false;
142+
}
143+
return true;
144+
}
145+
146+
/**
147+
* THIS IS ONLY FOR TESTS. DO NOT USE THIS OUTSIDE OF TESTS.
148+
*/
149+
public void setWorkdir(Path path) {
150+
this.workdir = path;
139151
}
140152

141153
/**
@@ -152,7 +164,7 @@ public Path getWorkingDirectory() {
152164
}
153165

154166
public List<Path> getDirectories() {
155-
return new ArrayList<Path>(this.directories);
167+
return new ArrayList<>(this.directories);
156168
}
157169

158170
/**
@@ -202,7 +214,7 @@ public int directoryCount() {
202214

203215
private Path findCourseDir(Path dir) {
204216
while (dir != null && Files.exists(dir)) {
205-
if (Files.exists(dir.resolve(CourseInfoIo.COURSE_CONFIG))) {
217+
if (isCourseDirectory(dir)) {
206218
return dir;
207219
}
208220
dir = dir.getParent();
@@ -218,10 +230,7 @@ private Path makeAbsolute(Path path) {
218230
}
219231
}
220232

221-
/**
222-
* THIS IS ONLY FOR TESTS. DO NOT USE THIS OUTSIDE OF TESTS.
223-
*/
224-
public void setWorkdir(Path path) {
225-
this.workdir = path;
233+
private boolean isCourseDirectory(Path dir) {
234+
return Files.exists(dir.resolve(CourseInfoIo.COURSE_CONFIG));
226235
}
227236
}

0 commit comments

Comments
 (0)