Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2324S1#79 from garylow2001/add-client…
Browse files Browse the repository at this point in the history
…s-and-leads

Refactor addclient and addlead, Add test cases
  • Loading branch information
tiif committed Oct 19, 2023
2 parents 3b4788b + 52634a1 commit 9f78542
Show file tree
Hide file tree
Showing 27 changed files with 866 additions and 930 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AddLeadCommand extends Command {

public static final String MESSAGE_SUCCESS = "New lead added: %1$s";

public static final String MESSAGE_DUPLICATE_CLIENT = "This lead already exists in the address book";
public static final String MESSAGE_DUPLICATE_LEAD = "This lead already exists in the address book";

private final Lead toAdd;

Expand All @@ -53,7 +53,7 @@ public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_CLIENT);
throw new CommandException(MESSAGE_DUPLICATE_LEAD);
}

model.addLead(toAdd);
Expand Down
63 changes: 0 additions & 63 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.commands.AddClientCommand;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddLeadCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
Expand Down Expand Up @@ -57,9 +56,6 @@ public Command parseCommand(String userInput) throws ParseException {

switch (commandWord) {

case AddCommand.COMMAND_WORD:
return new AddCommandParser().parse(arguments);

case AddClientCommand.COMMAND_WORD:
return new AddClientCommandParser().parse(arguments);

Expand Down
67 changes: 2 additions & 65 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import seedu.address.model.person.Client;
import seedu.address.model.person.Lead;
import seedu.address.model.person.Person;
import seedu.address.model.person.UniqueClientList;
import seedu.address.model.person.UniqueLeadList;
import seedu.address.model.person.UniquePersonList;

/**
Expand All @@ -20,8 +18,6 @@
public class AddressBook implements ReadOnlyAddressBook {

private final UniquePersonList persons;
private final UniqueClientList clients;
private final UniqueLeadList leads;

/*
* The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication
Expand All @@ -32,8 +28,6 @@ public class AddressBook implements ReadOnlyAddressBook {
*/
{
persons = new UniquePersonList();
clients = new UniqueClientList();
leads = new UniqueLeadList();
}

public AddressBook() {}
Expand All @@ -56,31 +50,13 @@ public void setPersons(List<Person> persons) {
this.persons.setPersons(persons);
}

/**
* Replaces the contents of the person list with {@code clients}.
* {@code clients} must not contain duplicate clients, use when loading clients from json.
*/
public void setClients(List<Client> clients) {
this.clients.setClients(clients);
}

/**
* Replaces the contents of the person list with {@code leads}.
* {@code leads} must not contain duplicate leads, use when loading leads from json.
*/
public void setLeads(List<Lead> leads) {
this.leads.setLeads(leads);
}

/**
* Resets the existing data of this {@code AddressBook} with {@code newData}.
*/
public void resetData(ReadOnlyAddressBook newData) {
requireNonNull(newData);

setPersons(newData.getPersonList());
setClients(newData.getClientList());
setLeads(newData.getLeadList());
}

//// person-level operations
Expand All @@ -106,7 +82,6 @@ public void addPerson(Person person) {
* The client must not already exist in the address book.
*/
public void addClient(Client client) {
clients.add(client);
persons.add(client);
}

Expand All @@ -115,7 +90,6 @@ public void addClient(Client client) {
* The lead must not already exist in the address book.
*/
public void addLead(Lead lead) {
leads.add(lead);
persons.add(lead);
}

Expand All @@ -129,16 +103,6 @@ public void setPerson(Person target, Person editedPerson) {
persons.setPerson(target, editedPerson);
}

public void setClient(Client target, Client editedPerson) {
requireNonNull(editedPerson);
clients.setClient(target, editedPerson);
}

public void setLead(Lead target, Lead editedPerson) {
requireNonNull(editedPerson);
leads.setLead(target, editedPerson);
}

/**
* Removes {@code personKey} from this {@code AddressBook}.
* {@code personKey} must exist in the address book.
Expand All @@ -147,24 +111,6 @@ public void removePerson(Person personKey) {
persons.remove(personKey);
}

/**
* Removes {@code clientKey} from this {@code AddressBook}.
* {@code clientKey} must exist in the address book.
*/
public void removeClient(Client clientKey) {
clients.remove(clientKey);
persons.remove(clientKey);
}

/**
* Removes {@code leadKey} from this {@code AddressBook}.
* {@code leadKey} must exist in the address book.
*/
public void removeLead(Lead leadKey) {
leads.remove(leadKey);
persons.remove(leadKey);
}

//// util methods

@Override
Expand All @@ -179,15 +125,6 @@ public ObservableList<Person> getPersonList() {
return persons.asUnmodifiableObservableList();
}

@Override
public ObservableList<Client> getClientList() {
return clients.asUnmodifiableObservableList();
}

@Override
public ObservableList<Lead> getLeadList() {
return leads.asUnmodifiableObservableList();
}

@Override
public boolean equals(Object other) {
Expand All @@ -201,11 +138,11 @@ public boolean equals(Object other) {
}

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

@Override
public int hashCode() {
return clients.hashCode() + leads.hashCode();
return persons.hashCode();
}
}
7 changes: 0 additions & 7 deletions src/main/java/seedu/address/model/ReadOnlyAddressBook.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package seedu.address.model;

import javafx.collections.ObservableList;
import seedu.address.model.person.Client;
import seedu.address.model.person.Lead;
import seedu.address.model.person.Person;

/**
Expand All @@ -15,9 +13,4 @@ public interface ReadOnlyAddressBook {
* This list will not contain any duplicate persons.
*/
ObservableList<Person> getPersonList();

ObservableList<Client> getClientList();

ObservableList<Lead> getLeadList();

}
Loading

0 comments on commit 9f78542

Please sign in to comment.