Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into pr/129
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelim01 committed Oct 25, 2023
2 parents 9f57075 + 80f7fda commit 819b6d0
Show file tree
Hide file tree
Showing 41 changed files with 621 additions and 323 deletions.
7 changes: 7 additions & 0 deletions src/main/java/wedlog/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import wedlog.address.logic.commands.CommandResult;
import wedlog.address.logic.commands.exceptions.CommandException;
import wedlog.address.logic.parser.exceptions.ParseException;
import wedlog.address.model.DietaryRequirementStatistics;
import wedlog.address.model.ReadOnlyAddressBook;
import wedlog.address.model.RsvpStatistics;
import wedlog.address.model.person.Guest;
Expand Down Expand Up @@ -62,4 +63,10 @@ public interface Logic {
* @return {@code RsvpStatistics}
*/
RsvpStatistics getRsvpStatistics();

/**
* Returns a {@code DietaryRequirementStatistics} with information about the dietary requirements of guests.
* @return {@code DietaryRequirementStatistics}
*/
DietaryRequirementStatistics getDietaryRequirementStatistics();
}
6 changes: 6 additions & 0 deletions src/main/java/wedlog/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import wedlog.address.logic.commands.exceptions.CommandException;
import wedlog.address.logic.parser.AddressBookParser;
import wedlog.address.logic.parser.exceptions.ParseException;
import wedlog.address.model.DietaryRequirementStatistics;
import wedlog.address.model.Model;
import wedlog.address.model.ReadOnlyAddressBook;
import wedlog.address.model.RsvpStatistics;
Expand Down Expand Up @@ -104,4 +105,9 @@ public RsvpStatistics getRsvpStatistics() {
return model.getRsvpStatistics();
}

@Override
public DietaryRequirementStatistics getDietaryRequirementStatistics() {
return model.getDietaryRequirementStatistics();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import wedlog.address.logic.commands.GuestAddCommand;
import wedlog.address.logic.parser.exceptions.ParseException;
import wedlog.address.model.person.Address;
import wedlog.address.model.person.DietaryRequirements;
import wedlog.address.model.person.Email;
import wedlog.address.model.person.Guest;
import wedlog.address.model.person.Name;
import wedlog.address.model.person.Phone;
import wedlog.address.model.person.RsvpStatus;
import wedlog.address.model.person.TableNumber;
import wedlog.address.model.tag.DietaryRequirement;
import wedlog.address.model.tag.Tag;

/**
Expand All @@ -46,9 +46,9 @@ public GuestAddCommand parse(String args) throws ParseException {
// message usage is a generic message about how to use the add command for guests
}

// throws parse exception if any field (except tags) is inputted twice
// throws parse exception if any field (except dietary and tags) is inputted twice
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_RSVP,
PREFIX_DIETARY, PREFIX_TABLE);
PREFIX_TABLE);

// marks the optional fields null if they are empty
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Expand All @@ -58,9 +58,8 @@ public GuestAddCommand parse(String args) throws ParseException {
RsvpStatus rsvpStatus = argMultimap.getValue(PREFIX_RSVP).isEmpty()
? RsvpStatus.unknown() // no input defaults to Status stored as unknown
: ParserUtil.parseRsvp(argMultimap.getValue(PREFIX_RSVP).get());
DietaryRequirements dietaryRequirements = argMultimap.getValue(PREFIX_DIETARY).isEmpty()
? new DietaryRequirements(null)
: ParserUtil.parseDietary(argMultimap.getValue(PREFIX_DIETARY).get());
Set<DietaryRequirement> dietaryRequirements =
ParserUtil.parseDietaryRequirements(argMultimap.getAllValues(PREFIX_DIETARY));
TableNumber tableNumber = argMultimap.getValue(PREFIX_TABLE).isEmpty()
? null
: ParserUtil.parseTable(argMultimap.getValue(PREFIX_TABLE).get());
Expand Down
33 changes: 22 additions & 11 deletions src/main/java/wedlog/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import wedlog.address.commons.util.StringUtil;
import wedlog.address.logic.parser.exceptions.ParseException;
import wedlog.address.model.person.Address;
import wedlog.address.model.person.DietaryRequirements;
import wedlog.address.model.person.Email;
import wedlog.address.model.person.Name;
import wedlog.address.model.person.Phone;
import wedlog.address.model.person.RsvpStatus;
import wedlog.address.model.person.TableNumber;
import wedlog.address.model.tag.DietaryRequirement;
import wedlog.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -107,19 +107,32 @@ public static RsvpStatus parseRsvp(String rsvp) throws ParseException {
}

/**
* Parses a {@code String dietaryRequirements} into a {@code DietaryRequirements}.
* Parses a {@code String dietaryRequirement} into a {@code DietaryRequirement}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code rsvp} is invalid.
* @throws ParseException if the given {@code dietaryRequirement} is invalid.
*/
public static DietaryRequirements parseDietary(String dietaryRequirements) {

if (dietaryRequirements == null) {
return new DietaryRequirements(null);
public static DietaryRequirement parseDietaryRequirement(String dietaryRequirement) throws ParseException {
requireNonNull(dietaryRequirement);
String trimmedDietaryRequirement = dietaryRequirement.trim();
if (!DietaryRequirement.isValidDietaryRequirement(trimmedDietaryRequirement)) {
throw new ParseException(DietaryRequirement.MESSAGE_CONSTRAINTS);
}
return new DietaryRequirement(trimmedDietaryRequirement);
}

String trimmedDietaryRequirements = dietaryRequirements.trim();
return new DietaryRequirements(trimmedDietaryRequirements);
/**
* Parses {@code Collection<String> dietaryRequirements} into a {@code Set<DietaryRequirement>}.
*/
public static Set<DietaryRequirement> parseDietaryRequirements(Collection<String> dietaryRequirements)
throws ParseException {
requireNonNull(dietaryRequirements);
final Set<DietaryRequirement> dietarySet = new HashSet<>();
for (String dietary : dietaryRequirements) {
// takes in a list of strings & parse then put into a hashset
dietarySet.add(parseDietaryRequirement(dietary));
}
return dietarySet;
}

/**
Expand Down Expand Up @@ -202,8 +215,6 @@ public static <R> R parseOptionally(Optional<String> optionalString, ParserFunct
return null;
}

//@@author

/**
* Returns the result of parsing {@code String} with the given
* parser function if {@code string} is not empty, else returns null.
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/wedlog/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ public RsvpStatistics getRsvpStatistics() {
guests.getNumGuestsRsvpUnknown());
}

/**
* Returns a {@code DietaryRequirementStatistics} with information on the dietary requirements of guests
* @return {@code DietaryRequirementStatistics}
*/
public DietaryRequirementStatistics getDietaryRequirementStatistics() {
return guests.getDietaryRequirementStatistics();
}

//// vendor-level operations

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package wedlog.address.model;

import java.util.HashMap;

/**
* This class encapsulates the dietary requirement statistics of the guests.
* It stores each dietary requirement as a key and the number of guests with that dietary requirement as the value.
* @author Keagan
*/
public class DietaryRequirementStatistics {
private final HashMap<String, Integer> dietaryRequirementMap;

/**
* Constructor for an empty {@code DietaryRequirementStatistics} object.
*/
public DietaryRequirementStatistics() {
this.dietaryRequirementMap = new HashMap<>();
}

/**
* Constructor for a {@code DietaryRequirementStatistics} object.
* @param dietaryRequirementMap The map of dietary requirements to the number of guests
* with that dietary requirement.
*/
public DietaryRequirementStatistics(HashMap<String, Integer> dietaryRequirementMap) {
this.dietaryRequirementMap = dietaryRequirementMap;
}

public HashMap<String, Integer> getMap() {
return this.dietaryRequirementMap;
}

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

if (!(other instanceof DietaryRequirementStatistics)) {
return false;
}

DietaryRequirementStatistics otherDietaryRequirementStatistics = (DietaryRequirementStatistics) other;
return this.dietaryRequirementMap.equals(otherDietaryRequirementStatistics.dietaryRequirementMap);
}
}
7 changes: 7 additions & 0 deletions src/main/java/wedlog/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ public interface Model {
*/
RsvpStatistics getRsvpStatistics();

/**
* Returns a {@code DietaryRequirementStatistics} with information of the dietary requirements of guests in
* {@code AddressBook}.
* @return {@code DietaryRequirementStatistics} object.
*/
DietaryRequirementStatistics getDietaryRequirementStatistics();

/**
* Returns true if a vendor with the same identity as {@code vendor} exists in the address book.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/wedlog/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public RsvpStatistics getRsvpStatistics() {
return addressBook.getRsvpStatistics();
}

@Override
public DietaryRequirementStatistics getDietaryRequirementStatistics() {
return addressBook.getDietaryRequirementStatistics();
}

@Override
public boolean hasVendor(Vendor vendor) {
requireNonNull(vendor);
Expand Down
88 changes: 0 additions & 88 deletions src/main/java/wedlog/address/model/person/DietaryRequirements.java

This file was deleted.

20 changes: 13 additions & 7 deletions src/main/java/wedlog/address/model/person/Guest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import static wedlog.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import wedlog.address.commons.util.ToStringBuilder;
import wedlog.address.model.tag.DietaryRequirement;
import wedlog.address.model.tag.Tag;

/**
Expand All @@ -17,28 +20,31 @@ public class Guest extends Person {

// Additional data fields
private final RsvpStatus rsvpStatus;
private final DietaryRequirements dietaryRequirements;
private final Set<DietaryRequirement> dietaryRequirements = new HashSet<>();
private final Optional<TableNumber> tableNumber;

/**
* Name, rsvp status, dietary requirements and tags must be present and not null.
*/
public Guest(Name name, Phone phone, Email email, Address address, RsvpStatus rsvpStatus,
DietaryRequirements dietaryRequirements, TableNumber tableNumber, Set<Tag> tags) {
Set<DietaryRequirement> dietaryRequirements, TableNumber tableNumber, Set<Tag> tags) {
super(name, phone, email, address, tags);
requireAllNonNull(rsvpStatus);
requireAllNonNull(rsvpStatus, dietaryRequirements);
this.rsvpStatus = rsvpStatus;
this.dietaryRequirements =
Objects.requireNonNullElseGet(dietaryRequirements, () -> new DietaryRequirements(null));
this.dietaryRequirements.addAll(dietaryRequirements);
this.tableNumber = Optional.ofNullable(tableNumber);
}

public RsvpStatus getRsvpStatus() {
return rsvpStatus;
}

public DietaryRequirements getDietaryRequirements() {
return dietaryRequirements;
/**
* Returns an immutable dietary requirement set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
*/
public Set<DietaryRequirement> getDietaryRequirements() {
return Collections.unmodifiableSet(dietaryRequirements);
}

public Optional<TableNumber> getTableNumber() {
Expand Down
Loading

0 comments on commit 819b6d0

Please sign in to comment.