Skip to content

Commit

Permalink
Merge pull request #249 from AY1920S2-CS2103T-F11-2/Refactor-Exercise…
Browse files Browse the repository at this point in the history
…-code

[Refactor] Add getValue() to Exercise classes to reduce sore eyes
  • Loading branch information
Yonggiee committed Apr 10, 2020
2 parents 117a508 + ac52de8 commit bfca19e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/exercise/ExerciseDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public long forPlot() {
return value.toEpochDay();
}

public LocalDate getValue() {
return value;
}

@Override
public String toString() {
return this.value.format(DateTimeFormatter.ofPattern("dd-MM-yyyy"));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/exercise/ExerciseName.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public static boolean isValidExerciseName(String test) {
return test.matches(VALIDATION_REGEX);
}

public String getValue() {
return value;
}

@Override
public String toString() {
return value;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/exercise/ExerciseReps.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public int convertToInt() {
return Integer.parseInt(value);
}

public String getValue() {
return value;
}

@Override
public String toString() {
return value;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/exercise/ExerciseSets.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public static boolean isValidExerciseSets(String test) {
return test.equals(EMPTY_STRING) || test.matches(VALIDATION_REGEX);
}

public String getValue() {
return value;
}

@Override
public String toString() {
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public int convertToInt() {
return Integer.parseInt(value);
}

public String getValue() {
return value;
}

@Override
public String toString() {
return value;
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/seedu/address/model/exercise/UniqueExerciseList.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public boolean contains(Exercise toCheck) {
public boolean containsNameWithinDate(ExerciseName toCheck, StartDate startDate, EndDate endDate) {
requireNonNull(toCheck);
return internalList.stream()
.filter(exercise -> (exercise.getExerciseDate().value.compareTo(startDate.value) >= 0))
.filter(exercise -> (exercise.getExerciseDate().value.compareTo(endDate.value) <= 0))
.anyMatch(exercise -> exercise.getExerciseName().value.equals(toCheck.value));
.filter(exercise -> (exercise.getExerciseDate().getValue().compareTo(startDate.value) >= 0))
.filter(exercise -> (exercise.getExerciseDate().getValue().compareTo(endDate.value) <= 0))
.anyMatch(exercise -> exercise.getExerciseName().getValue().equals(toCheck.getValue()));
}

/**
Expand Down Expand Up @@ -95,15 +95,17 @@ public void addToSorted(Exercise toAdd) {
}

int idx = 0;
LocalDate toAddDate = toAdd.getExerciseDate().value;
String toAddName = toAdd.getExerciseName().value.toLowerCase();
LocalDate toAddDate = toAdd.getExerciseDate().getValue();
String toAddName = toAdd.getExerciseName().getValue().toLowerCase();
for (Exercise curr : internalList) {
LocalDate currDate = curr.getExerciseDate().value;
String currName = curr.getExerciseName().value.toLowerCase();
if (toAddDate.compareTo(currDate) > 0) {
LocalDate currDate = curr.getExerciseDate().getValue();
String currName = curr.getExerciseName().getValue().toLowerCase();

int dateComparision = toAddDate.compareTo(currDate);
if (dateComparision > 0) {
// already at correct position
break;
} else if (toAddDate.compareTo(currDate) == 0) {
} else if (dateComparision == 0) {
// sort by name
if (toAddName.compareTo(currName) <= 0) {
break;
Expand Down Expand Up @@ -147,10 +149,10 @@ public void setExercise(Exercise target, Exercise editedExercise) {
*/
public void sortByExerciseDateAndName() {
Comparator<Exercise> byExerciseDate = (Exercise e1, Exercise e2) -> {
LocalDate e1Date = e1.getExerciseDate().value;
LocalDate e2Date = e2.getExerciseDate().value;
String e1Name = e1.getExerciseName().value.toUpperCase();
String e2Name = e2.getExerciseName().value.toUpperCase();
LocalDate e1Date = e1.getExerciseDate().getValue();
LocalDate e2Date = e2.getExerciseDate().getValue();
String e1Name = e1.getExerciseName().getValue().toUpperCase();
String e2Name = e2.getExerciseName().getValue().toUpperCase();
if (e2Date.compareTo(e1Date) == 0) {
return e1Name.compareTo(e2Name);
}
Expand Down

0 comments on commit bfca19e

Please sign in to comment.