Skip to content

Commit

Permalink
Edit Data Classes, remove unnecessary dependencies (#120)
Browse files Browse the repository at this point in the history
* v1.1

* fix some errors and typos

* Refactor entire project, remove all traces of Addressbook

* Update developer guide for ExportCommandP (#80)

* Update documentation for view command (#81)

* Remove remaining Addressbook classes

* Refactor some classes

* fix missing files issue

* Add test cases for add function, Utils and other code enhancements

* fix codacy issues

* fix codacy issues

* Add tests for Utils

* Add diagrams

* Update Ui.png

* fix issue with Ui.png

* Update Codacy Badge link due to reinitialization.

* Enhance ordering of slots printed

* Update UserGuide.adoc with feedback from peers

* Update UserGuide.adoc with nicer tables

* Update UserGuide.adoc: fix formatting issues

* UserGuide.adoc Remove potential Netlify breaking code

* README.adoc revert changes

* UserGuide.adoc revert Netlify breakdown test code

* Add tests for Add, Edit and Delete commands and optimise code

* Fix checkstyle error

* Update UserGuide.adoc with Managing Slots and diagrams

* Solved unchecked or unsafe operation warnings

* Edit Data Classes, remove unnecessary dependencies
  • Loading branch information
seanieyap authored and marcus-pzj committed Mar 26, 2019
1 parent b99339b commit c87980d
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 551 deletions.
14 changes: 3 additions & 11 deletions src/planmysem/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
import java.util.Set;
import java.util.TreeMap;

import planmysem.common.Utils;
import planmysem.data.exception.IllegalValueException;
import planmysem.data.recurrence.Recurrence;
import planmysem.data.semester.Day;
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;

/**
Expand All @@ -39,13 +35,10 @@ public class AddCommand extends Command {

/**
* Convenience constructor using raw values.
*
* @throws IllegalValueException if any of the raw values are invalid
*/
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));
int duration, Set<String> tags, Set<String> recurrences) {
slot = new Slot(name, location, description, startTime, duration, tags);
recurrence = new Recurrence(recurrences, date);
}

Expand All @@ -56,8 +49,7 @@ public AddCommand(LocalDate date, String name, String location, String descripti
*/
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));
slot = new Slot(name, location, description, startTime, duration, tags);
recurrence = new Recurrence(recurrences, day);
}

Expand Down
11 changes: 3 additions & 8 deletions src/planmysem/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

import javafx.util.Pair;
import planmysem.common.Messages;
import planmysem.common.Utils;
import planmysem.data.exception.IllegalValueException;
import planmysem.data.semester.ReadOnlyDay;
import planmysem.data.slot.ReadOnlySlot;
import planmysem.data.tag.Tag;

/**
* Adds a person to the address book.
Expand All @@ -34,15 +31,13 @@ public class DeleteCommand extends Command {
public static final String MESSAGE_SUCCESS_NO_CHANGE = "No Slots were deleted.\n\n%1$s";
public static final String MESSAGE_SUCCESS = "%1$s Slots deleted.\n\n%2$s\n%3$s";

private final Set<Tag> tags = new HashSet<>();
private final Set<String> tags = new HashSet<>();

/**
* Convenience constructor using raw values.
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public DeleteCommand(Set<String> tags) throws IllegalValueException {
this.tags.addAll(Utils.parseTags(tags));
public DeleteCommand(Set<String> tags) {
this.tags.addAll(tags);
}

/**
Expand Down
30 changes: 10 additions & 20 deletions src/planmysem/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

import javafx.util.Pair;
import planmysem.common.Messages;
import planmysem.common.Utils;
import planmysem.data.exception.IllegalValueException;
import planmysem.data.semester.ReadOnlyDay;
import planmysem.data.slot.ReadOnlySlot;
import planmysem.data.tag.Tag;

/**
* Adds a person to the address book.
Expand Down Expand Up @@ -46,36 +43,33 @@ public class EditCommand extends Command {
private final String name;
private final String location;
private final String description;
private final Set<Tag> tags = new HashSet<>();
private final Set<Tag> newTags = new HashSet<>();
private final Set<String> tags = new HashSet<>();
private final Set<String> newTags = new HashSet<>();

/**
* Convenience constructor using raw values.
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public EditCommand(String name, LocalTime startTime, int duration, String location, String description,
Set<String> tags, Set<String> newTags) throws IllegalValueException {
Set<String> tags, Set<String> newTags) {
this.date = null;
this.startTime = startTime;
this.duration = duration;
this.name = name;
this.location = location;
this.description = description;
if (tags != null) {
this.tags.addAll(Utils.parseTags(tags));
this.tags.addAll(tags);
}
if (newTags != null) {
this.newTags.addAll(Utils.parseTags(newTags));
this.newTags.addAll(newTags);
}
}

/**
* Convenience constructor using raw values.
*/
public EditCommand(int index, String name, LocalDate date, LocalTime startTime, int duration,
String location, String description, Set<String> newTags)
throws IllegalValueException {
String location, String description, Set<String> newTags) {
super(index);
this.date = date;
this.startTime = startTime;
Expand All @@ -84,7 +78,7 @@ public EditCommand(int index, String name, LocalDate date, LocalTime startTime,
this.location = location;
this.description = description;
if (newTags != null) {
this.newTags.addAll(Utils.parseTags(newTags));
this.newTags.addAll(newTags);
}
}

Expand Down Expand Up @@ -112,12 +106,8 @@ public CommandResult execute() {
String successMessage = craftSuccessMessage(selectedSlots);

for (Map.Entry<LocalDate, Pair<ReadOnlyDay, ReadOnlySlot>> entry : selectedSlots.entrySet()) {
try {
planner.editSlot(entry.getKey(), entry.getValue().getValue(), date,
startTime, duration, name, location, description, newTags);
} catch (IllegalValueException ive) {
return new CommandResult(MESSAGE_FAIL_ILLEGAL_VALUE);
}
planner.editSlot(entry.getKey(), entry.getValue().getValue(), date,
startTime, duration, name, location, description, newTags);
}

return new CommandResult(String.format(MESSAGE_SUCCESS, selectedSlots.size(),
Expand Down Expand Up @@ -178,7 +168,7 @@ public String craftSuccessMessage(Map<LocalDate, Pair<ReadOnlyDay, ReadOnlySlot>
sb.append("\nTags: ");
StringJoiner sj = new StringJoiner(", ");

for (Tag tag : newTags) {
for (String tag : newTags) {
StringBuilder sb2 = new StringBuilder();
sb2.append("\"");
sb2.append(tag);
Expand Down
9 changes: 4 additions & 5 deletions src/planmysem/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import planmysem.data.semester.ReadOnlyDay;
import planmysem.data.slot.ReadOnlySlot;
import planmysem.data.slot.Slot;
import planmysem.data.tag.Tag;


/**
Expand Down Expand Up @@ -46,13 +45,13 @@ public CommandResult execute() {
for (Map.Entry<LocalDate, Day> entry : planner.getAllDays().entrySet()) {
for (Slot slot : entry.getValue().getSlots()) {
if (isFindByName) {
if (Pattern.matches(".*" + keyword + ".*", slot.getName().value)) {
if (Pattern.matches(".*" + keyword + ".*", slot.getName())) {
selectedSlots.put(entry.getKey(), new Pair<>(entry.getValue(), slot));
}
} else {
Set<Tag> tagSet = slot.getTags();
for (Tag tag : tagSet) {
if (Pattern.matches(".*" + keyword + ".*", tag.value)) {
Set<String> tagSet = slot.getTags();
for (String tag : tagSet) {
if (Pattern.matches(".*" + keyword + ".*", tag)) {
selectedSlots.put(entry.getKey(), new Pair<>(entry.getValue(), slot));
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/planmysem/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import planmysem.data.semester.ReadOnlyDay;
import planmysem.data.slot.ReadOnlySlot;
import planmysem.data.slot.Slot;
import planmysem.data.tag.Tag;

/**
* Displays a list of all slots in the planner whose name matches the argument keyword.
Expand All @@ -38,21 +37,22 @@ public ListCommand(String name, String tag) {
this.keyword = (name == null) ? tag.trim() : name.trim();
this.isListByName = (name != null);
}

@Override
public CommandResult execute() {
Map<LocalDate, Pair<ReadOnlyDay, ReadOnlySlot>> selectedSlots = new TreeMap<>();

for (Map.Entry<LocalDate, Day> entry : planner.getAllDays().entrySet()) {
for (Slot slot : entry.getValue().getSlots()) {
if (isListByName) {
if (slot.getName().value.equalsIgnoreCase(keyword)) {
if (slot.getName().equalsIgnoreCase(keyword)) {
selectedSlots.put(entry.getKey(), new Pair<>(entry.getValue(), slot));
}
} else {
Set<Tag> tagSet = slot.getTags();
for (Tag tag : tagSet) {
Set<String> tagSet = slot.getTags();
for (String tag : tagSet) {
// if (slot.getTags().contains(keyword))
if (tag.value.equalsIgnoreCase(keyword)) {
if (tag.equalsIgnoreCase(keyword)) {
selectedSlots.put(entry.getKey(), new Pair<>(entry.getValue(), slot));
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/planmysem/common/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javafx.util.Pair;
import planmysem.data.semester.ReadOnlyDay;
import planmysem.data.slot.ReadOnlySlot;
import planmysem.data.tag.Tag;

/**
* Container for user visible messages.
Expand All @@ -16,10 +15,8 @@ public class Messages {

public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_COMMAND_FORMAT_ADDITIONAL = "Invalid command format! \n%1$s\n\n%2$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_MULTIPLE_PARAMS = "Either search by NAME or by TAG only, not both.";
public static final String MESSAGE_INVALID_SLOT_DISPLAYED_INDEX = "The slot index provided is invalid";
public static final String MESSAGE_PERSON_NOT_IN_ADDRESSBOOK = "Person could not be found in address book";
public static final String MESSAGE_SLOT_NOT_IN_PLANNER = "Slot could not be found in Planner";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_SLOTS_LISTED_OVERVIEW = "%1$d slots listed!";
Expand All @@ -38,19 +35,20 @@ public class Messages {
+ "\n\t12-Hour in the form of `hh:mm+AM|PM`. e.g. \"12:30am\""
+ "\n\tOr perhaps type a duration in minutes. e.g. \"60\" to represent 60 minutes";

public static final String MESSAGE_ILLEGAL_VALUE = "Illegal value detected!";

/**
* Craft selected message.
*/
public static String craftSelectedMessage(Set<Tag> tags) {
public static String craftSelectedMessage(Set<String> tags) {
StringBuilder sb = new StringBuilder();
sb.append("Selected Slots containing tags: \n");

int count = 1;
for (Tag tag : tags) {
for (String tag : tags) {
sb.append(count);
sb.append(".\t");
sb.append(tag.toString());
sb.append(tag);
sb.append("\n");
count++;
}
Expand Down Expand Up @@ -89,7 +87,7 @@ public static String craftListMessage(Map<LocalDate, Pair<ReadOnlyDay, ReadOnlyS
sb.append("\n");
sb.append(count + ".\t");
sb.append("Name: ");
sb.append(entry.getValue().getValue().getName().toString());
sb.append(entry.getValue().getValue().getName());
sb.append(",\n\t");
sb.append("Date: ");
sb.append(entry.getKey().toString());
Expand Down
25 changes: 10 additions & 15 deletions src/planmysem/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import java.util.Set;
import java.util.regex.Pattern;

import planmysem.data.exception.IllegalValueException;
import planmysem.data.tag.Tag;

/**
* Utility methods
*/
Expand Down Expand Up @@ -171,19 +168,17 @@ public static int parseInteger(String value) {

/**
* Convert set of strings into set of tags.
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public static Set<Tag> parseTags(Set<String> tags) throws IllegalValueException {
if (tags == null) {
return null;
}
Set<Tag> tagSet = new HashSet<>();
for (String tag : tags) {
tagSet.add(new Tag(tag));
}
return tagSet;
}
// public static Set<String> parseTags(Set<String> tags) {
// if (tags == null) {
// return null;
// }
// Set<String> tagSet = new HashSet<>();
// for (String tag : tags) {
// tagSet.add(new String(tag));
// }
// return tagSet;
// }


/**
Expand Down
8 changes: 2 additions & 6 deletions src/planmysem/data/Planner.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import java.util.TreeMap;

import javafx.util.Pair;
import planmysem.data.exception.IllegalValueException;
import planmysem.data.semester.Day;
import planmysem.data.semester.ReadOnlyDay;
import planmysem.data.semester.Semester;
import planmysem.data.slot.ReadOnlySlot;
import planmysem.data.slot.Slot;
import planmysem.data.tag.Tag;

/**
* Represents the entire Planner. Contains the data of the Planner.
Expand Down Expand Up @@ -64,12 +62,10 @@ public void removeSlot(LocalDate date, ReadOnlySlot slot) {

/**
* Edit specific slot within the planner.
*
* @throws IllegalValueException if a targetDate is not found in the semester.
*/
public void editSlot(LocalDate targetDate, ReadOnlySlot targetSlot, LocalDate date,
LocalTime startTime, int duration, String name, String location,
String description, Set<Tag> tags) throws IllegalValueException {
String description, Set<String> tags) {
semester.editSlot(targetDate, targetSlot, date, startTime, duration, name, location, description, tags);
}

Expand Down Expand Up @@ -150,7 +146,7 @@ public Day getDay(LocalDate date) {
/**
* gets all slots in the Planner containing all specified tags.
*/
public Map<LocalDate, Pair<ReadOnlyDay, ReadOnlySlot>> getSlots(Set<Tag> tags) {
public Map<LocalDate, Pair<ReadOnlyDay, ReadOnlySlot>> getSlots(Set<String> tags) {
final Map<LocalDate, Pair<ReadOnlyDay, ReadOnlySlot>> selectedSlots = new TreeMap<>();

for (Map.Entry<LocalDate, Day> entry : getAllDays().entrySet()) {
Expand Down
10 changes: 0 additions & 10 deletions src/planmysem/data/exception/DuplicateDataException.java

This file was deleted.

3 changes: 1 addition & 2 deletions src/planmysem/data/semester/Day.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.ArrayList;
import java.util.Objects;

import planmysem.data.exception.IllegalValueException;
import planmysem.data.slot.ReadOnlySlot;
import planmysem.data.slot.Slot;

Expand Down Expand Up @@ -46,7 +45,7 @@ public void addSlot(Slot slot) {
* Edit a slot in the day.
*/
public void editSlot(ReadOnlySlot targetSlot, LocalTime startTime, int duration,
String name, String location, String description) throws IllegalValueException {
String name, String location, String description) {
for (Slot slot : slots) {
if (slot.equals(targetSlot)) {
if (startTime != null) {
Expand Down
Loading

0 comments on commit c87980d

Please sign in to comment.