-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[W5][T12-4]Lau Wei Tang #169
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,12 +60,14 @@ Put a `p` before the phone / email / address prefixes to mark it as `private`. ` | |
be seen using the `viewall` command. | ||
|
||
Persons can have any number of tags (including 0). | ||
|
||
Address must be of this format: `blockNumber, streetNumber, unitNumber, postalCodeNumber` | ||
**** | ||
|
||
Examples: | ||
|
||
* `add John Doe p/98765432 e/[email protected] a/John street, block 123, #01-01` | ||
* `add Betsy Crowe pp/1234567 e/[email protected] pa/Newgate Prison t/criminal t/friend` | ||
* `add John Doe p/98765432 e/[email protected] a/123, John street, #01-01, S111111` | ||
* `add Betsy Crowe pp/1234567 e/[email protected] pa/Newgate Prison, Newgate street, #21-03, S222222 t/criminal t/friend` | ||
|
||
== Listing all persons : `list` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ public class AddCommand extends Command { | |
+ "Contact details can be marked private by prepending 'p' to the prefix.\n" | ||
+ "Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...\n" | ||
+ "Example: " + COMMAND_WORD | ||
+ " John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney"; | ||
+ " John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25, S600292 t/friends t/owesMoney"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New person added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,25 @@ | |
|
||
import seedu.addressbook.data.exception.IllegalValueException; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Represents a Person's address in the address book. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidAddress(String)} | ||
*/ | ||
public class Address { | ||
|
||
public static final String EXAMPLE = "123, some street"; | ||
public static final String MESSAGE_ADDRESS_CONSTRAINTS = "Person addresses can be in any format"; | ||
public static final String EXAMPLE = "123, some street, some unit, some postal code"; | ||
public static final String MESSAGE_ADDRESS_CONSTRAINTS = "Person addresses must have 4 parameters only."; | ||
public static final String ADDRESS_VALIDATION_REGEX = ".+"; | ||
|
||
//public final String value; | ||
private final Block block; | ||
private final Street street; | ||
private final Unit unit; | ||
private final PostalCode postalCode; | ||
public final String value; | ||
|
||
private boolean isPrivate; | ||
|
||
/** | ||
|
@@ -27,30 +35,87 @@ public Address(String address, boolean isPrivate) throws IllegalValueException { | |
throw new IllegalValueException(MESSAGE_ADDRESS_CONSTRAINTS); | ||
} | ||
this.value = trimmedAddress; | ||
this.block = assignBlock(trimmedAddress); | ||
this.street = assignStreet(trimmedAddress); | ||
this.unit = assignUnit(trimmedAddress); | ||
this.postalCode = assignPostalCode(trimmedAddress); | ||
|
||
} | ||
|
||
/* | ||
* Returns the Person's block of his address. | ||
* | ||
* @param trimmedAddress the String to be operated on | ||
*/ | ||
public Block assignBlock(String trimmedAddress) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a different name for this method, as the block is not in fact assigned, but rather extracted out from the trimmed address. |
||
return new Block(trimmedAddress.split(",")[0].trim()); | ||
} | ||
|
||
/* | ||
* Returns the Person's street of his address. | ||
* | ||
* @param trimmedAddress the String to be operated on | ||
*/ | ||
public Street assignStreet(String trimmedAddress) { | ||
return new Street(trimmedAddress.split(",")[1].trim()); | ||
} | ||
|
||
/* | ||
* Returns the Person's unit of his address. | ||
* | ||
* @param trimmedAddress the String to be operated on | ||
*/ | ||
public Unit assignUnit(String trimmedAddress) { | ||
return new Unit(trimmedAddress.split(",")[2].trim()); | ||
} | ||
|
||
/* | ||
* Returns the Person's block of his address. | ||
* | ||
* @param trimmedAddress the String to be operated on | ||
*/ | ||
public PostalCode assignPostalCode(String trimmedAddress) { | ||
return new PostalCode(trimmedAddress.split(",")[3].trim()); | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid person address. | ||
*/ | ||
public static boolean isValidAddress(String test) { | ||
return test.matches(ADDRESS_VALIDATION_REGEX); | ||
return (test.matches(ADDRESS_VALIDATION_REGEX)) && (test.split(",").length == 4); | ||
} | ||
|
||
public Block getBlock() { | ||
return this.block; | ||
} | ||
|
||
public Street getStreet() { | ||
return this.street; | ||
} | ||
|
||
public Unit getUnit() { | ||
return this.unit; | ||
} | ||
|
||
public PostalCode getPostalCode() { | ||
return this.postalCode; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
return block + ", " + street + ", " + unit + ", " + postalCode; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof Address // instanceof handles nulls | ||
&& this.value.equals(((Address) other).value)); // state check | ||
&& this.value.equals(((Address) other).value)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! However, the indentation for wrapped lines should be 8 spaces. |
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
return Objects.hash(block, street, unit, postalCode); | ||
} | ||
|
||
public boolean isPrivate() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package seedu.addressbook.data.person; | ||
|
||
/** | ||
* The block of a person address. | ||
*/ | ||
public class Block { | ||
private String blockNumber; | ||
|
||
public Block(String blockNumber) { | ||
this.blockNumber = blockNumber; | ||
} | ||
|
||
public String getBlockNumber() { | ||
return this.blockNumber; | ||
} | ||
|
||
public void setBlockNumber(String blockNumber) { | ||
this.blockNumber = blockNumber; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.blockNumber; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package seedu.addressbook.data.person; | ||
|
||
/** | ||
* The postal code of a person address. | ||
*/ | ||
public class PostalCode { | ||
private String postalCodeNumber; | ||
|
||
public PostalCode(String postalCodeNumber) { | ||
this.postalCodeNumber = postalCodeNumber; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A possible improvement is to utilize regex so that the postal code must be of the form "Sxxxxxx", where x must be a digit from 0 to 9. |
||
} | ||
|
||
public String getPostalCodeNumber() { | ||
return this.postalCodeNumber; | ||
} | ||
|
||
public void setPostalCodeNumber(String postalCodeNumber) { | ||
this.postalCodeNumber = postalCodeNumber; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.postalCodeNumber; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package seedu.addressbook.data.person; | ||
|
||
/** | ||
* The street of a person address. | ||
*/ | ||
public class Street { | ||
private String streetNumber; | ||
|
||
public Street(String streetNumber) { | ||
this.streetNumber = streetNumber; | ||
} | ||
|
||
public String getStreetNumber() { | ||
return this.streetNumber; | ||
} | ||
|
||
public void setStreetNumber(String streetNumber) { | ||
this.streetNumber = streetNumber; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.streetNumber; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package seedu.addressbook.data.person; | ||
|
||
/** | ||
* The unit of a person address. | ||
*/ | ||
public class Unit { | ||
private String unitNumber; | ||
|
||
public Unit(String unitNumber) { | ||
this.unitNumber = unitNumber; | ||
} | ||
|
||
public String getUnitNumber() { | ||
return this.unitNumber; | ||
} | ||
|
||
public void setUnitNumber(String unitNumber) { | ||
this.unitNumber = unitNumber; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.unitNumber; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
John Doe p/98765432 e/[email protected] a/John street, block 123, #01-01 | ||
Betsy Crowe pp/1234567 e/[email protected] pa/Newgate Prison t/friend t/criminal | ||
John Doe p/98765432 e/[email protected] a/123, John street, #01-01, S111111 | ||
Betsy Crowe pp/1234567 e/[email protected] pa/Newgate Prison, Newgate street, #21-03, S222222 t/friend t/criminal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use blank lines sparingly. It's good to have blank lines to separate logical code blocks, but too many blank lines will increase the height of the code, which increases the amount of scrolling.