Skip to content

Commit

Permalink
Merge pull request #61 from FionaQY/fix-tier-bugs
Browse files Browse the repository at this point in the history
Fix Tier bugs
  • Loading branch information
ZShunRen authored Oct 16, 2024
2 parents 0d02ae1 + 59e16ce commit bf30d68
Show file tree
Hide file tree
Showing 23 changed files with 119 additions and 121 deletions.
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIER;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
Expand All @@ -31,15 +31,15 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_JOB + "JOB "
+ PREFIX_INCOME + "INCOME "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "[" + PREFIX_TIER + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_JOB + "doctor "
+ PREFIX_INCOME + "300 "
+ PREFIX_TAG + "GOLD "
+ PREFIX_TIER + "GOLD "
+ PREFIX_REMARK + "owesMoney";

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_JOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIER;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.List;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_JOB + "JOB] "
+ "[" + PREFIX_INCOME + "INCOME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "[" + PREFIX_TIER + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "[email protected]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_JOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIER;

import java.util.stream.Stream;

Expand Down Expand Up @@ -36,7 +36,7 @@ public class AddCommandParser implements Parser<AddCommand> {
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_JOB,
PREFIX_INCOME, PREFIX_TAG);
PREFIX_INCOME, PREFIX_TIER);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_JOB, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_INCOME)
Expand All @@ -45,14 +45,14 @@ public AddCommand parse(String args) throws ParseException {
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_JOB,
PREFIX_INCOME);
PREFIX_INCOME, PREFIX_TIER);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Job job = ParserUtil.parseJob(argMultimap.getValue(PREFIX_JOB).get());
Income income = ParserUtil.parseIncome(argMultimap.getValue(PREFIX_INCOME).get());
Tier tier = ParserUtil.parseTag(argMultimap.getValue(PREFIX_TAG).orElse("NA"));
Tier tier = ParserUtil.parseTier(argMultimap.getValue(PREFIX_TIER).orElse("NA"));
Remark remark = new Remark(""); // add command does not allow adding remarks straight away
Person person = new Person(name, phone, email, address, job, income, tier, remark);
return new AddCommand(person);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CliSyntax {
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_JOB = new Prefix("j/");
public static final Prefix PREFIX_INCOME = new Prefix("i/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_TIER = new Prefix("t/");
public static final Prefix PREFIX_REMARK = new Prefix("r/");

}
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_JOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIER;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.EditCommand;
Expand All @@ -29,7 +29,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_INCOME, PREFIX_JOB, PREFIX_TAG);
PREFIX_INCOME, PREFIX_JOB, PREFIX_TIER);

Index index;

Expand All @@ -40,7 +40,7 @@ public EditCommand parse(String args) throws ParseException {
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_INCOME, PREFIX_JOB);
PREFIX_INCOME, PREFIX_JOB, PREFIX_TIER);

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();

Expand All @@ -62,8 +62,8 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_INCOME).isPresent()) {
editPersonDescriptor.setIncome(ParserUtil.parseIncome(argMultimap.getValue(PREFIX_INCOME).get()));
}
if (argMultimap.getValue(PREFIX_TAG).isPresent()) {
editPersonDescriptor.setTier(ParserUtil.parseTag(argMultimap.getValue(PREFIX_TAG).get()));
if (argMultimap.getValue(PREFIX_TIER).isPresent()) {
editPersonDescriptor.setTier(ParserUtil.parseTier(argMultimap.getValue(PREFIX_TIER).get()));
}
if (!editPersonDescriptor.isAnyFieldEdited()) {
throw new ParseException(EditCommand.MESSAGE_NOT_EDITED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIER;

import java.util.Arrays;

Expand All @@ -36,14 +36,14 @@ public FilterCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_INCOME, PREFIX_JOB, PREFIX_REMARK, PREFIX_TAG);
PREFIX_INCOME, PREFIX_JOB, PREFIX_REMARK, PREFIX_TIER);

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_INCOME, PREFIX_JOB, PREFIX_REMARK, PREFIX_TAG);
PREFIX_INCOME, PREFIX_JOB, PREFIX_REMARK, PREFIX_TIER);

// Filtering by multiple fields/flags has not been implemented yet
long numberOfFiltersUsed = countPrefixesUsed(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_JOB, PREFIX_INCOME, PREFIX_REMARK, PREFIX_TAG);
PREFIX_ADDRESS, PREFIX_JOB, PREFIX_INCOME, PREFIX_REMARK, PREFIX_TIER);
if (numberOfFiltersUsed > 1) {
throw new ParseException(FilterCommand.MULTIPLE_FILTERS_NOT_IMPLEMENTED);
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ public static Remark parseRemark(String remark) throws ParseException {
*
* @throws ParseException if the given {@code tag} is invalid.
*/
public static Tier parseTag(String tag) throws ParseException {
public static Tier parseTier(String tag) throws ParseException {
requireNonNull(tag);
String trimmedTag = tag.trim();
if (!Tier.isValidTagName(trimmedTag)) {
if (trimmedTag.isEmpty()) {
trimmedTag = Tier.TierEnum.NA.toString();
}
if (!Tier.isValidTierName(trimmedTag)) {
throw new ParseException(Tier.MESSAGE_CONSTRAINTS);
}
return new Tier(trimmedTag);
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/seedu/address/model/tier/Tier.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/**
* Represents a Tag in the address book.
* Guarantees: immutable; name is valid as declared in {@link #isValidTagName(String)}
* Guarantees: immutable; name is valid as declared in {@link #isValidTierName(String)}
*/
public class Tier {

Expand All @@ -21,14 +21,17 @@ public class Tier {
*/
public Tier(String tagName) {
requireNonNull(tagName);
checkArgument(isValidTagName(tagName), MESSAGE_CONSTRAINTS);
this.tagName = TierEnum.valueOf(tagName.toUpperCase());;
if (tagName.isEmpty()) {
tagName = TierEnum.NA.toString();
}
checkArgument(isValidTierName(tagName), MESSAGE_CONSTRAINTS);
this.tagName = TierEnum.valueOf(tagName.toUpperCase());
}

/**
* Returns true if a given string is a valid tag name.
*/
public static boolean isValidTagName(String test) {
public static boolean isValidTierName(String test) {
for (TierEnum c : TierEnum.values()) {
if (c.name().equals(test.toUpperCase())) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/storage/JsonAdaptedTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public String getTagName() {
* @throws IllegalValueException if there were any data constraints violated in the adapted tag.
*/
public Tier toModelType() throws IllegalValueException {
if (!Tier.isValidTagName(tagName)) {
if (!Tier.isValidTierName(tagName)) {
throw new IllegalValueException(Tier.MESSAGE_CONSTRAINTS);
}
return new Tier(tagName);
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_JOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIER;
import static seedu.address.testutil.Assert.assertThrows;

import java.util.ArrayList;
Expand Down Expand Up @@ -54,8 +54,8 @@ public class CommandTestUtil {
public static final String JOB_DESC_BOB = " " + PREFIX_JOB + VALID_JOB_BOB;
public static final String INCOME_DESC_AMY = " " + PREFIX_INCOME + VALID_INCOME_AMY;
public static final String INCOME_DESC_BOB = " " + PREFIX_INCOME + VALID_INCOME_BOB;
public static final String TAG_DESC_REJECT = " " + PREFIX_TAG + VALID_TIER_REJECT;
public static final String TAG_DESC_GOLD = " " + PREFIX_TAG + VALID_TIER_GOLD;
public static final String TIER_DESC_REJECT = " " + PREFIX_TIER + VALID_TIER_REJECT;
public static final String TIER_DESC_GOLD = " " + PREFIX_TIER + VALID_TIER_GOLD;

public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones
Expand All @@ -64,7 +64,7 @@ public class CommandTestUtil {
public static final String INVALID_JOB_DESC = " " + PREFIX_JOB; // empty string not allowed for job
public static final String INVALID_INCOME_DESC = " " + PREFIX_INCOME + "-999"; // negative numbers should not be
// allowed
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags
public static final String INVALID_TIER_DESC = " " + PREFIX_TIER + "platinum"; // not one of the 4 TierEnums

public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";
Expand All @@ -79,12 +79,12 @@ public class CommandTestUtil {
DESC_AMY = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY)
.withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY)
.withJob(VALID_JOB_AMY).withIncome(Integer.parseInt(VALID_INCOME_AMY))
.withTiers(VALID_TIER_GOLD).build();
.withTier(VALID_TIER_GOLD).build();

DESC_BOB = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB)
.withJob(VALID_JOB_BOB).withIncome(Integer.parseInt(VALID_INCOME_BOB))
.withTiers(VALID_TIER_REJECT).build();
.withTier(VALID_TIER_REJECT).build();
}
/**
* Executes the given {@code command}, confirms that <br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() {

PersonBuilder personInList = new PersonBuilder(lastPerson);
Person editedPerson = personInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
.withTiers(VALID_TIER_REJECT).build();
.withTier(VALID_TIER_REJECT).build();

EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB).withTiers(VALID_TIER_REJECT).build();
.withPhone(VALID_PHONE_BOB).withTier(VALID_TIER_REJECT).build();
EditCommand editCommand = new EditCommand(indexLastPerson, descriptor);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void equals() {
assertFalse(DESC_AMY.equals(editedAmy));

// different tags -> returns false
editedAmy = new EditPersonDescriptorBuilder(DESC_AMY).withTiers(VALID_TIER_REJECT).build();
editedAmy = new EditPersonDescriptorBuilder(DESC_AMY).withTier(VALID_TIER_REJECT).build();
assertFalse(DESC_AMY.equals(editedAmy));
}

Expand Down
Loading

0 comments on commit bf30d68

Please sign in to comment.