Skip to content

Commit

Permalink
Remove command regeneration. Store the creation command and look it u…
Browse files Browse the repository at this point in the history
…p in every recreateCmd() call
  • Loading branch information
WilliamHaiweiGu committed Feb 18, 2023
1 parent 63ec68e commit c3a217f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 32 deletions.
13 changes: 1 addition & 12 deletions bugTracker
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
Known bugs
1.
Expected :[D][ ] Zul/by (by: [[`)uFR2zbRF#U[1@Y7L^Ct `mh_g.[Q2A|d~i>IkG4O}S`3jzW]])
Actual :[D][ ] Zul (by: [/by [`)uFR2zbRF#U[1@Y7L^Ct `mh_g.[Q2A|d~i>IkG4O}S`3jzW]])

deadline x/by /by t

2.
Expected :[E][ ] 3~8;W>"?(>8't"nBWbgfm'KF}#<+]14d/to (from: 1984-09-29 13:52 to: 1991-09-18 08:20)
Actual :[E][ ] 3~8;W>"?(>8't"nBWbgfm'KF}#<+]14d (from: [29091984 1352 /to 18091991 0820] to: [])

event x/to /from t
Known bugs
2 changes: 1 addition & 1 deletion src/main/java/MeggyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MeggyTest {

/** @return String that will never be entirely whitespace. */
private static String randString() {
final int strLenMax = 10;
final int strLenMax = 50;
final int printableCharRange = 95;
while (true) {
final int len = 1 + RAND.nextInt(strLenMax);
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/meggy/task/DdlTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ public class DdlTask extends UserTask {
public final MeggyTime due;

/**
* @param desc Non-null. Description string of task.
* @param due Non-null. Due time.
* @param desc Non-null. Description string of task.
* @param due Non-null. Due time.
* @param origin Non-null. The line (command removed) that created this task.
*/
private DdlTask(String desc, MeggyTime due) throws MeggyException {
super(desc);
private DdlTask(String desc, MeggyTime due, String origin) throws MeggyException {
super(desc, origin);
assert due != null;
this.due = due;
}

/**
* Factory method. Parses description and due time from arguments.
*
* @param args Non-null. User input line with command removed.
* @param args Non-null. The line (command and extra space removed) that created this task.
*/
public static DdlTask of(String args) throws MeggyException {
assert args != null;
Expand All @@ -43,13 +44,13 @@ public static DdlTask of(String args) throws MeggyException {
desc = args.substring(0, kwIdx).trim();
due = MeggyTime.of(args.substring(kwIdx + DUE_LEN));
}
return new DdlTask(desc, due);
return new DdlTask(desc, due, args);
}

/** @inheritDoc */
@Override
public String recreateCmd() {
return Resource.CMD_DDL + ' ' + desc + DUE_KEYWORD_FORMATTED + due.encode();
return Resource.CMD_DDL + ' ' + args;
}

/** Two {@link DdlTask} objects are equal iff they have same (non-null) description and due time. */
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/meggy/task/EventTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public class EventTask extends UserTask {
* @param desc Non-null. Parsed description string.
* @param start Non-null. Parsed start time.
* @param end Non-null. Parsed end time.
* @param args The line (command and extra space removed) that created this task.
*/
private EventTask(String desc, MeggyTime start, MeggyTime end) throws MeggyException {
super(desc);
private EventTask(String desc, MeggyTime start, MeggyTime end, String args) throws MeggyException {
super(desc, args);
assert start != null;
assert end != null;
this.start = start;
Expand All @@ -36,7 +37,7 @@ private EventTask(String desc, MeggyTime start, MeggyTime end) throws MeggyExcep
/**
* Factory method. Parses description, start time, and end time from arguments.
*
* @param args Non-null. User input line with command removed.
* @param args Non-null. The line (command and extra space removed) that created this task.
*/
public static EventTask of(String args) throws MeggyException {
assert args != null;
Expand Down Expand Up @@ -67,14 +68,13 @@ public static EventTask of(String args) throws MeggyException {
final String start = kwValue.get(START_KEYWORD_FORMATTED);
// If "end" keyword is in args, write to end time variable. Otherwise use default.
final String end = kwValue.get(END_KEYWORD_FORMATTED);
return new EventTask(desc.trim(), MeggyTime.of(start), MeggyTime.of(end));
return new EventTask(desc.trim(), MeggyTime.of(start), MeggyTime.of(end), args);
}

/** @inheritDoc */
@Override
public String recreateCmd() {
return Resource.CMD_EVENT + ' ' + desc + START_KEYWORD_FORMATTED + start.encode() + END_KEYWORD_FORMATTED +
end.encode();
return Resource.CMD_EVENT + ' ' + args;
}

/** @inheritDoc */
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/meggy/task/TodoTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ public class TodoTask extends UserTask {
/** Bracketed icon of task type. */
public static final String LABEL = getTaskTypeLabel(Resource.CMD_TODO);

/** @param desc Non-null. Description string of task with command removed. */
/** @param desc Non-null. Parsed description string. */
public TodoTask(String desc) throws MeggyException {
super(desc);
// In TodoTasks, args IS description.
super(desc, desc);
}

/** @inheritDoc */
@Override
public String recreateCmd() {
return Resource.CMD_TODO + ' ' + desc;
return Resource.CMD_TODO + ' ' + args;
}

/** @inheritDoc */
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/meggy/task/UserTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@
public abstract class UserTask {
/** Task description. */
public final String desc;
/** The line (command and extra space removed) that created this task. Stored to avoid repeated regeneration. */
final String args;
/** Task completion status. */
private boolean isDone;

/** @param desc Non-null. Description string of task with command removed. */
public UserTask(String desc) throws MeggyException {
/**
* @param desc Non-null. Description string of task with command removed.
* @param args Non-null. The line (command and extra space removed) that created this task.
*/
UserTask(String desc, String args) throws MeggyException {
assert desc != null;
assert args != null;
if (desc.isEmpty()) { // No arguments
throw new MeggyNoArgException();
}
this.desc = desc;
this.args = args;
isDone = false;
}

Expand Down Expand Up @@ -54,7 +61,7 @@ public void setDone(boolean done) {
isDone = done;
}

/** @return Re-create the command that would add the task. */
/** @return Re-create the entry line that would create the task. */
public abstract String recreateCmd();

/** @return The string representation of this task in text UI. */
Expand Down

0 comments on commit c3a217f

Please sign in to comment.