Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up the codebase #146

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/main/java/trackitnus/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ public interface Logic {
* @param code The module code to query
* @return the list of contacts for a specific module
*/
public ObservableList<Contact> getModuleContacts(Code code);
ObservableList<Contact> getModuleContacts(Code code);

// ObservableList<Task> getOverdueTasks(LocalDate date);

/**
* @param code The module code to query
* @return the list of task for a specific module
*/
ObservableList<Task> getModuleTasks(Code code); // TODO: check if the list of tasks has been sorted in the
// correct order
ObservableList<Task> getModuleTasks(Code code);

/**
* @return the list of all tasks that take place on and after the current day
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/trackitnus/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public ObservableList<Lesson> getFilteredLessonList() {
}

//--------------------------------START of V1.3's new functions--------------------------------
// TODO:
// All the current functions are just dummy implementations
// All functions should only generate new predicates and use the corresponding getFilteredList to return
@Override
public ObservableList<Lesson> getUpcomingLessons() {
return model.getUpcomingLessons();
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/trackitnus/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ public ObservableList<Lesson> getFilteredLessonList() {
}

//--------------------------------START of V1.3's new functions--------------------------------
// TODO:
// All the current functions are just dummy implementations
// All functions should only generate new predicates and use the corresponding getFilteredList to return
@Override
public ObservableList<Lesson> getUpcomingLessons() {
sortLesson();
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/trackitnus/model/TrackIter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;

import java.util.List;
import java.util.Objects;

import javafx.collections.ObservableList;
import trackitnus.model.contact.Contact;
Expand Down Expand Up @@ -253,10 +254,15 @@ public void removeLesson(Lesson key) {

//// util methods


@Override
public String toString() {
return contacts.asUnmodifiableObservableList().size() + " contacts";
// TODO: refine later
return "TrackIter{" +
"contacts=" + contacts +
", modules=" + modules +
", tasks=" + tasks +
", lessons=" + lessons +
'}';
}

@Override
Expand Down Expand Up @@ -307,8 +313,7 @@ private void sortAll() {

@Override
public int hashCode() {
return contacts.hashCode();
// TODO: refine later
return Objects.hash(contacts, modules, tasks, lessons);
}

public void sortLesson() {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/trackitnus/model/commons/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Name {
*/
public static final String VALIDATION_REGEX = "[^/ ][^/]+";

public final String fullName;
public final String value;

/**
* Constructs a {@code Name}.
Expand All @@ -29,7 +29,7 @@ public class Name {
public Name(String name) {
requireNonNull(name);
AppUtil.checkArgument(isValidName(name), MESSAGE_CONSTRAINTS);
fullName = name;
value = name;
}

/**
Expand All @@ -42,19 +42,19 @@ public static boolean isValidName(String test) {

@Override
public String toString() {
return fullName;
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Name // instanceof handles nulls
&& fullName.equals(((Name) other).fullName)); // state check
&& value.equals(((Name) other).value)); // state check
}

@Override
public int hashCode() {
return fullName.hashCode();
return value.hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public NameContainsKeywordsPredicate(List<String> keywords) {
@Override
public boolean test(Contact contact) {
return keywords.stream()
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(contact.getName().fullName, keyword));
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(contact.getName().value, keyword));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public NameContainsKeywordsPredicate(List<String> keywords) {
@Override
public boolean test(Task task) {
return keywords.stream()
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(task.getName().fullName, keyword));
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(task.getName().value, keyword));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/trackitnus/model/task/TaskComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TaskComparator implements Comparator<Task> {
public int compare(Task t1, Task t2) {
int res = t1.getDate().compareTo(t2.getDate());
return res == 0
? t1.getName().fullName.compareTo(t2.getName().fullName)
? t1.getName().value.compareTo(t2.getName().value)
: res;
}
}
2 changes: 1 addition & 1 deletion src/main/java/trackitnus/storage/JsonAdaptedContact.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public JsonAdaptedContact(@JsonProperty("name") String name, @JsonProperty("phon
* Converts a given {@code Contact} into this class for Jackson use.
*/
public JsonAdaptedContact(Contact source) {
name = source.getName().fullName;
name = source.getName().value;
phone = source.getPhone().value;
email = source.getEmail().value;
tagged.addAll(source.getTags().stream()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/trackitnus/storage/JsonAdaptedModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public JsonAdaptedModule(@JsonProperty("code") String code, @JsonProperty("name"
*/
public JsonAdaptedModule(Module source) {
code = source.getCode().code;
name = source.getName().fullName;
name = source.getName().value;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/trackitnus/storage/JsonAdaptedTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class JsonAdaptedTask {
private final String date;
private final String code;
private final String remark;
private boolean isDone;
private final boolean isDone;

/**
* Constructs a {@code JsonAdaptedTask} with the given task details.
Expand All @@ -42,7 +42,7 @@ public JsonAdaptedTask(@JsonProperty("name") String name, @JsonProperty("date")
* Converts a given {@code Task} into this class for Jackson use.
*/
public JsonAdaptedTask(Task source) {
name = source.getName().fullName;
name = source.getName().value;
date = source.getDate().format(Task.FORMATTER);
code = source.getCode().isPresent() ? source.getCode().get().code : null;
remark = source.getRemark();
Expand Down
1 change: 0 additions & 1 deletion src/main/java/trackitnus/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
menuItem.setAccelerator(keyCombination);

/*
* TODO: the code below can be removed once the bug reported here
* https://bugs.openjdk.java.net/browse/JDK-8131666
* is fixed in later version of SDK.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/trackitnus/ui/contact/ContactCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ContactCard(Contact contact, int displayedIndex) {
super(FXML);
this.contact = contact;
id.setText(displayedIndex + ". ");
name.setText(contact.getName().fullName);
name.setText(contact.getName().value);
phone.setText(contact.getPhone().value);
email.setText(contact.getEmail().value);
contact.getTags().stream()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/trackitnus/ui/module/ModuleCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ModuleCard(Module module, int displayedIndex) {
this.module = module;
id.setText(displayedIndex + ". ");
code.setText(module.getCode().code);
name.setText(module.getName().fullName);
name.setText(module.getName().value);
}

@Override
Expand Down
3 changes: 0 additions & 3 deletions src/test/java/trackitnus/commons/util/JsonUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,4 @@ public void deserializeObjectFromJsonFile_noExceptionThrown() throws IOException
assertEquals(serializableTestClass.getMapOfIntegerToString(), SerializableTestClass.getHashMapTestValues());
}

//TODO: @Test jsonUtil_readJsonStringToObjectInstance_correctObject()

//TODO: @Test jsonUtil_writeThenReadObjectToJson_correctObject()
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void showContactAtIndex(Model model, Index targetIndex) {
assertTrue(targetIndex.getZeroBased() < model.getFilteredContactList().size());

Contact contact = model.getFilteredContactList().get(targetIndex.getZeroBased());
final String[] splitName = contact.getName().fullName.split("\\s+");
final String[] splitName = contact.getName().value.split("\\s+");
model.updateFilteredContactList(new NameContainsKeywordsPredicate(Arrays.asList(splitName[0])));

assertEquals(1, model.getFilteredContactList().size());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/trackitnus/model/ModelManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void equals() {
assertFalse(modelManager.equals(new ModelManager(differentTrackIter, userPrefs)));

// different filteredList -> returns false
String[] keywords = ALICE.getName().fullName.split("\\s+");
String[] keywords = ALICE.getName().value.split("\\s+");
modelManager.updateFilteredContactList(new NameContainsKeywordsPredicate(Arrays.asList(keywords)));
assertFalse(modelManager.equals(new ModelManager(trackIter, userPrefs)));

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/trackitnus/testutil/ContactUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static String getAddCommand(Contact contact) {
*/
public static String getContactDetails(Contact contact) {
StringBuilder sb = new StringBuilder();
sb.append(PREFIX_NAME + contact.getName().fullName + " ");
sb.append(PREFIX_NAME + contact.getName().value + " ");
sb.append(PREFIX_PHONE + contact.getPhone().value + " ");
sb.append(PREFIX_EMAIL + contact.getEmail().value + " ");
contact.getTags().stream().forEach(
Expand All @@ -43,7 +43,7 @@ public static String getContactDetails(Contact contact) {
*/
public static String getEditContactDescriptorDetails(EditContactCommand.EditContactDescriptor descriptor) {
StringBuilder sb = new StringBuilder();
descriptor.getName().ifPresent(name -> sb.append(PREFIX_NAME).append(name.fullName).append(" "));
descriptor.getName().ifPresent(name -> sb.append(PREFIX_NAME).append(name.value).append(" "));
descriptor.getPhone().ifPresent(phone -> sb.append(PREFIX_PHONE).append(phone.value).append(" "));
descriptor.getEmail().ifPresent(email -> sb.append(PREFIX_EMAIL).append(email.value).append(" "));
if (descriptor.getTags().isPresent()) {
Expand Down