Skip to content

Commit

Permalink
Merge pull request #69 from AY2122S2-CS2103T-T09-4/develop
Browse files Browse the repository at this point in the history
Final feature update for v1.2
  • Loading branch information
MechFroG88 authored Mar 16, 2022
2 parents 2b5ccdb + 18d3761 commit 670bc57
Show file tree
Hide file tree
Showing 66 changed files with 1,523 additions and 692 deletions.
4 changes: 4 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changes

# Related Issues/ PRs
- Fixes # (issue)
5 changes: 3 additions & 2 deletions src/main/java/seedu/ibook/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ public AddCommand parse(String args) throws ParseException {
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_CATEGORY, PREFIX_EXPIRY_DATE, PREFIX_DESCRIPTION,
PREFIX_PRICE);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_CATEGORY, PREFIX_EXPIRY_DATE, PREFIX_DESCRIPTION,
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_EXPIRY_DATE, PREFIX_DESCRIPTION,
PREFIX_PRICE) || !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Category category = ParserUtil.parseCategory(argMultimap.getValue(PREFIX_CATEGORY).get());
Category category =
ParserUtil.parseCategory(argMultimap.getValue(PREFIX_CATEGORY).orElse(Category.DEFAULT_CATEGORY));
ExpiryDate expiryDate = ParserUtil.parseExpiryDate(argMultimap.getValue(PREFIX_EXPIRY_DATE).get());
Description description = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get());
Price price = ParserUtil.parsePrice(argMultimap.getValue(PREFIX_PRICE).get());
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/ibook/logic/parser/FindCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,35 @@ public FindCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
} else {
name = Name.WILDNAME;
name = Name.WILD_NAME;
wildCard--;
}

if (argMultimap.getValue(PREFIX_CATEGORY).isPresent()) {
category = ParserUtil.parseCategory(argMultimap.getValue(PREFIX_CATEGORY).get());
} else {
category = Category.WILDCATEGORY;
category = Category.WILD_CATEGORY;
wildCard--;
}

if (argMultimap.getValue(PREFIX_EXPIRY_DATE).isPresent()) {
expiryDate = ParserUtil.parseExpiryDate(argMultimap.getValue(PREFIX_EXPIRY_DATE).get());
} else {
expiryDate = ExpiryDate.WILDEXPIRYDATE;
expiryDate = ExpiryDate.WILD_EXPIRY_DATE;
wildCard--;
}

if (argMultimap.getValue(PREFIX_DESCRIPTION).isPresent()) {
description = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get());
} else {
description = Description.WILDDESCRIPTION;
description = Description.WILD_DESCRIPTION;
wildCard--;
}

if (argMultimap.getValue(PREFIX_PRICE).isPresent()) {
price = ParserUtil.parsePrice(argMultimap.getValue(PREFIX_PRICE).get());
} else {
price = Price.WILDPRICE;
price = Price.WILD_PRICE;
wildCard--;
}

Expand Down
22 changes: 10 additions & 12 deletions src/main/java/seedu/ibook/model/product/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@
*/
public class Category {

private static class WildCategory extends Category {
private WildCategory() {};

public static final Category WILD_CATEGORY = new Category() {
@Override
public boolean equals(Object other) {
if (other instanceof Category) {
return true;
} else {
return false;
}
return other instanceof Category;
}
}
public static final WildCategory WILDCATEGORY = new WildCategory();
};

public static final String DEFAULT_CATEGORY = "Miscellaneous";

public static final String MESSAGE_CONSTRAINTS =
"Categories (if given) should only contain alphanumeric characters and spaces";
Expand All @@ -38,7 +33,7 @@ public boolean equals(Object other) {
* Constructs a {@code Category} representing no categorization.
*/
private Category() {
fullCategoryName = "";
fullCategoryName = DEFAULT_CATEGORY;
}

/**
Expand All @@ -53,7 +48,10 @@ public Category(String categoryName) {
}

/**
* Returns true if a given string is a valid category name.
* Checks if the string is valid as per {@code VALIDATION_REGEX}.
*
* @param test String to test.
* @return Result of test.
*/
public static boolean isValidCategoryName(String test) {
return test.matches(VALIDATION_REGEX);
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/seedu/ibook/model/product/Description.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@
*/
public class Description {

private static class WildDescription extends Description {
private WildDescription() {};

public static final Description WILD_DESCRIPTION = new Description() {
@Override
public boolean equals(Object other) {
if (other instanceof Description) {
return true;
} else {
return false;
}
return other instanceof Description;
}
}
public static final WildDescription WILDDESCRIPTION = new WildDescription();
};

public static final String MESSAGE_CONSTRAINTS =
"Descriptions should only contain alphanumeric characters and spaces";

Expand All @@ -35,7 +29,7 @@ public boolean equals(Object other) {

private Description() {
fullDescription = "???";
};
}

/**
* Constructs a {@code Description}.
Expand All @@ -49,7 +43,10 @@ public Description(String description) {
}

/**
* Returns true if a given string is a valid description.
* Checks if the string is valid as per {@code VALIDATION_REGEX}.
*
* @param test String to test.
* @return Result of test.
*/
public static boolean isValidDescription(String test) {
return test.matches(VALIDATION_REGEX);
Expand Down
19 changes: 7 additions & 12 deletions src/main/java/seedu/ibook/model/product/ExpiryDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@
*/
public class ExpiryDate {

private static class WildExpiryDate extends ExpiryDate {
private WildExpiryDate() {};

public static final ExpiryDate WILD_EXPIRY_DATE = new ExpiryDate() {
@Override
public boolean equals(Object other) {
if (other instanceof ExpiryDate) {
return true;
} else {
return false;
}
return other instanceof ExpiryDate;
}
}

public static final WildExpiryDate WILDEXPIRYDATE = new WildExpiryDate();
};

public static final String MESSAGE_CONSTRAINTS =
"Expiry dates should have format such as 03 May 2022, 3 May 2022 or 2022-05-03";
Expand Down Expand Up @@ -62,7 +54,10 @@ public ExpiryDate(String date) {
}

/**
* Returns true if a given {@code LocalDate} is a valid expiry date.
* Checks if a given {@code LocalDate} is valid as per {@code VALIDATION_REGEX}.
*
* @param expiryDate Date to test.
* @return Result of test.
*/
public static boolean isValidExpiryDate(String expiryDate) {
return Arrays.stream(ACCEPTED_FORMATS)
Expand Down
22 changes: 7 additions & 15 deletions src/main/java/seedu/ibook/model/product/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,12 @@
*/
public class Name {

private static class WildName extends Name {
private WildName() {};

public static final Name WILD_NAME = new Name() {
@Override
public boolean equals(Object other) {
if (other instanceof Name) {
return true;
} else {
return false;
}
return other instanceof Name;
}

}

public static final WildName WILDNAME = new WildName();
};

public static final String MESSAGE_CONSTRAINTS =
"Names should only contain alphanumeric characters and spaces, and it should not be blank";
Expand All @@ -36,8 +27,6 @@ public boolean equals(Object other) {

public final String fullName;



private Name() {
fullName = "???";
}
Expand All @@ -54,7 +43,10 @@ public Name(String name) {
}

/**
* Returns true if a given string is a valid name.
* Checks if the string is valid as per {@code VALIDATION_REGEX}.
*
* @param test String to test.
* @return Result of test.
*/
public static boolean isValidName(String test) {
return test.matches(VALIDATION_REGEX);
Expand Down
36 changes: 23 additions & 13 deletions src/main/java/seedu/ibook/model/product/Price.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,21 @@
*/
public class Price {

private static class WildPrice extends Price {
private WildPrice() {};

public static final Price WILD_PRICE = new Price() {
@Override
public boolean equals(Object other) {
if (other instanceof Price) {
return true;
} else {
return false;
}
return other instanceof Price;
}
};

}

public static final WildPrice WILDPRICE = new WildPrice();
public static final String MESSAGE_CONSTRAINTS =
"Prices should only be of type double, and should not be negative";

/*
* The first character of the name must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "\\d+(?:.\\d{1,2})?";
public static final String VALIDATION_REGEX = "\\$?(\\d+(?:.\\d{1,2})?)";

public final Double price;

Expand All @@ -47,16 +39,34 @@ private Price() {
public Price(String price) {
requireNonNull(price);
checkArgument(isValidPrice(price), MESSAGE_CONSTRAINTS);

price = removeDollarSign(price);
this.price = Double.parseDouble(price);
}

/**
* Returns true if a given string is a valid price.
* Checks if the string is valid as per {@code VALIDATION_REGEX}.
*
* @param test String to test.
* @return Result of test.
*/
public static boolean isValidPrice(String test) {
return test.matches(VALIDATION_REGEX);
}

/**
* Removes "$" sign (if any) from a price string.
*
* @param price Price string.
* @return Price string with "$" sign removed (if any).
*/
private String removeDollarSign(String price) {
if (price.startsWith("$")) {
return price.substring(1);
}

return price;
}

@Override
public String toString() {
Expand Down
54 changes: 0 additions & 54 deletions src/main/java/seedu/ibook/model/tag/Tag.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/java/seedu/ibook/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package seedu.ibook.model.util;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

import seedu.ibook.model.IBook;
import seedu.ibook.model.ReadOnlyIBook;
import seedu.ibook.model.product.Category;
Expand All @@ -12,7 +8,6 @@
import seedu.ibook.model.product.Name;
import seedu.ibook.model.product.Price;
import seedu.ibook.model.product.Product;
import seedu.ibook.model.tag.Tag;

/**
* Contains utility methods for populating {@code AddressBook} with sample data.
Expand All @@ -26,15 +21,6 @@ public static Product[] getSampleProducts() {
};
}

/**
* Returns a tag set containing the list of strings given.
*/
public static Set<Tag> getTagSet(String... strings) {
return Arrays.stream(strings)
.map(Tag::new)
.collect(Collectors.toSet());
}

public static ReadOnlyIBook getSampleIBook() {
IBook sampleIb = new IBook();
for (Product sampleProduct : getSampleProducts()) {
Expand Down
Loading

0 comments on commit 670bc57

Please sign in to comment.