Skip to content

Commit

Permalink
Merge pull request #37 from tiuweehan/update-ui
Browse files Browse the repository at this point in the history
Refactor UI, Storage and Validations
  • Loading branch information
tiuweehan authored Sep 30, 2019
2 parents 8db4653 + 681fd3a commit 8cf90fa
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 58 deletions.
10 changes: 5 additions & 5 deletions src/main/java/seedu/algobase/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public AddCommand parse(String args) throws ParseException {
}

WebLink webLink;
if (arePrefixesPresent(argMultimap, PREFIX_AUTHOR)) {
if (arePrefixesPresent(argMultimap, PREFIX_WEBLINK)) {
webLink = ParserUtil.parseWeblink(argMultimap.getValue(PREFIX_WEBLINK).get());
} else {
webLink = WebLink.DEFAULT_WEBLINK;
}

Description description;
if (arePrefixesPresent(argMultimap, PREFIX_AUTHOR)) {
if (arePrefixesPresent(argMultimap, PREFIX_DESCRIPTION)) {
description = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get());
} else {
description = Description.DEFAULT_DESCRIPTION;
Expand All @@ -76,21 +76,21 @@ public AddCommand parse(String args) throws ParseException {
}

Difficulty difficulty;
if (arePrefixesPresent(argMultimap, PREFIX_AUTHOR)) {
if (arePrefixesPresent(argMultimap, PREFIX_DIFFICULTY)) {
difficulty = ParserUtil.parseDifficulty(argMultimap.getValue(PREFIX_DIFFICULTY).get());
} else {
difficulty = Difficulty.DEFAULT_DIFFICULTY;
}

Remark remark;
if (arePrefixesPresent(argMultimap, PREFIX_AUTHOR)) {
if (arePrefixesPresent(argMultimap, PREFIX_REMARK)) {
remark = ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK).get());
} else {
remark = Remark.DEFAULT_REMARK;
}

Source source;
if (arePrefixesPresent(argMultimap, PREFIX_AUTHOR)) {
if (arePrefixesPresent(argMultimap, PREFIX_SOURCE)) {
source = ParserUtil.parseSource(argMultimap.getValue(PREFIX_SOURCE).get());
} else {
source = Source.DEFAULT_SOURCE;
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/seedu/algobase/model/problem/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Author {

public static final String MESSAGE_CONSTRAINTS =
"Author numbers should only contain numbers, and it should be at least 3 digits long";
public static final String DEFAULT_AUTHOR_STRING = "";
public static final Author DEFAULT_AUTHOR = new Author();

/*
Expand All @@ -33,11 +34,25 @@ public Author(String author) {
}

private Author() {
value = "";
value = DEFAULT_AUTHOR_STRING;
}

/**
* Returns true if a given string is a valid author number.
* Returns true if a given String matches the default author String.
*/
public static boolean isDefaultAuthor(String test) {
return test.equals(DEFAULT_AUTHOR_STRING);
}

/**
* Returns true if a given {@code Author} is the default author.
*/
public static boolean isDefaultAuthor(Author author) {
return author == DEFAULT_AUTHOR;
}

/**
* Returns true if a given string is a valid author.
*/
public static boolean isValidAuthor(String test) {
return test.matches(VALIDATION_REGEX);
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/seedu/algobase/model/problem/Description.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class Description {

public static final String MESSAGE_CONSTRAINTS = "Descriptions can take any values, and it should not be blank";
public static final String DEFAULT_DESCRIPTION_STRING = "";
public static final Description DEFAULT_DESCRIPTION = new Description();

/*
Expand All @@ -32,11 +33,25 @@ public Description(String description) {
}

private Description() {
value = "";
value = DEFAULT_DESCRIPTION_STRING;
}

/**
* Returns true if a given string is a valid weblink.
* Returns true if a given string matches the default description string.
*/
public static boolean isDefaultDescription(String test) {
return test.equals(DEFAULT_DESCRIPTION_STRING);
}

/**
* Returns true if a given {@code Description} is the default description.
*/
public static boolean isDefaultDescription(Description test) {
return test == DEFAULT_DESCRIPTION;
}

/**
* Returns true if a given string is a valid description.
*/
public static boolean isValidDescription(String test) {
return test.matches(VALIDATION_REGEX);
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/seedu/algobase/model/problem/Difficulty.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Difficulty {
public static final String MESSAGE_CONSTRAINTS = "Difficulty should be numeric.";
public static final double DIFFICULTY_LOWER_BOUND = 0.0;
public static final double DIFFICULTY_UPPER_BOUND = 5.0;
public static final double DEFAULT_DIFFICULTY_VALUE = DIFFICULTY_LOWER_BOUND;
public static final Difficulty DEFAULT_DIFFICULTY = new Difficulty();
public static final String VALIDATION_REGEX = "\\d+.\\d+";
public final double value;
Expand All @@ -28,7 +29,25 @@ public Difficulty(String difficulty) {
}

private Difficulty() {
value = 0.0;
value = DEFAULT_DIFFICULTY_VALUE;
}

/**
* Returns true if a given string matches the default difficulty value.
*/
public static boolean isDefaultDifficulty(String test) {
try {
return Double.parseDouble(test) == DEFAULT_DIFFICULTY_VALUE;
} catch (NumberFormatException ex) {
return false;
}
}

/**
* Returns true if a given {@code Difficulty} is the default difficulty.
*/
public static boolean isDefaultDifficulty(Difficulty test) {
return test == DEFAULT_DIFFICULTY;
}

/**
Expand All @@ -45,13 +64,6 @@ public static boolean isValidDifficulty(String test) {
}
}

/**
* Returns true if a given {@code Difficulty} is default.
*/
public static boolean isDefaultDifficulty(Difficulty difficulty) {
return difficulty == DEFAULT_DIFFICULTY;
}

@Override
public String toString() {
return Double.toString(value);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/algobase/model/problem/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class Name {
"Names should only contain alphanumeric characters and spaces, and it should not be blank";

/*
* The first character of the name must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
* A name is any combination of the following characters: A-Z, a-z, ', . or whitespace.
* A name must contain at least one non-whitespace character.
*/
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
public static final String VALIDATION_REGEX = "^([A-z\\'\\.-ᶜ]+(\\s)*)*$";

public final String fullName;

Expand Down
21 changes: 16 additions & 5 deletions src/main/java/seedu/algobase/model/problem/Remark.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public class Remark {
public static final Remark DEFAULT_REMARK = new Remark();

/*
* A remark is a combination of characters or whitespaces.
* The first character of the solution must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[^\\s].*";
public static final String VALIDATION_REGEX = "^\\S[\\s\\S]*$";

public final String value;

Expand All @@ -41,17 +42,27 @@ private Remark() {
value = DEFAULT_REMARK_STRING;
}

/**
* Returns true if a given String matches the default remark String.
*/
public static boolean isDefaultRemark(String test) {
return test.equals(DEFAULT_REMARK_STRING);
}

/**
* Returns true if a given {@code Remark} is the default remark.
*/
public static boolean isDefaultRemark(Remark test) {
return test == DEFAULT_REMARK;
}

/**
* Returns true if a given string is a valid remark.
*/
public static boolean isValidRemark(String test) {
return test.matches(VALIDATION_REGEX);
}

public static boolean isDefaultRemark(Remark remark) {
return remark == DEFAULT_REMARK;
}

@Override
public String toString() {
return value;
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/seedu/algobase/model/problem/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,27 @@ private Source() {
value = DEFAULT_SOURCE_STRING;
}

/**
* Returns true if a given string matches the default source string.
*/
public static boolean isDefaultSource(String test) {
return test.equals(DEFAULT_SOURCE_STRING);
}

/**
* Returns true if a given {@code Source} is the default source.
*/
public static boolean isDefaultSource(Source test) {
return test == DEFAULT_SOURCE;
}

/**
* Returns true if a given string is a valid source.
*/
public static boolean isValidSource(String test) {
return test.matches(VALIDATION_REGEX);
}

public static boolean isDefaultSource(Source source) {
return source == DEFAULT_SOURCE;
}

@Override
public String toString() {
return value;
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/seedu/algobase/model/problem/WebLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class WebLink {
public static final String MESSAGE_CONSTRAINTS = "Weblinks should be parsable by java.net.URL";
public static final String VALIDATION_REGEX =
"<\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]>";
public static final String DEFAULT_WEBLINK_STRING = "";
public static final WebLink DEFAULT_WEBLINK = new WebLink();

public final String value;
Expand All @@ -31,11 +32,25 @@ public WebLink(String weblink) {
}

private WebLink() {
value = "";
value = DEFAULT_WEBLINK_STRING;
}

/**
* Returns if a given string is a valid weblink.
* Returns true if a given string matches the default weblink string.
*/
public static boolean isDefaultWeblink(String test) {
return test.equals(DEFAULT_WEBLINK_STRING);
}

/**
* Returns true if a given {@code Weblink} is a default weblink.
*/
public static boolean isDefaultWeblink(WebLink test) {
return test == DEFAULT_WEBLINK;
}

/**
* Returns true if a given string is a valid weblink.
*/
public static boolean isValidWeblink(String test) {
try {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/algobase/model/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
*/
public class Tag {

public static final String MESSAGE_CONSTRAINTS = "Tags names should be alphanumeric";
public static final String VALIDATION_REGEX = "\\p{Alnum}+";
public static final String MESSAGE_CONSTRAINTS =
"Tags names should contain only alphabets, numbers, hyphen or underscore";
public static final String VALIDATION_REGEX = "^[a-zA-Z0-9_-]*$";

public final String tagName;

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/seedu/algobase/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public static Problem[] getSampleProblems() {
new WebLink("https://leetcode.com/problems/two-sum/"),
new Description("Given an array of integers, "
+ "return indices of the two numbers such that they add up to a specific target."),
getTagSet("array", "hash table", "algorithm"),
getTagSet("array", "hash-table", "algorithm"),
new Difficulty("1.0"),
new Remark("You may assume that each input would have exactly one solution, "
new Remark("You may assume that each input would have exactly one solution, \n"
+ "and you may not use the same element twice."),
new Source("LeetCode")),
new Problem(new Name("Second Highest Salary"), new Author("LeetCode"),
Expand All @@ -49,16 +49,16 @@ public static Problem[] getSampleProblems() {
new Problem(new Name("Sudoku Solver"), Author.DEFAULT_AUTHOR,
new WebLink("https://leetcode.com/problems/sudoku-solver/"),
Description.DEFAULT_DESCRIPTION,
getTagSet("hash table", "backtracking", "algorithm"),
getTagSet("hash-table", "backtracking", "algorithm"),
new Difficulty("5.0"),
new Remark("You may assume that the given Sudoku puzzle will have a single unique solution."),
new Source("LeetCode")),
new Problem(new Name("A. Dawid and Bags of Candies"), Author.DEFAULT_AUTHOR,
new Problem(new Name("A Dawid and Bags of Candies"), Author.DEFAULT_AUTHOR,
new WebLink("https://codeforces.com/problemset/problem/1230/A"),
Description.DEFAULT_DESCRIPTION,
getTagSet("brute force"),
getTagSet("brute-force"),
new Difficulty("4.0"),
new Remark("time limit per test1 second\n" + "memory limit per test256 megabytes"),
new Remark("time limit per test1 second" + "memory limit per test256 megabytes"),
new Source("CodeForce")),
new Problem(new Name("Factorial"), new Author("Wee Han"), WebLink.DEFAULT_WEBLINK,
new Description("define a function factorial that takes in a number n "
Expand Down
Loading

0 comments on commit 8cf90fa

Please sign in to comment.