Skip to content

Commit

Permalink
Fix checkstyle issues in src/main
Browse files Browse the repository at this point in the history
  • Loading branch information
DanzaSeah committed Oct 8, 2024
1 parent 608ba89 commit fe8ae98
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TagCommand parse(String args) throws ParseException {

// Convert tag values to Tag objects
List<Tag> tags = tagValues.stream()
.map(TagName::new) // Convert each string to a TagName object
.map(TagName::new) // Convert each string to a TagName object
.map(Tag::new)
.collect(Collectors.toList());

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public void resetData(ReadOnlyAddressBook newData) {
* Replaces the contents of the tag list with {@code tags}.
* {@code tags} must not contain duplicate tags.
*/
public void setTags(List<Tag> tags) { this.tags.setTags(tags); }
public void setTags(List<Tag> tags) {
this.tags.setTags(tags);
}

//// person-level operations

Expand Down Expand Up @@ -109,7 +111,9 @@ public void removePerson(Person key) {
* Adds a tag to the address book.
* The tag must not already exist in the address book.
*/
public void addTag(Tag tag) { tags.add(tag); }
public void addTag(Tag tag) {
tags.add(tag);
}

/**
* Returns true if a tag with the same name as {@code tag} exists in the address book.
Expand Down Expand Up @@ -145,7 +149,9 @@ public ObservableList<Person> getPersonList() {
}

@Override
public ObservableList<Tag> getTagList() { return tags.asUnmodifiableObservableList(); }
public ObservableList<Tag> getTagList() {
return tags.asUnmodifiableObservableList();
}

@Override
public boolean equals(Object other) {
Expand All @@ -166,6 +172,4 @@ public boolean equals(Object other) {
public int hashCode() {
return persons.hashCode();
}


}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ public interface Model {
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredTagList(Predicate<Tag> predicate);
}
}
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,4 @@ public boolean equals(Object other) {
&& userPrefs.equals(otherModelManager.userPrefs)
&& filteredPersons.equals(otherModelManager.filteredPersons);
}

}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/ReadOnlyAddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public interface ReadOnlyAddressBook {
* This list will not contain any duplicate tags.
*/
ObservableList<Tag> getTagList();
}
}
14 changes: 11 additions & 3 deletions src/main/java/seedu/address/model/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public static boolean isValidTagName(String test) {
return test.matches(VALIDATION_REGEX);
}

/**
* Returns true if this tag is considered the same as {@code otherTag}.
* Two tags are considered the same if they have the same {@code TagName}.
*
* @param otherTag The tag to compare with.
* @return {@code true} if the tags are the same, {@code false} otherwise.
*/
public boolean isSameTag(Tag otherTag) {
if (otherTag == this) {
return true;
Expand All @@ -39,7 +46,9 @@ public boolean isSameTag(Tag otherTag) {
&& otherTag.getTagName().equals(getTagName());
}

public TagName getTagName() { return tagName; }
public TagName getTagName() {
return tagName;
}

@Override
public boolean equals(Object other) {
Expand Down Expand Up @@ -67,5 +76,4 @@ public int hashCode() {
public String toString() {
return '[' + tagName.toString() + ']';
}

}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/tag/TagName.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ public int hashCode() {
public boolean matches(String validationRegex) {
return tagName.matches(validationRegex);
}
}
}
40 changes: 20 additions & 20 deletions src/main/java/seedu/address/model/tag/UniqueTagList.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public void setTag(Tag target, Tag editedPerson) {
internalList.set(index, editedPerson);
}

public void setTag(UniqueTagList replacement) {
requireNonNull(replacement);
internalList.setAll(replacement.internalList);
}

/**
* Removes the equivalent tag from the list.
* The tag must exist in the list.
Expand All @@ -78,11 +83,6 @@ public void remove(Tag toRemove) {
}
}

public void setTag(UniqueTagList replacement) {
requireNonNull(replacement);
internalList.setAll(replacement.internalList);
}

/**
* Replaces the contents of this list with {@code persons}.
* {@code persons} must not contain duplicate persons.
Expand All @@ -103,6 +103,20 @@ public ObservableList<Tag> asUnmodifiableObservableList() {
return internalUnmodifiableList;
}

/**
* Returns true if {@code tags} contains only unique tags.
*/
private boolean tagsAreUnique(List<Tag> tags) {
for (int i = 0; i < tags.size() - 1; i++) {
for (int j = i + 1; j < tags.size(); j++) {
if (tags.get(i).isSameTag(tags.get(j))) {
return false;
}
}
}
return true;
}

@Override
public Iterator<Tag> iterator() {
return internalList.iterator();
Expand Down Expand Up @@ -132,18 +146,4 @@ public int hashCode() {
public String toString() {
return internalList.toString();
}

/**
* Returns true if {@code tags} contains only unique tags.
*/
private boolean tagsAreUnique(List<Tag> tags) {
for (int i = 0; i < tags.size() - 1; i++) {
for (int j = i + 1; j < tags.size(); j++) {
if (tags.get(i).isSameTag(tags.get(j))) {
return false;
}
}
}
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class DuplicateTagException extends RuntimeException {
public DuplicateTagException() {
super("Operation would result in duplicate tags");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/**
* Signals that the operation is unable to find the specified tag.
*/
public class TagNotFoundException extends RuntimeException {}
public class TagNotFoundException extends RuntimeException {}
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/storage/JsonAdaptedTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ public Tag toModelType() throws IllegalValueException {
}
return new Tag(new TagName(tagName));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,4 @@ public AddressBook toModelType() throws IllegalValueException {
}
return addressBook;
}

}
}

0 comments on commit fe8ae98

Please sign in to comment.