Skip to content

Commit

Permalink
Merge pull request #4 from CS2113-AY1819S2-T08-3/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
marcus-pzj authored Feb 28, 2019
2 parents 68d09ac + cf96ca3 commit ac99165
Show file tree
Hide file tree
Showing 23 changed files with 713 additions and 165 deletions.
52 changes: 52 additions & 0 deletions AcademicCalendar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
1:Vacation
2:Vacation
3:Week 1
4:Week 2
5:Week 3
6:Week 4
7:Week 5
8:Week 6
9:Recess Week
10:Week 7
11:Week 8
12:Week 9
13:Week 10
14:Week 11
15:Week 12
16:Week 13
17:Reading Week
18:Examination Week
19:Examination Week
20:Vacation
21:Vacation
22:Vacation
23:Vacation
24:Vacation
25:Vacation
26:Vacation
27:Vacation
28:Vacation
29:Vacation
30:Vacation
31:Vacation
32:Orientation Week
33:Week 1
34:Week 2
35:Week 3
36:Week 4
37:Week 5
38:Week 6
39:Recess Week
40:Week 7
41:Week 8
42:Week 9
43:Week 10
44:Week 11
45:Week 12
46:Week 13
47:Reading Week
48:Examination Week
49:Examination Week
50:Vacation
51:Vacation
52:Vacation
7 changes: 7 additions & 0 deletions PlanMySem.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Planner>
<semester>
<noOfWeeks>0</noOfWeeks>
<days/>
</semester>
</Planner>
4 changes: 2 additions & 2 deletions docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ ifdef::env-github[]
:warning-caption: :warning:
:experimental:
endif::[]
:repoURL: https://github.com/se-edu/addressbook-level4/tree/master
:repoURL: https://github.com/CS2113-AY1819S2-T08-3/main

By: `T08-3`
By: `T08-3` Since: `Jan 2019` Licence: `MIT`

== Setting up

Expand Down
3 changes: 2 additions & 1 deletion docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ Format: `help`
=== Adding Slots : `add`

Add a _slot_ to the planner. +
Format: `add slot d/DATE t/TIME d/DURATION [r/norecess] [r/noreading] [r/nonormal] [r/recess] [r/reading] [r/normal] [tag/TAG]...`
Format: `add NAME st/START_TIME et/END_TIME|DURATION [date/DATE|DAY_OF_WEEK] +
[l/LOCATION] [d/DESCRIPTION] [r/recess|norecess] [r/reading|noreading] [r/normal|nonormal] [t/TAG]...`

Examples:

Expand Down
2 changes: 1 addition & 1 deletion src/planmysem/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public class AddCommand extends Command {

public static final String COMMAND_WORD = "addDay";
public static final String COMMAND_WORD = "add";

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"
Expand Down
88 changes: 66 additions & 22 deletions src/planmysem/commands/AddCommandP.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import java.util.HashSet;
import java.util.Set;

import javafx.util.Pair;
import planmysem.common.Utils;
import planmysem.data.exception.IllegalValueException;
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;
Expand All @@ -19,49 +22,90 @@ public class AddCommandP extends CommandP {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Adds a slot to the Planner. "
+ "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_USAGE = COMMAND_WORD + ":\n" + "Adds a single or multiple slot to the Planner."
+ "\n\tParameters: NAME st/START_TIME et/END_TIME|DURATION [date/DATE|DAY_OF_WEEK] "
+ "[l/LOCATION] [d/DESCRIPTION] [r/recess|norecess] [r/reading|noreading] [r/normal|nonormal] [t/TAG].."
+ "\n\tExample: " + COMMAND_WORD
+ " CS2113T Tutorial st/0800 et/0900 date/tuesday l/COM2 r/norecess r/noreading "
+ " t/tutorial t/cs2113t t/module";

public static final String MESSAGE_SUCCESS = "New slot added: %1$s";
// public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
public static final String MESSAGE_SUCCESS = "New slot(s) added: %1$s";
public static final String MESSAGE_SUCCESS_NO_CHANGE = "No slots were added.";
public static final String MESSAGE_FAIL_OUT_OF_BOUNCE = "Date specified is out of bounce.";

private final Slot slot;
private final Pair<Slot, Recurrence> toAdd;

/**
* Convenience constructor using raw values.
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public AddCommandP(String name, String location, String description, String startTime,
int duration, Set<String> tags) throws IllegalValueException {
public AddCommandP(String date, String name, String location, String description, String startTime,
String endTime, Set<String> tags, Set<String> recurrences) throws IllegalValueException {

final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
}

// check variable date if it is a date or day
int day = Utils.getDay(date);
if (day != 0) {
toAdd = new Pair<>(new Slot(new Name(name), new Location(location), new Description(description),
Utils.parseTime(startTime), Utils.parseTime(endTime), tagSet), new Recurrence(recurrences, day));
} else {
toAdd = new Pair<>(new Slot(new Name(name), new Location(location), new Description(description),
Utils.parseTime(startTime), Utils.parseTime(endTime), tagSet),
new Recurrence(recurrences, Utils.parseDate(date)));
}
}

/**
* Convenience constructor using raw values.
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public AddCommandP(String date, String name, String location, String description, String startTime,
int duration, Set<String> tags, Set<String> recurrences) throws IllegalValueException {
final Set<Tag> tagSet = new HashSet<>();

for (String tagName : tags) {
tagSet.add(new Tag(tagName));
}

this.slot = new Slot(new Name(name), new Location(location), new Description(description),
Utils.getLocalTime(startTime), duration, tagSet);
// check variable date if it is a date or day
int day = Utils.getDay(date);
if (day != 0) {
toAdd = new Pair<>(new Slot(new Name(name), new Location(location), new Description(description),
Utils.parseTime(startTime), duration, tagSet), new Recurrence(recurrences, day));
} else {
toAdd = new Pair<>(new Slot(new Name(name), new Location(location), new Description(description),
Utils.parseTime(startTime), duration, tagSet), new Recurrence(recurrences, Utils.parseDate(date)));
}
}

public AddCommandP(Slot slot) {
this.slot = slot;
public AddCommandP(Pair<Slot, Recurrence> toAdd) {
this.toAdd = toAdd;
}
public ReadOnlySlot getSlot() {
return slot;

public Pair<? extends ReadOnlySlot, Recurrence> getSlots() {
return toAdd;
}

@Override
public CommandResultP execute() {
// try {
planner.addSlot(slot);
return new CommandResultP(String.format(MESSAGE_SUCCESS, slot));
// } catch (UniquePersonList.DuplicatePersonException dpe) {
// return new CommandResult(MESSAGE_DUPLICATE_PERSON);
// }
try {
int addCount = planner.addSlots(toAdd);

if (addCount == 1) {
return new CommandResultP(MESSAGE_SUCCESS_NO_CHANGE);
} else {
return new CommandResultP(String.format(MESSAGE_SUCCESS, toAdd));
}
} catch (Semester.DayNotFoundException dnfe) {
return new CommandResultP(MESSAGE_FAIL_OUT_OF_BOUNCE);
}

}

}
2 changes: 1 addition & 1 deletion src/planmysem/commands/CommandResultP.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CommandResultP {
public final String feedbackToUser;

/**
* The list of persons that was produced by the command
* The list of days that was produced by the command
*/
private final HashMap<LocalDate, ? extends ReadOnlyDay> days;

Expand Down
19 changes: 19 additions & 0 deletions src/planmysem/commands/ExitCommandP.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package planmysem.commands;

/**
* Terminates the program.
*/
public class ExitCommandP extends CommandP {

public static final String COMMAND_WORD = "exit";

public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Exits the program.\n\t"
+ "Example: " + COMMAND_WORD;
public static final String MESSAGE_EXIT_ACKNOWEDGEMENT = "Exiting PlanMySem as requested ...";

@Override
public CommandResultP execute() {
return new CommandResultP(MESSAGE_EXIT_ACKNOWEDGEMENT);
}

}
107 changes: 104 additions & 3 deletions src/planmysem/common/Utils.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
package planmysem.common;

import static java.time.temporal.ChronoUnit.MINUTES;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Utility methods
*/
public class Utils {
public static final Pattern DATE_FORMAT =
Pattern.compile("(0?[1-9]|[12][0-9]|3[01])-(0?[1-9]|1[012])-((19|20)\\d\\d)");

public static final Pattern TWELVE_HOUR_FORMAT =
Pattern.compile("(1[012]|[1-9]):[0-5][0-9](\\s)?(?i)(am|pm)");
public static final Pattern TWENTY_FOUR_HOUR_FORMAT =
Pattern.compile("([01]?[0-9]|2[0-3]):[0-5][0-9]\n");

/**
* Checks whether any of the given items are null.
Expand Down Expand Up @@ -37,9 +50,97 @@ public static boolean elementsAreUnique(Collection<?> items) {
}

/**
* TODO
* Check if String represents an actual date or day.
* Returns 0 if string does not represent a DayOfWeek, else returns int corresponding to the day.
*/
public static int getDay(String unknown) {
String day = unknown.toLowerCase();

int result = 0;
switch (day) {
case "monday":
case "mon":
case "1":
result = 1;
break;

case "tuesday":
case "tues":
case "2":
result = 2;
break;

case "wednesday":
case "wed":
case "3":
result = 3;
break;
case "thursday":
case "thurs":
case "4":
result = 4;
break;

case "friday":
case "fri":
case "5":
result = 5;
break;

default:
result = 0;
}

return result;
}

/**
* Parse String LocalDate.
*/
public static LocalDate parseDate(String date) {
LocalDate localDate = null;
Matcher dateMatcher = DATE_FORMAT.matcher(date);

if (dateMatcher.matches()) {
localDate = LocalDate.parse(date, DateTimeFormatter.ofPattern("d-MM-yyyy"));
}

return localDate;
}

/**
* Parse String to 12 hour or 24 hour time format.
*/
public static LocalTime parseTime(String time) {
LocalTime localTime = null;
Matcher twelveHourMatcher = TWELVE_HOUR_FORMAT.matcher(time);
Matcher twentyFourHourMatcher = TWENTY_FOUR_HOUR_FORMAT.matcher(time);

// Parse start time into 12 hour format, else, as 24 Hour Format
if (twelveHourMatcher.matches()) {
localTime = LocalTime.parse(time, DateTimeFormatter.ofPattern("hh:mm:ss a"));
} else if (twentyFourHourMatcher.matches()) {
localTime = LocalTime.parse(time, DateTimeFormatter.ofPattern("kk:mm:ss"));
}

return localTime;
}

/**
* Get the time difference between two LocalTimes
*/
public static int getDuration(LocalTime startTime, LocalTime endTime) {
return (int) MINUTES.between(startTime, endTime);
}

/**
* Get number of matches
*/
public static LocalTime getLocalTime(String date) {
return LocalTime.of(1, 1, 1);
public static int countMatches(Matcher matcher) {
int counter = 0;
while (matcher.find()) {
counter++;
}
return counter;
}
}
Loading

0 comments on commit ac99165

Please sign in to comment.