Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
Merge 37c274c into 921e61f
Browse files Browse the repository at this point in the history
  • Loading branch information
pyokagan committed Feb 23, 2019
2 parents 921e61f + 37c274c commit 28291db
Show file tree
Hide file tree
Showing 25 changed files with 216 additions and 113 deletions.
1 change: 1 addition & 0 deletions src/main/java/seedu/address/AppParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public boolean equals(Object other) {
return true;
}

// instanceof handles nulls
if (!(other instanceof AppParameters)) {
return false;
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/seedu/address/commons/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof Config)) { //this handles null as well.

// instanceof handles nulls
if (!(other instanceof Config)) {
return false;
}

Config o = (Config) other;

return Objects.equals(logLevel, o.logLevel)
&& Objects.equals(userPrefsFilePath, o.userPrefsFilePath);
Config otherConfig = (Config) other;
return Objects.equals(logLevel, otherConfig.logLevel)
&& Objects.equals(userPrefsFilePath, otherConfig.userPrefsFilePath);
}

@Override
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/seedu/address/commons/core/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof GuiSettings)) { //this handles null as well.

// instanceof handles nulls
if (!(other instanceof GuiSettings)) {
return false;
}

GuiSettings o = (GuiSettings) other;

return windowWidth == o.windowWidth
&& windowHeight == o.windowHeight
&& Objects.equals(windowCoordinates, o.windowCoordinates);
GuiSettings otherGuiSettings = (GuiSettings) other;
return windowWidth == otherGuiSettings.windowWidth
&& windowHeight == otherGuiSettings.windowHeight
&& Objects.equals(windowCoordinates, otherGuiSettings.windowCoordinates);
}

@Override
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/seedu/address/commons/core/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,21 @@ public int compareTo(Version other) {
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(obj instanceof Version)) {

// instanceof handles nulls
if (!(other instanceof Version)) {
return false;
}
final Version other = (Version) obj;

return compareTo(other) == 0;
Version otherVersion = (Version) other;
return major == otherVersion.major
&& minor == otherVersion.minor
&& patch == otherVersion.patch
&& isEarlyAccess == otherVersion.isEarlyAccess;
}

@Override
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/seedu/address/commons/core/index/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ public static Index fromOneBased(int oneBasedIndex) {

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

// instanceof handles nulls
if (!(other instanceof Index)) {
return false;
}

Index otherIndex = (Index) other;
return zeroBasedIndex == otherIndex.zeroBasedIndex;
}
}
12 changes: 5 additions & 7 deletions src/main/java/seedu/address/logic/CommandHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,18 @@ public ObservableList<String> getHistory() {
}

@Override
public boolean equals(Object obj) {
// short circuit if same object
if (obj == this) {
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(obj instanceof CommandHistory)) {
if (!(other instanceof CommandHistory)) {
return false;
}

// state check
CommandHistory other = (CommandHistory) obj;
return userInputHistory.equals(other.userInputHistory);
CommandHistory otherCommandHistory = (CommandHistory) other;
return userInputHistory.equals(otherCommandHistory.userInputHistory);
}

@Override
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,15 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddCommand // instanceof handles nulls
&& toAdd.equals(((AddCommand) other).toAdd));
if (other == this) {
return true;
}

if (!(other instanceof AddCommand)) {
return false;
}

AddCommand otherAddCommand = (AddCommand) other;
return toAdd.equals(otherAddCommand.toAdd);
}
}
14 changes: 11 additions & 3 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

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

// instanceof handles nulls
if (!(other instanceof DeleteCommand)) {
return false;
}

DeleteCommand otherDeleteCommand = (DeleteCommand) other;
return targetIndex.equals(otherDeleteCommand.targetIndex);
}
}
24 changes: 10 additions & 14 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

Expand Down Expand Up @@ -106,7 +107,6 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript

@Override
public boolean equals(Object other) {
// short circuit if same object
if (other == this) {
return true;
}
Expand All @@ -116,10 +116,9 @@ public boolean equals(Object other) {
return false;
}

// state check
EditCommand e = (EditCommand) other;
return index.equals(e.index)
&& editPersonDescriptor.equals(e.editPersonDescriptor);
EditCommand otherEditCommand = (EditCommand) other;
return index.equals(otherEditCommand.index)
&& editPersonDescriptor.equals(otherEditCommand.editPersonDescriptor);
}

/**
Expand Down Expand Up @@ -205,7 +204,6 @@ public Optional<Set<Tag>> getTags() {

@Override
public boolean equals(Object other) {
// short circuit if same object
if (other == this) {
return true;
}
Expand All @@ -215,14 +213,12 @@ public boolean equals(Object other) {
return false;
}

// state check
EditPersonDescriptor e = (EditPersonDescriptor) other;

return getName().equals(e.getName())
&& getPhone().equals(e.getPhone())
&& getEmail().equals(e.getEmail())
&& getAddress().equals(e.getAddress())
&& getTags().equals(e.getTags());
EditPersonDescriptor otherEditPersonDescriptor = (EditPersonDescriptor) other;
return Objects.equals(name, otherEditPersonDescriptor.name)
&& Objects.equals(phone, otherEditPersonDescriptor.phone)
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
}
}
}
14 changes: 11 additions & 3 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ public CommandResult execute(Model model, CommandHistory history) {

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

// instanceof handles nulls
if (!(other instanceof FindCommand)) {
return false;
}

FindCommand otherFindCommand = (FindCommand) other;
return predicate.equals(otherFindCommand.predicate);
}
}
14 changes: 11 additions & 3 deletions src/main/java/seedu/address/logic/commands/SelectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

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

// instanceof handles nulls
if (!(other instanceof SelectCommand)) {
return false;
}

SelectCommand otherSelectCommand = (SelectCommand) other;
return targetIndex.equals(otherSelectCommand.targetIndex);
}
}
16 changes: 9 additions & 7 deletions src/main/java/seedu/address/logic/parser/Prefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ public int hashCode() {
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Prefix)) {
return false;
}
if (obj == this) {
public boolean equals(Object other) {
if (other == this) {
return true;
}

Prefix otherPrefix = (Prefix) obj;
return otherPrefix.getPrefix().equals(getPrefix());
// instanceof handles nulls
if (!(other instanceof Prefix)) {
return false;
}

Prefix otherPrefix = (Prefix) other;
return prefix.equals(otherPrefix.prefix);
}
}
14 changes: 11 additions & 3 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,17 @@ public ObservableList<Person> getPersonList() {

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddressBook // instanceof handles nulls
&& persons.equals(((AddressBook) other).persons));
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof AddressBook)) {
return false;
}

AddressBook otherAddressBook = (AddressBook) other;
return persons.equals(otherAddressBook.persons);
}

@Override
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,21 @@ private void ensureSelectedPersonIsValid(ListChangeListener.Change<? extends Per
}

@Override
public boolean equals(Object obj) {
// short circuit if same object
if (obj == this) {
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(obj instanceof ModelManager)) {
if (!(other instanceof ModelManager)) {
return false;
}

// state check
ModelManager other = (ModelManager) obj;
return versionedAddressBook.equals(other.versionedAddressBook)
&& userPrefs.equals(other.userPrefs)
&& filteredPersons.equals(other.filteredPersons)
&& Objects.equals(selectedPerson.get(), other.selectedPerson.get());
ModelManager otherModelManager = (ModelManager) other;
return versionedAddressBook.equals(otherModelManager.versionedAddressBook)
&& userPrefs.equals(otherModelManager.userPrefs)
&& filteredPersons.equals(otherModelManager.filteredPersons)
&& Objects.equals(selectedPerson.get(), otherModelManager.selectedPerson.get());
}

}
11 changes: 6 additions & 5 deletions src/main/java/seedu/address/model/UserPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof UserPrefs)) { //this handles null as well.

// instanceof handles nulls
if (!(other instanceof UserPrefs)) {
return false;
}

UserPrefs o = (UserPrefs) other;

return guiSettings.equals(o.guiSettings)
&& addressBookFilePath.equals(o.addressBookFilePath);
UserPrefs otherUserPrefs = (UserPrefs) other;
return guiSettings.equals(otherUserPrefs.guiSettings)
&& addressBookFilePath.equals(otherUserPrefs.addressBookFilePath);
}

@Override
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/seedu/address/model/VersionedAddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public boolean canRedo() {

@Override
public boolean equals(Object other) {
// short circuit if same object
if (other == this) {
return true;
}
Expand All @@ -83,8 +82,6 @@ public boolean equals(Object other) {
}

VersionedAddressBook otherVersionedAddressBook = (VersionedAddressBook) other;

// state check
return super.equals(otherVersionedAddressBook)
&& addressBookStateList.equals(otherVersionedAddressBook.addressBookStateList)
&& currentStatePointer == otherVersionedAddressBook.currentStatePointer;
Expand Down

0 comments on commit 28291db

Please sign in to comment.