Skip to content

Commit

Permalink
Improve readability of mass operations
Browse files Browse the repository at this point in the history
  • Loading branch information
yisiox committed Feb 18, 2024
1 parent d976292 commit db5efaf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/main/java/earl/logic/DeleteHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ public void handle(TaskList tasks, Ui ui) throws EarlException {
+ "valid indices in range.");
return;
}

for (int idx : indices) {
addDisplayEntry(idx + 1 + "." + tasks.delete(idx));
}
addDisplayEntry("Item(s) heretofore have been expunged.");
ui.makeResponse(getDisplay());

ui.makeResponse(getDisplayEntriesReversed());
} catch (ParserException e) {
throw new EarlException(
"The indices' format is fraught with invalidity."
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/earl/logic/MarkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void handle(TaskList tasks, Ui ui) throws EarlException {
+ "valid indices in range.");
return;
}

for (int idx : indices) {
boolean success = tasks.get(idx).markAsDone();
String feedback = idx + 1 + "." + tasks.get(idx);
Expand All @@ -35,7 +36,8 @@ public void handle(TaskList tasks, Ui ui) throws EarlException {
addDisplayEntry(feedback);
}
addDisplayEntry("Item(s) duly accomplished.");
ui.makeResponse(getDisplay());

ui.makeResponse(getDisplayEntriesReversed());
} catch (ParserException e) {
throw new EarlException(
"The indices' format is fraught with invalidity."
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/earl/logic/MassOperableHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ protected void addDisplayEntry(String entry) {
modifiedItems.add(entry);
}

protected String[] getDisplay() {
// Returns the added display entries in reversed order
protected String[] getDisplayEntriesReversed() {
Collections.reverse(modifiedItems);
String[] result = modifiedItems.toArray(String[]::new);
modifiedItems.clear();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/earl/logic/UnmarkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void handle(TaskList tasks, Ui ui) throws EarlException {
+ "valid indices in range.");
return;
}

for (int idx : indices) {
boolean success = tasks.get(idx).markUndone();
String feedback = idx + 1 + "." + tasks.get(idx);
Expand All @@ -33,7 +34,8 @@ public void handle(TaskList tasks, Ui ui) throws EarlException {
addDisplayEntry(feedback);
}
addDisplayEntry("Item(s) persist as undone.");
ui.makeResponse(getDisplay());

ui.makeResponse(getDisplayEntriesReversed());
} catch (ParserException e) {
throw new EarlException(
"The indices' format is fraught with invalidity."
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/earl/util/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public int getSize() {
public Task get(int i) {
return tasks.get(i);
}

/** Returns the added task itself. */
public void add(Task task) {
tasks.add(task);
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/earl/util/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private void setPrevResponse(String... arr) {
response = arr;
}

/** Displays a horizontal divider for TUI mode. */
/** Displays a horizontal divider for CLI mode. */
private static void printDivider() {
System.out.println(PADDING + DIVIDER);
}
Expand Down Expand Up @@ -84,8 +84,7 @@ public String appendNewline(String line) {
/**
* Returns the previous response made for GUI interactions.
*
* @return the previous response appearing as it would on a
* text based UI
* @return the previous response appearing as it would on a CLI
*/
public String getResponse() {
int n = response.length;
Expand Down

0 comments on commit db5efaf

Please sign in to comment.