Skip to content
This repository has been archived by the owner on Dec 24, 2022. It is now read-only.

Commit

Permalink
Refactor entire project, remove all traces of Addressbook
Browse files Browse the repository at this point in the history
  • Loading branch information
seanieyap committed Mar 17, 2019
1 parent 984e459 commit 3dc81e8
Show file tree
Hide file tree
Showing 53 changed files with 807 additions and 3,855 deletions.
3 changes: 1 addition & 2 deletions src/planmysem/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import javafx.application.Platform;
import javafx.stage.Stage;
import planmysem.logic.Logic;
import planmysem.logic.LogicP;
import planmysem.ui.Gui;
import planmysem.ui.Stoppable;

Expand All @@ -26,7 +25,7 @@ public static void main(String[] args) {

@Override
public void start(Stage primaryStage) throws Exception {
gui = new Gui(new Logic(), new LogicP(), VERSION);
gui = new Gui(new Logic(), VERSION);
gui.start(primaryStage, this);
}

Expand Down
122 changes: 75 additions & 47 deletions src/planmysem/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,75 +1,103 @@
package planmysem.commands;

import java.util.HashSet;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Set;

import planmysem.common.Utils;
import planmysem.data.exception.IllegalValueException;
import planmysem.data.person.Address;
import planmysem.data.person.Email;
import planmysem.data.person.Name;
import planmysem.data.person.Person;
import planmysem.data.person.Phone;
import planmysem.data.person.ReadOnlyPerson;
import planmysem.data.person.UniquePersonList;
import planmysem.data.tag.Tag;
import planmysem.data.recurrence.Recurrence;
import planmysem.data.semester.Semester;
import planmysem.data.slot.Description;
import planmysem.data.slot.Location;
import planmysem.data.slot.Name;
import planmysem.data.slot.Slot;

/**
* Adds a person to the address book.
* Adds a person to the planner.
*/
public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";
public static final String COMMAND_WORD_SHORT = "a";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Add single or multiple slots to the Planner."
+ "\n\tParameters: "
+ "\n\t\tMandatory: n/NAME d/DATE_OR_DAY_OF_WEEK st/START_TIME et/END_TIME_OR_DURATION"
+ "\n\t\tOptional: [l/LOCATION] [des/DESCRIPTION] [r/normal] [r/recess] [r/reading] [r/exam]"
+ "[r/past] [t/TAG]..."
+ "\n\tExample: " + COMMAND_WORD
+ " n/CS2113T Tutorial d/mon st/08:00 et/09:00 des/Topic: Sequence Diagram t/CS2113T "
+ "t/Tutorial r/normal";

public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Adds a person to the address book. "
+ "Contact details can be marked private by prepending 'p' to the prefix.\n\t"
+ "Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...\n\t"
+ "Example: " + COMMAND_WORD
+ " John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney";

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
public static final String MESSAGE_SUCCESS_NO_CHANGE = "No slots were added.";
public static final String MESSAGE_SUCCESS = "%1$s Slots added.\n\n%2$s";
public static final String MESSAGE_FAIL_OUT_OF_BOUNDS = "Date specified is out of bounds.";

private final Person toAdd;
private final Slot slot;
private final Recurrence recurrence;

/**
* Convenience constructor using raw values.
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public AddCommand(String name,
String phone, boolean isPhonePrivate,
String email, boolean isEmailPrivate,
String address, boolean isAddressPrivate,
Set<String> tags) throws IllegalValueException {
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
}
this.toAdd = new Person(
new Name(name),
new Phone(phone, isPhonePrivate),
new Email(email, isEmailPrivate),
new Address(address, isAddressPrivate),
tagSet
);
}

public AddCommand(Person toAdd) {
this.toAdd = toAdd;
public AddCommand(LocalDate date, String name, String location, String description, LocalTime startTime,
int duration, Set<String> tags, Set<String> recurrences) throws IllegalValueException {
slot = new Slot(new Name(name), new Location(location), new Description(description),
startTime, duration, Utils.parseTags(tags));
recurrence = new Recurrence(recurrences, date);
}

public ReadOnlyPerson getPerson() {
return toAdd;
/**
* Convenience constructor using raw values.
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public AddCommand(int day, String name, String location, String description, LocalTime startTime,
int duration, Set<String> tags, Set<String> recurrences) throws IllegalValueException {
slot = new Slot(new Name(name), new Location(location), new Description(description),
startTime, duration, Utils.parseTags(tags));
recurrence = new Recurrence(recurrences, day);
}

@Override
public CommandResult execute() {
try {
addressBook.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
} catch (UniquePersonList.DuplicatePersonException dpe) {
return new CommandResult(MESSAGE_DUPLICATE_PERSON);
Set<LocalDate> dates = recurrence.generateDates(planner.getSemester());

for (LocalDate date : dates) {
try {
planner.addSlot(date, slot);
} catch (Semester.DateNotFoundException dnfe) {
return new CommandResult(MESSAGE_FAIL_OUT_OF_BOUNDS);
}
}

if (dates.size() == 0) {
return new CommandResult(MESSAGE_SUCCESS_NO_CHANGE);
} else {
return new CommandResult(String.format(MESSAGE_SUCCESS, dates.size(),
craftSuccessMessage(dates, slot)));
}
}

/**
* Craft success message.
*/
private String craftSuccessMessage(Set<LocalDate> dates, Slot slot) {
StringBuilder sb = new StringBuilder();
sb.append("On dates:");

for (LocalDate date : dates) {
sb.append("\n\t");
sb.append(planner.getSemester().getDays().get(date).getType());
sb.append(", ");
sb.append(date.toString());
sb.append(", ");
sb.append(date.getDayOfWeek().toString());
}
sb.append("\n\n");

sb.append(slot.toString());

return sb.toString();
}
}
103 changes: 0 additions & 103 deletions src/planmysem/commands/AddCommandP.java

This file was deleted.

10 changes: 5 additions & 5 deletions src/planmysem/commands/ClearCommand.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package planmysem.commands;

/**
* Clears the address book.
* Clears the planner.
*/
public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Clears address book permanently.\n\t"
+ "Example: " + COMMAND_WORD;
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Clears the planner permanently."
+ "\n\tExample: " + COMMAND_WORD;

public static final String MESSAGE_SUCCESS = "Address book has been cleared!";
public static final String MESSAGE_SUCCESS = "The Planner has been cleared!";

@Override
public CommandResult execute() {
addressBook.clear();
planner.clearSlots();
return new CommandResult(MESSAGE_SUCCESS);
}
}
19 changes: 0 additions & 19 deletions src/planmysem/commands/ClearCommandP.java

This file was deleted.

Loading

0 comments on commit 3dc81e8

Please sign in to comment.