Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into branch-SortEvent
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/ezschedule/logic/Logic.java
#	src/main/java/ezschedule/logic/LogicManager.java
#	src/main/java/ezschedule/model/Model.java
#	src/test/java/ezschedule/logic/commands/AddCommandTest.java
  • Loading branch information
lhy-hoyin committed Mar 27, 2023
2 parents 02f3827 + 6553c5a commit 32506d8
Show file tree
Hide file tree
Showing 36 changed files with 853 additions and 171 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ dependencies {
}

shadowJar {
dependsOn test
dependsOn checkstyleMain
dependsOn checkstyleTest
archiveFileName = 'Ez-Schedule.jar'
doLast {
println "Generated *.jar can be found at /build/libs/"
}
}

defaultTasks 'clean', 'test'
2 changes: 1 addition & 1 deletion src/main/java/ezschedule/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected Config initConfig(Path configFilePath) {
initializedConfig = configOptional.orElse(new Config());
} catch (DataConversionException e) {
logger.warning("Config file at " + configFilePathUsed + " is not in the correct format. "
+ "Using default config properties");
+ "Using default config properties");
initializedConfig = new Config();
}

Expand Down
15 changes: 11 additions & 4 deletions src/main/java/ezschedule/logic/Logic.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ezschedule.logic;

import java.nio.file.Path;
import java.util.function.Predicate;

import ezschedule.commons.core.GuiSettings;
import ezschedule.logic.commands.CommandResult;
Expand Down Expand Up @@ -34,18 +35,24 @@ public interface Logic {

/**
* Returns an unmodifiable view of the upcoming list of events
*
* @return
*/
ObservableList<Event> getUpcomingEventList();

/**
* Returns an unmodifiable view of the list of events
*/
ObservableList<Event> getEventList();

/**
* Returns an unmodifiable view of the filtered list of events
*
* @return
*/
ObservableList<Event> getFilteredEventList();

/**
* Updates the filtered list of events
*/
void updateFilteredEventList(Predicate<Event> predicate);

/**
* Returns the user prefs' scheduler file path.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/ezschedule/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.function.Predicate;
import java.util.logging.Logger;

import ezschedule.commons.core.GuiSettings;
Expand Down Expand Up @@ -64,11 +65,21 @@ public ObservableList<Event> getUpcomingEventList() {
return model.getUpcomingEventList();
}

@Override
public ObservableList<Event> getEventList() {
return model.getEventList();
}

@Override
public ObservableList<Event> getFilteredEventList() {
return model.getFilteredEventList();
}

@Override
public void updateFilteredEventList(Predicate<Event> predicate) {
model.updateFilteredEventList(predicate);
}

@Override
public Path getSchedulerFilePath() {
return model.getSchedulerFilePath();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/ezschedule/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ public static class EditEventDescriptor {
private Time startTime;
private Time endTime;

public EditEventDescriptor() {
}
public EditEventDescriptor() {}

/**
* Copy constructor.
Expand Down
103 changes: 94 additions & 9 deletions src/main/java/ezschedule/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

import static java.util.Objects.requireNonNull;

import java.util.Arrays;
import java.util.Optional;

import ezschedule.commons.core.Messages;
import ezschedule.logic.parser.CliSyntax;
import ezschedule.model.Model;
import ezschedule.model.event.Date;
import ezschedule.model.event.EventContainsKeywordsPredicate;
import ezschedule.model.event.EventMatchesDatePredicate;
import ezschedule.model.event.EventMatchesKeywordsAndDatePredicate;
import ezschedule.model.event.Name;

/**
* Finds and lists all events in scheduler whose name contains any of the argument keywords.
Expand All @@ -14,29 +22,106 @@ public class FindCommand extends Command {

public static final String COMMAND_WORD = "find";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds events that contain keyword provided"
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds events that contain keyword provided "
+ "and displays them as a list with index number \n"
+ "Parameters: KEYWORD [MORE_KEYWORDS] ... \n"
+ "Example: " + COMMAND_WORD + " booking basketball court";
+ "Parameters: "
+ CliSyntax.PREFIX_NAME + "NAME "
+ CliSyntax.PREFIX_DATE + "DATE "
+ "\nExample: " + COMMAND_WORD + " "
+ "Example: " + COMMAND_WORD + " "
+ CliSyntax.PREFIX_NAME + "basketball court "
+ CliSyntax.PREFIX_DATE + "2023-01-01 ";

private final EventContainsKeywordsPredicate predicate;
private final FindEventDescriptor findEventDescriptor;

public FindCommand(EventContainsKeywordsPredicate predicate) {
this.predicate = predicate;
public FindCommand(FindEventDescriptor findEventDescriptor) {
this.findEventDescriptor = findEventDescriptor;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredEventList(predicate);
if (findEventDescriptor.getName().isPresent() && findEventDescriptor.getDate().isPresent()) {
String[] nameKeywords = findEventDescriptor.getName().get().toString().split("\\s+");
Date date = findEventDescriptor.getDate().get();
EventMatchesKeywordsAndDatePredicate predicate =
new EventMatchesKeywordsAndDatePredicate(Arrays.asList(nameKeywords), date);
model.updateFilteredEventList(predicate);

} else if (findEventDescriptor.getName().isPresent()) {
String[] nameKeywords = findEventDescriptor.getName().get().toString().split("\\s+");
EventContainsKeywordsPredicate predicate = new EventContainsKeywordsPredicate(Arrays.asList(nameKeywords));
model.updateFilteredEventList(predicate);

} else {
Date date = findEventDescriptor.getDate().get();
EventMatchesDatePredicate predicate = new EventMatchesDatePredicate(date);
model.updateFilteredEventList(predicate);
}

return new CommandResult(
String.format(Messages.MESSAGE_EVENTS_LISTED_OVERVIEW, model.getFilteredEventList().size()));
String.format(Messages.MESSAGE_EVENTS_LISTED_OVERVIEW, model.getFilteredEventList().size()));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof FindCommand // instanceof handles nulls
&& predicate.equals(((FindCommand) other).predicate)); // state check
&& findEventDescriptor.equals(((FindCommand) other).findEventDescriptor)); // state check
}

/**
* Stores the details to find the event with.
* Each non-empty field value will replace the corresponding field value of the event.
*/
public static class FindEventDescriptor {

private Name name;
private Date date;

public FindEventDescriptor() {}

/**
* Copy constructor.
*/
public FindEventDescriptor(FindEventDescriptor toCopy) {
setName(toCopy.name);
setDate(toCopy.date);
}

public Optional<Name> getName() {
return Optional.ofNullable(name);
}

public void setName(Name name) {
this.name = name;
}

public Optional<Date> getDate() {
return Optional.ofNullable(date);
}

public void setDate(Date date) {
this.date = date;
}

@Override
public boolean equals(Object other) {
// short circuit if same object
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof FindEventDescriptor)) {
return false;
}

// state check
FindEventDescriptor e = (FindEventDescriptor) other;

return getName().equals(e.getName())
&& getDate().equals(e.getDate());
}
}
}
31 changes: 24 additions & 7 deletions src/main/java/ezschedule/logic/parser/FindCommandParser.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
package ezschedule.logic.parser;

import java.util.Arrays;
import java.util.stream.Stream;

import ezschedule.commons.core.Messages;
import ezschedule.logic.commands.FindCommand;
import ezschedule.logic.commands.FindCommand.FindEventDescriptor;
import ezschedule.logic.parser.exceptions.ParseException;
import ezschedule.model.event.EventContainsKeywordsPredicate;

/**
* Parses input arguments and creates a new FindCommand object
*/
public class FindCommandParser implements Parser<FindCommand> {

/**
* Returns true if any of the prefixes contains empty {@code Optional} values
* in the given {@code ArgumentMultimap}.
*/
private static boolean areAnyPrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) {
return Stream.of(prefixes).anyMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
}

/**
* Parses the given {@code String} of arguments in the context of the FindCommand
* and returns a FindCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format
*/
public FindCommand parse(String args) throws ParseException {
String trimmedArgs = args.trim();
if (trimmedArgs.isEmpty()) {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, CliSyntax.PREFIX_NAME, CliSyntax.PREFIX_DATE);

if (!areAnyPrefixesPresent(argMultimap, CliSyntax.PREFIX_NAME, CliSyntax.PREFIX_DATE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(
String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}

String[] nameKeywords = trimmedArgs.split("\\s+");
FindEventDescriptor findEventDescriptor = new FindEventDescriptor();
if (argMultimap.getValue(CliSyntax.PREFIX_NAME).isPresent()) {
findEventDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(CliSyntax.PREFIX_NAME).get()));
}
if (argMultimap.getValue(CliSyntax.PREFIX_DATE).isPresent()) {
findEventDescriptor.setDate(ParserUtil.parseDate(argMultimap.getValue(CliSyntax.PREFIX_DATE).get()));
}

return new FindCommand(new EventContainsKeywordsPredicate(Arrays.asList(nameKeywords)));
return new FindCommand(findEventDescriptor);
}
}
14 changes: 10 additions & 4 deletions src/main/java/ezschedule/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public interface Model {
void setSchedulerFilePath(Path schedulerFilePath);

/**
* Replaces scheduler data with the data in {@code scheduler}.
* Returns the Scheduler
*/
void setScheduler(ReadOnlyScheduler scheduler);
ReadOnlyScheduler getScheduler();

/**
* Returns the Scheduler
* Replaces scheduler data with the data in {@code scheduler}.
*/
ReadOnlyScheduler getScheduler();
void setScheduler(ReadOnlyScheduler scheduler);

/**
* Returns true if an event with the same identity as {@code event} exists in the Scheduler.
Expand Down Expand Up @@ -90,6 +90,12 @@ public interface Model {
*/
ObservableList<Event> getUpcomingEventList();

/**
* Returns an unmodifiable view of the event list
*/
ObservableList<Event> getEventList();


/**
* Returns an unmodifiable view of the filtered event list
*/
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/ezschedule/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void setEvent(Event target, Event editedEvent) {
scheduler.setEvent(target, editedEvent);
}

//=========== Filtered Event List Accessors =============================================================
//=========== Event List Accessors =============================================================

/**
* Returns an unmodifiable view of the list of {@code Event} backed by the internal list of
Expand All @@ -131,6 +131,11 @@ public ObservableList<Event> getUpcomingEventList() {
* Returns an unmodifiable view of the list of {@code Event} backed by the internal list of
* {@code scheduler}
*/
@Override
public ObservableList<Event> getEventList() {
return scheduler.getEventList();
}

@Override
public ObservableList<Event> getFilteredEventList() {
return filteredEvents;
Expand All @@ -157,7 +162,7 @@ public boolean equals(Object obj) {
// state check
ModelManager other = (ModelManager) obj;
return scheduler.equals(other.scheduler)
&& userPrefs.equals(other.userPrefs)
&& filteredEvents.equals(other.filteredEvents);
&& userPrefs.equals(other.userPrefs)
&& filteredEvents.equals(other.filteredEvents);
}
}
1 change: 0 additions & 1 deletion src/main/java/ezschedule/model/Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public void setEvents(List<Event> events) {
*/
public void resetData(ReadOnlyScheduler newData) {
requireNonNull(newData);

setEvents(newData.getEventList());
}

Expand Down
Loading

0 comments on commit 32506d8

Please sign in to comment.