Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tingxuanp committed Oct 17, 2024
2 parents de8bcf1 + fef883f commit 76b488c
Show file tree
Hide file tree
Showing 69 changed files with 2,808 additions and 407 deletions.
19 changes: 19 additions & 0 deletions src/main/java/seedu/address/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ public static boolean containsPartialWordIgnoreCase(String sentence, String word
return preppedSentence.contains(preppedWord);
}

/**
* Returns true if the {@code phoneNumber} contains the {@code searchNumber}.
* Only a partial match is required.
* <br>examples:<pre>
* containsPhoneNumber("99209378", "92") == true // partial match
* containsPhoneNumber("99209378", "9378") == true // partial match
* containsPhoneNumber("82810284", "82810284") == true // full match
* containsPhoneNumber("99209378", "86") == false // no partial match with number
* </pre>
* @param phoneNumber cannot be null
* @param searchNumber cannot be null, cannot be empty
*/
public static boolean containsPhoneNumber(String phoneNumber, String searchNumber) {
requireNonNull(phoneNumber);
requireNonNull(searchNumber);
checkArgument(!searchNumber.isEmpty(), "Phone number parameter cannot be empty");
return phoneNumber.toLowerCase().contains(searchNumber.toLowerCase());
}

/**
* Returns a detailed message of the t, including the stack trace.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ public class Messages {
public static final String MESSAGE_TAG_NOT_FOUND_IN_CONTACT = "Some tags were not found in the person's tag list.";
public static final String MESSAGE_ADD_TAG_SUCCESS = "Added tag(s) %1$s to %2$s.";
public static final String MESSAGE_ADD_WEDDING_SUCCESS = "Added wedding(s) %1$s to %2$s.";
public static final String MESSAGE_REMOVE_WEDDING_SUCCESS = "Removed wedding(s) %1$s from %2$s.";
public static final String MESSAGE_WEDDING_NOT_FOUND = "One or more specified weddings do not exist in "
+ "the Wedlinker.";
public static final String MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT = "Some weddings were not found in "
+ "the person's wedding list.";
public static final String MESSAGE_FORCE_ASSIGN_WEDDING_TO_CONTACT = "Use f/ to force the assignment of wedding(s)."
+ " This will create the required Wedding objects.";

/**
* Returns an error message indicating the duplicate prefixes.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.commands;

import static seedu.address.logic.Messages.MESSAGE_ADD_WEDDING_SUCCESS;
import static seedu.address.logic.Messages.MESSAGE_FORCE_ASSIGN_WEDDING_TO_CONTACT;
import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX;
import static seedu.address.logic.Messages.MESSAGE_WEDDING_NOT_FOUND;

Expand Down Expand Up @@ -33,6 +34,7 @@ public class AssignWeddingCommand extends Command {

private final Index index;
private final HashSet<Wedding> weddingsToAdd;
private boolean force = false;

/**
* Constructs a {@code AssignWedding} Command to add weddings to a person.
Expand All @@ -44,6 +46,18 @@ public AssignWeddingCommand(Index index, HashSet<Wedding> weddingsToAdd) {
this.weddingsToAdd = weddingsToAdd;
}

/**
* Constructs a {@code AssignWedding} Command to add weddings to a person with the force flag.
* @param index The index of the person in the person list.
* @param weddingsToAdd The list of weddings to be added.
* @param force Whether the command should force the assignment by creating the Wedding object.
*/
public AssignWeddingCommand(Index index, HashSet<Wedding> weddingsToAdd, boolean force) {
this.index = index;
this.weddingsToAdd = weddingsToAdd;
this.force = force;
}

/**
* Generates a command execution success message showing the added weddings and the person.
*
Expand All @@ -69,7 +83,13 @@ public CommandResult execute(Model model) throws CommandException {

for (Wedding wedding : weddingsToAdd) {
if (!model.hasWedding(wedding)) {
throw new CommandException(MESSAGE_WEDDING_NOT_FOUND);
if (this.force) {
CreateWeddingCommand newWeddingCommand = new CreateWeddingCommand(wedding);
newWeddingCommand.execute(model);
} else {
throw new CommandException(
MESSAGE_WEDDING_NOT_FOUND + "\n" + MESSAGE_FORCE_ASSIGN_WEDDING_TO_CONTACT);
}
}
}

Expand Down
58 changes: 0 additions & 58 deletions src/main/java/seedu/address/logic/commands/FilterCommand.java

This file was deleted.

65 changes: 0 additions & 65 deletions src/main/java/seedu/address/logic/commands/FindCommand.java

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/java/seedu/address/logic/commands/TagCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_ADD_TAG_SUCCESS;
import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX;
import static seedu.address.logic.Messages.MESSAGE_TAG_NOT_FOUND;
Expand Down Expand Up @@ -41,6 +42,8 @@ public class TagCommand extends Command {
* @param tagsToAdd The list of tags to be added.
*/
public TagCommand(Index index, HashSet<Tag> tagsToAdd) {
requireNonNull(index);
requireNonNull(tagsToAdd);
this.index = index;
this.tagsToAdd = tagsToAdd;
}
Expand Down Expand Up @@ -74,6 +77,10 @@ public CommandResult execute(Model model) throws CommandException {
}
}

for (Tag tag : tagsToAdd) {
tag.increaseTaggedCount();
}

Set<Tag> updatedTags = new HashSet<>(personToEdit.getTags());
updatedTags.addAll(tagsToAdd);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.commands;

import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX;
import static seedu.address.logic.Messages.MESSAGE_REMOVE_WEDDING_SUCCESS;
import static seedu.address.logic.Messages.MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT;

import java.util.HashSet;
Expand All @@ -19,7 +20,6 @@
*/
public class UnassignWeddingCommand extends Command {
public static final String COMMAND_WORD = "unassign-wedding";
public static final String MESSAGE_REMOVE_WEDDING_SUCCESS = "Removed wedding(s) %1$s from %2$s.";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Removes one or multiple weddings from the person identified "
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/seedu/address/logic/commands/UntagCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX;
import static seedu.address.logic.Messages.MESSAGE_TAG_NOT_FOUND_IN_CONTACT;

Expand Down Expand Up @@ -40,6 +41,8 @@ public class UntagCommand extends Command {
* @param tagsToRemove The list of tags to be removed.
*/
public UntagCommand(Index index, HashSet<Tag> tagsToRemove) {
requireNonNull(index);
requireNonNull(tagsToRemove);
this.index = index;
this.tagsToRemove = tagsToRemove;
}
Expand Down Expand Up @@ -72,15 +75,16 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_TAG_NOT_FOUND_IN_CONTACT);
}

if (tagsToRemove.isEmpty()) {
throw new CommandException(MESSAGE_TAG_NOT_FOUND_IN_CONTACT);
}

if (!updatedTags.containsAll(tagsToRemove)) {
throw new CommandException(MESSAGE_TAG_NOT_FOUND_IN_CONTACT);
}

updatedTags.removeAll(tagsToRemove);

for (Tag tag : tagsToRemove) {
tag.decreaseTaggedCount();
}

Person editedPerson = new Person(
personToEdit.getName(),
personToEdit.getPhone(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package seedu.address.logic.commands.findcommand;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;
import seedu.address.model.person.keywordspredicate.AddressContainsKeywordsPredicate;
/**
* Finds and lists all persons in address book whose address contains any of the argument keywords.
* Keyword matching is case-insensitive and allows partial matching.
*/
public class FindAddressCommand extends FindCommand {

public static final String MESSAGE_FIND_ADDRESS_PERSON_SUCCESS = "Search for address containing \"%s\" "
+ " was successful. Showing results:";

/**
* Command to filter contacts in WedLinker based on phone numbers.
* The search matches any parts of the phone numbers.
*
* @param predicate Keywords used to filter contacts by their phone number.
*/
public FindAddressCommand(AddressContainsKeywordsPredicate predicate) {
super(predicate);
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList((AddressContainsKeywordsPredicate) predicate);

if (!model.getFilteredPersonList().isEmpty()) {
return new CommandResult(String.format(MESSAGE_FIND_ADDRESS_PERSON_SUCCESS, predicate.getDisplayString()));
} else {
return new CommandResult(MESSAGE_FIND_PERSON_UNSUCCESSFUL);
}
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

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

return predicate.equals(otherFindCommand.predicate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package seedu.address.logic.commands.findcommand;

import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;
import seedu.address.model.person.keywordspredicate.TraitContainsKeywordsPredicate;

/**
* Finds and lists all persons in address book whose name contains any of the argument keywords.
* Keyword matching is case-insensitive and allows partial matching.
*/
public abstract class FindCommand extends Command {

public static final String COMMAND_WORD = "find";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons based on the specified keywords "
+ "(case-insensitive) after the prefix representing the field, "
+ "and displays them as a list with index numbers.\n"
+ "Use 'n/' to search by name, 'a/' to search by address etc. \n"
+ "Parameters: PREFIX/ KEYWORDS [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " " + PREFIX_NAME + " alice charlie";

public static final String MESSAGE_FIND_PERSON_UNSUCCESSFUL = "No contacts found.";

protected final TraitContainsKeywordsPredicate<?> predicate;

public FindCommand(TraitContainsKeywordsPredicate<?> predicate) {
this.predicate = predicate;
}

@Override
public abstract CommandResult execute(Model model);

@Override
public abstract boolean equals(Object other);

@Override
public String toString() {
return new ToStringBuilder(this)
.add("predicate", predicate)
.toString();
}
}
Loading

0 comments on commit 76b488c

Please sign in to comment.