forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/KhoonSun47/tp
* 'master' of https://github.com/KhoonSun47/tp: (24 commits) Fix ParserUtilTest.java lexicographical order Fix ParserUtil.java Error Fix checkstyle of ParserUtilTest.java Update ParserUtilTest.java Fix ParserUtilTest.java Fix checkstyle in ParserUtil.java Fix ParserUtil.java Issue #46: Add Unit Number Add test cases for street parser Update ParserUtil to parse Street inputs Add test cases for level parser Update ParserUtil to parse Level inputs Fix level input validation Issue #46: Add Unit Number Issue #46: Add Unit Number Issue #46: Add Unit Number Issue #46: Add Unit Number Fix typo in method name Add a prefix for street field Add test cases for Street class ...
- Loading branch information
Showing
9 changed files
with
502 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package seedu.address.model.house; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
|
||
/** | ||
* Represents a House's level. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidLevel(String)} | ||
*/ | ||
public class Level { | ||
|
||
public static final String MESSAGE_CONSTRAINTS = | ||
"Level should only contain numbers, and it should only be at most 2 digits long"; | ||
public static final String VALIDATION_REGEX = "\\d{1,2}"; | ||
public static final String ZERO_REGEX = "^0+$"; | ||
|
||
public final String value; | ||
|
||
/** | ||
* Constructs a {@code Level}. | ||
* | ||
* @param level A valid level. | ||
*/ | ||
public Level(String level) { | ||
requireNonNull(level); | ||
checkArgument(isValidLevel(level), MESSAGE_CONSTRAINTS); | ||
value = level; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid level. | ||
*/ | ||
public static boolean isValidLevel(String test) { | ||
return test.matches(VALIDATION_REGEX) && !test.matches(ZERO_REGEX); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof Level)) { | ||
return false; | ||
} | ||
|
||
Level otherLevel = (Level) other; | ||
return value.equals(otherLevel.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package seedu.address.model.house; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
/** | ||
* Represents a House's street. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidStreet(String)} | ||
*/ | ||
public class Street { | ||
|
||
public static final String MESSAGE_CONSTRAINTS = | ||
"Street should only contain alphanumeric characters and hyphens."; | ||
public static final String VALIDATION_REGEX = "^(?=.*[a-zA-Z0-9])[a-zA-Z0-9\\s-]+$"; | ||
public final String value; | ||
|
||
/** | ||
* Constructs a {@code Street}. | ||
* | ||
* @param street A valid street. | ||
*/ | ||
public Street(String street) { | ||
requireNonNull(street); | ||
checkArgument(isValidStreet(street), MESSAGE_CONSTRAINTS); | ||
value = street; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid street. | ||
*/ | ||
public static boolean isValidStreet(String test) { | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof Street)) { | ||
return false; | ||
} | ||
|
||
Street otherStreet = (Street) other; | ||
return value.equals(otherStreet.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package seedu.address.model.house; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
/** | ||
* Represents a House's unit number in the address book. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidUnitNumber(String)} | ||
*/ | ||
public class UnitNumber { | ||
|
||
public static final String MESSAGE_CONSTRAINTS = | ||
"The unit number should only contain numbers, it should be at least 1 digit " | ||
+ "and at most 3 digits long, and cannot be '0', '00' or '000'."; | ||
public static final String VALIDATION_REGEX = "\\d{1,3}"; | ||
public static final String ZERO_REGEX = "^0+$"; | ||
|
||
public final String value; | ||
|
||
/** | ||
* Constructs a {@code UnitNumber}. | ||
* | ||
* @param unitNumber A valid unit number. | ||
*/ | ||
public UnitNumber(String unitNumber) { | ||
requireNonNull(unitNumber); | ||
checkArgument(isValidUnitNumber(unitNumber), MESSAGE_CONSTRAINTS); | ||
value = unitNumber; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid unit number. | ||
* | ||
* @param test The string to test. | ||
* @return true if the test matches the VALIDATION_REGEX and is not "0". | ||
*/ | ||
public static boolean isValidUnitNumber(String test) { | ||
return test.matches(VALIDATION_REGEX) && !test.matches(ZERO_REGEX); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof UnitNumber)) { | ||
return false; | ||
} | ||
|
||
UnitNumber otherUnitNumber = (UnitNumber) other; | ||
return value.equals(otherUnitNumber.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.