-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CompareCommand.java for compare command
- Loading branch information
1 parent
6c7d09b
commit 4ad6022
Showing
5 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package seedu.duke.command; | ||
|
||
import seedu.duke.exception.DukeException; | ||
import seedu.duke.ui.Ui; | ||
import seedu.duke.user.User; | ||
import seedu.duke.user.UserList; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
import seedu.duke.task.Event; | ||
|
||
public class CompareCommand extends Command{ | ||
|
||
public CompareCommand(String input) { | ||
super(input); | ||
} | ||
|
||
@Override | ||
public void execute(UserList users, Ui ui, User nowUser) throws DukeException { | ||
|
||
ArrayList<Integer> outputArray = new ArrayList<Integer>(Arrays.asList(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23)); | ||
|
||
if (nowUser != null) { | ||
String[] parsedInputs = input.split(" /", 3); | ||
String targetName = parsedInputs[0].substring(1); | ||
String date = parsedInputs[1]; | ||
ArrayList<Event> nowUserTimetable; | ||
ArrayList<Event> targetUserTimetable; | ||
|
||
User targetUser = users.getUserByName(targetName); //implement a function to return user from UserList based on name | ||
|
||
if (targetUser == null){ | ||
throw new DukeException("No such user!"); | ||
} | ||
|
||
switch (date) { | ||
case "mon": | ||
nowUserTimetable = nowUser.getTimetable().getTimetable("mon"); | ||
targetUserTimetable = targetUser.getTimetable().getTimetable("mon"); | ||
break; | ||
case "tue": | ||
nowUserTimetable = nowUser.getTimetable().getTimetable("tue"); | ||
targetUserTimetable = targetUser.getTimetable().getTimetable("tue"); | ||
break; | ||
case "wed": | ||
nowUserTimetable = nowUser.getTimetable().getTimetable("wed"); | ||
targetUserTimetable = targetUser.getTimetable().getTimetable("wed"); | ||
break; | ||
case "thu": | ||
nowUserTimetable = nowUser.getTimetable().getTimetable("thu"); | ||
targetUserTimetable = targetUser.getTimetable().getTimetable("thu"); | ||
break; | ||
case "fri": | ||
nowUserTimetable = nowUser.getTimetable().getTimetable("fri"); | ||
targetUserTimetable = targetUser.getTimetable().getTimetable("fri"); | ||
break; | ||
case "sat": | ||
nowUserTimetable = nowUser.getTimetable().getTimetable("sat"); | ||
targetUserTimetable = targetUser.getTimetable().getTimetable("sat"); | ||
break; | ||
case "sun": | ||
nowUserTimetable = nowUser.getTimetable().getTimetable("sun"); | ||
targetUserTimetable = targetUser.getTimetable().getTimetable("sun"); | ||
break; | ||
default: | ||
throw new DukeException("Sorry! I don't know what day you mean :-("); | ||
} | ||
|
||
/** | ||
* Compare targetUser and nowUser Timetables (ArrayList<Object>) | ||
* Assuming for each day of the week, timetable ArrayList<Object> contains only [0:23] timeslots | ||
* Loop below returns an outputArray that holds the common available hours in that day | ||
*/ | ||
for (Event event : nowUserTimetable){ | ||
int temp_x = (Integer.valueOf(Integer.parseInt(event.getTimeStart().substring(0,2)))); | ||
int temp_y = (Integer.valueOf(Integer.parseInt(event.getTimeEnd().substring(0,2)))); | ||
|
||
for (int i = temp_x; i<temp_y+1 ; i++){ | ||
outputArray.remove(Integer.valueOf(i)); | ||
} | ||
} | ||
|
||
for (Event event : targetUserTimetable){ | ||
int temp_x = (Integer.valueOf(Integer.parseInt(event.getTimeStart().substring(0,2)))); | ||
int temp_y = (Integer.valueOf(Integer.parseInt(event.getTimeEnd().substring(0,2)))); | ||
|
||
for (int i = temp_x; i<=temp_y ; i++){ | ||
outputArray.remove(Integer.valueOf(i)); | ||
} | ||
} | ||
|
||
ui.printCompare(outputArray); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters