Skip to content
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

[T4A3][T15-A1] Neo Wei Jie, Esmond #1702

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
db3978d
Update regex for better Name matching
okkhoy Aug 30, 2016
730ea58
fix tests to clean up all entries before closing
okkhoy Aug 30, 2016
c3ac0d5
Merge branch 'master' into fix-Name-regex
okkhoy Oct 5, 2016
cec9204
add more tests to check for dash, dot, qote and unicode characters in…
okkhoy Oct 5, 2016
adef5c6
fixed regex to "^[\\p{L}0-9 .'-]+$", the prev one did not have numbers
okkhoy Oct 5, 2016
bf7f6bc
add more test case to test name with numbers (the latest fix)
okkhoy Oct 5, 2016
8928fef
convert input and expected to UTF-8 encoding.
okkhoy Oct 6, 2016
02b59fc
encoding to UTF-8 w/o BOM for input and actual
okkhoy Oct 20, 2016
c61e65b
[41] Name regex doesn't match hyphen, dots and quote
ndt93 Oct 21, 2016
2283852
Add codacy badge
damithc Nov 27, 2016
43c506d
[#101] Remove unused imports (#114)
jia1 Dec 7, 2016
7518552
[#102] Fix coding problem: reassigning parameters (#115)
jia1 Dec 8, 2016
f196968
[#109] Add unit tests for DeleteCommand class (#119)
yamgent Dec 10, 2016
88133a6
[#108] Add unit tests for AddCommand class (#118)
Neurrone Dec 11, 2016
7d1de69
[#124] Fix code style violation (#125)
yamgent Dec 13, 2016
1a15e66
[#107] Add unit tests for Utils class (#127)
zzzzwen Dec 22, 2016
24335db
[#104] Add unit tests for StorageFile class (#128)
zzzzwen Dec 28, 2016
753fcc1
[#133] Test Failing due to incorrect message (#135)
zzzzwen Jan 2, 2017
a909e09
[#110] Add unit tests for FindCommand class (#120)
Jan 3, 2017
2fdb124
[#130] Change file extension requirement from .txt to .xml (#132)
zzzzwen Jan 3, 2017
70f60ba
[#117] Names with unicode characters are treated as invalid (#138)
Neurrone Jan 8, 2017
6dc39b2
T3A2:
zeticous Jan 27, 2017
91d0dac
T3A3: Create Class
zeticous Jan 27, 2017
7274ea8
Fixes for StorageOperationException and T3A2
zeticous Jan 30, 2017
0fdfc4f
[T3A5] Added PrefixFormatter
zeticous Jan 30, 2017
24fbb45
[T4A3] Add parent class Contact
zeticous Feb 3, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Default storage file for addressbook : don't need to cleanup when running from IDE

addressbook.txt
addressbook.xml

# Compiled classfiles
bin/
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/ad7aa7caa7ba4d40aef9440b16ea68d6)](https://www.codacy.com/app/se-edu/addressbook-level2?utm_source=github.com&utm_medium=referral&utm_content=se-edu/addressbook-level2&utm_campaign=Badge_Grade)

# AddressBook (Level 2)
* This is a CLI (Command Line Interface) Address Book application **written in OOP fashion**.
* It is a Java sample application intended for students learning Software Engineering while using Java as
Expand All @@ -19,4 +21,4 @@

* **Bug reports, Suggestions** : Post in our [issue tracker](https://github.com/se-edu/addressbook-level2/issues)
if you noticed bugs or have suggestions on how to improve.
* **Contributing** : We welcome pull requests. Follow the process described [here](https://github.com/oss-generic/process)
* **Contributing** : We welcome pull requests. Follow the process described [here](https://github.com/oss-generic/process)
6 changes: 3 additions & 3 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ Address book data are saved in the hard disk automatically after any command tha
There is no need to save manually.

#### Changing the save location
Address book data are saved in a file called `addressbook.txt` in the project root folder.
Address book data are saved in a file called `addressbook.xml` in the project root folder.
You can change the location by specifying the file path as a program argument.

Example:
* `java seedu.addressbook.Main mydata.txt`
* `java seedu.addressbook.Main mydata.xml`

> The file name must end in `.txt` for it to be acceptable to the program.
> The file name must end in `.xml` for it to be acceptable to the program.
>
> When running the program inside Eclipse, you can set command line parameters
before running the program.
4 changes: 2 additions & 2 deletions src/seedu/addressbook/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void recordResult(CommandResult result) {

/**
* Executes the command and returns the result.
*
*
* @param command user command
* @return result of the command
*/
Expand All @@ -126,4 +126,4 @@ private StorageFile initializeStorage(String[] launchArgs) throws InvalidStorage
}


}
}
4 changes: 2 additions & 2 deletions src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class AddCommand extends Command {

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
+ "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"
+ "Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/BLOCK, STREET, UNIT, POSTAL CODE [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, 622311 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";
Expand Down
3 changes: 0 additions & 3 deletions src/seedu/addressbook/commands/ClearCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package seedu.addressbook.commands;

import seedu.addressbook.common.Utils;


/**
* Clears the address book.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected Command() {
* @param personsDisplayed used to generate summary
* @return summary message for persons displayed
*/
protected String getMessageForPersonListShownSummary(List<? extends ReadOnlyPerson> personsDisplayed) {
public static String getMessageForPersonListShownSummary(List<? extends ReadOnlyPerson> personsDisplayed) {
return String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, personsDisplayed.size());
}

Expand Down
8 changes: 6 additions & 2 deletions src/seedu/addressbook/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
public class CommandResult {

/** The feedback message to be shown to the user. Contains a description of the execution result */
public final String feedbackToUser;

private final String feedbackToUser;

public String getFeedbackToUser(){
return feedbackToUser;
}

/** The list of persons that was produced by the command */
private final List<? extends ReadOnlyPerson> relevantPersons;

Expand Down
8 changes: 6 additions & 2 deletions src/seedu/addressbook/commands/FindCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package seedu.addressbook.commands;

import seedu.addressbook.data.person.ReadOnlyPerson;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import java.util.*;
import seedu.addressbook.data.person.ReadOnlyPerson;

/**
* Finds and lists all persons in address book whose name contains any of the argument keywords.
Expand Down
4 changes: 2 additions & 2 deletions src/seedu/addressbook/commands/IncorrectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
/**
* Represents an incorrect command. Upon execution, produces some feedback to the user.
*/
public class IncorrectCommand extends Command{
public class IncorrectCommand extends Command {

public final String feedbackToUser;

public IncorrectCommand(String feedbackToUser){
public IncorrectCommand(String feedbackToUser) {
this.feedbackToUser = feedbackToUser;
}

Expand Down
1 change: 0 additions & 1 deletion src/seedu/addressbook/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
Expand Down
8 changes: 8 additions & 0 deletions src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,12 @@ public UniquePersonList getAllPersons() {
public UniqueTagList getAllTags() {
return new UniqueTagList(allTags);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddressBook // instanceof handles nulls
&& this.allPersons.equals(((AddressBook) other).allPersons)
&& this.allTags.equals(((AddressBook) other).allTags));
}
}
58 changes: 36 additions & 22 deletions src/seedu/addressbook/data/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,61 @@
* Represents a Person's address in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidAddress(String)}
*/
public class Address {
public class Address extends Contact {

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 ADDRESS_VALIDATION_REGEX = ".+";

public final String value;
private boolean isPrivate;

/**

public static final int ADDRESS_INDEX_BLOCK = 0;
public static final int ADDRESS_INDEX_STREET = 1;
public static final int ADDRESS_INDEX_UNIT = 2;
public static final int ADDRESS_INDEX_POSTAL_CODE = 3;
public static final int ADDRESS_FIELD_COUNT = 4;

private Block addressBlock;
private Street addressStreet;
private Unit addressUnit;
private PostalCode addressPostalCode;

/*
* Validates given address.
*
* @throws IllegalValueException if given address string is invalid.
*/
public Address(String address, boolean isPrivate) throws IllegalValueException {
this.isPrivate = isPrivate;
if (!isValidAddress(address)) {
/*
* Address Format: a/ BLOCK, STREET, FLOOR-UNIT, POSTAL_CODE
*/
super(address,isPrivate);
if (!isValidAddress(value)) {
throw new IllegalValueException(MESSAGE_ADDRESS_CONSTRAINTS);
}
this.value = address;
String[] addressField = splitAddress(value);
fillAddressField(addressField);
}

public String[] splitAddress(String address){
return address.split(",");
}

public void fillAddressField(String[] addressField){
addressBlock = new Block(addressField[ADDRESS_INDEX_BLOCK].trim());
addressStreet = new Street(addressField[ADDRESS_INDEX_STREET].trim());
addressUnit = new Unit(addressField[ADDRESS_INDEX_UNIT].trim());
addressPostalCode = new PostalCode(addressField[ADDRESS_INDEX_POSTAL_CODE].trim());
}

/**
* Returns true if a given string is a valid person email.
*/
public static boolean isValidAddress(String test) {
return test.matches(ADDRESS_VALIDATION_REGEX);
return test.matches("(.*),(.*),(.*)-(.*),(.*)");
}

@Override
public String toString() {
return value;
return addressBlock.getBlockNumber()+", "+addressStreet.getStreetName()+", "
+addressUnit.getUnitNumber()+", "+addressPostalCode.getPostalCode();
}

@Override
Expand All @@ -46,13 +69,4 @@ public boolean equals(Object other) {
|| (other instanceof Address // instanceof handles nulls
&& this.value.equals(((Address) other).value)); // state check
}

@Override
public int hashCode() {
return value.hashCode();
}

public boolean isPrivate() {
return isPrivate;
}
}
}
17 changes: 17 additions & 0 deletions src/seedu/addressbook/data/person/Block.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package seedu.addressbook.data.person;

public class Block {
private int blockNumber;

public Block(String blockNumber){
setBlockNumber(blockNumber);
}

public int getBlockNumber(){
return blockNumber;
}

public void setBlockNumber(String blockNumber){
this.blockNumber = Integer.parseInt(blockNumber);
}
}
34 changes: 34 additions & 0 deletions src/seedu/addressbook/data/person/Contact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package seedu.addressbook.data.person;

import seedu.addressbook.data.exception.IllegalValueException;

/**
* The parent class for Email, Address and phone.
*/
public class Contact {
public final String value;
protected boolean isPrivate;

public Contact(String contact, boolean isPrivate) throws IllegalValueException {
this.isPrivate = isPrivate;
String trimmedContact = contact.trim();
this.value = trimmedContact;
}

@Override
public String toString() {
return value;
}


@Override
public int hashCode() {
return value.hashCode();
}


public boolean isPrivate() {
return isPrivate;
}

}
28 changes: 4 additions & 24 deletions src/seedu/addressbook/data/person/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@
* Represents a Person's email in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidEmail(String)}
*/
public class Email {
public class Email extends Contact {

public static final String EXAMPLE = "[email protected]";
public static final String MESSAGE_EMAIL_CONSTRAINTS =
"Person emails should be 2 alphanumeric/period strings separated by '@'";
public static final String EMAIL_VALIDATION_REGEX = "[\\w\\.]+@[\\w\\.]+";

public final String value;
private boolean isPrivate;

/**
* Validates given email.
*
* @throws IllegalValueException if given email address string is invalid.
*/
public Email(String email, boolean isPrivate) throws IllegalValueException {
this.isPrivate = isPrivate;
email = email.trim();
if (!isValidEmail(email)) {
super(email,isPrivate);
if (!isValidEmail(value)) {
throw new IllegalValueException(MESSAGE_EMAIL_CONSTRAINTS);
}
this.value = email;
}

/**
Expand All @@ -37,25 +32,10 @@ public static boolean isValidEmail(String test) {
return test.matches(EMAIL_VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Email // instanceof handles nulls
&& this.value.equals(((Email) other).value)); // state check
}

@Override
public int hashCode() {
return value.hashCode();
}


public boolean isPrivate() {
return isPrivate;
}
}
}
7 changes: 3 additions & 4 deletions src/seedu/addressbook/data/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class Name {
public static final String EXAMPLE = "John Doe";
public static final String MESSAGE_NAME_CONSTRAINTS = "Person names should be spaces or alphabetic characters";
public static final String NAME_VALIDATION_REGEX = "[\\p{Alpha} ]+";

public final String fullName;

/**
Expand All @@ -23,11 +22,11 @@ public class Name {
* @throws IllegalValueException if given name string is invalid.
*/
public Name(String name) throws IllegalValueException {
name = name.trim();
if (!isValidName(name)) {
String trimmedName = name.trim();
if (!isValidName(trimmedName)) {
throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS);
}
this.fullName = name;
this.fullName = trimmedName;
}

/**
Expand Down
Loading