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

[T4A5][T15-A1] Neo Wei Jie, Esmond #1704

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
71ccd26
[T4A5] Add Tagging association class.
zeticous Feb 8, 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
38 changes: 37 additions & 1 deletion src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import seedu.addressbook.data.tag.UniqueTagList;
import seedu.addressbook.data.tag.UniqueTagList.*;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.Tagging;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -22,13 +24,14 @@ public class AddressBook {

private final UniquePersonList allPersons;
private final UniqueTagList allTags; // can contain tags not attached to any person

private final ArrayList<Tagging> allTaggings;
/**
* Creates an empty address book.
*/
public AddressBook() {
allPersons = new UniquePersonList();
allTags = new UniqueTagList();
allTaggings = new ArrayList<Tagging>();
}

/**
Expand All @@ -44,6 +47,8 @@ public AddressBook(UniquePersonList persons, UniqueTagList tags) {
for (Person p : allPersons) {
syncTagsWithMasterList(p);
}

allTaggings = new ArrayList<Tagging>();
}

/**
Expand Down Expand Up @@ -89,6 +94,29 @@ public void addPerson(Person toAdd) throws DuplicatePersonException {
public void addTag(Tag toAdd) throws DuplicateTagException {
allTags.add(toAdd);
}

/**
* Records any tags that are added to a person into allTaggings.
*/
public void addTaggings(Tag tag, Person person){
allTaggings.add(new Tagging(tag,person,Tagging.STATE_ADD_TAG));
}

/**
* Records any tags that are removed from a person into allTaggings.
*/
public void removeTaggings(Tag tag, Person person){
allTaggings.add(new Tagging(tag,person,Tagging.STATE_REMOVE_TAG));
}

/**
* Print all records of tagging.
*/
public void printTaggings(){
for(Tagging tagging: allTaggings){
System.out.println(tagging.toString());
}
}

/**
* Checks if an equivalent person exists in the address book.
Expand Down Expand Up @@ -143,4 +171,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));
}
}
47 changes: 38 additions & 9 deletions src/seedu/addressbook/data/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,62 @@ 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 ADDRESS_VALIDATION_REGEX = ".+";

public final String value;

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 boolean isPrivate;

/**

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

public String value;
/*
* Validates given address.
*
* @throws IllegalValueException if given address string is invalid.
*/
public Address(String address, boolean isPrivate) throws IllegalValueException {
/*
* Address Format: a/ BLOCK, STREET, FLOOR-UNIT, POSTAL_CODE
*/

String[] addressField = splitAddress(address);
this.isPrivate = isPrivate;
if (!isValidAddress(address)) {
throw new IllegalValueException(MESSAGE_ADDRESS_CONSTRAINTS);
}
this.value = address;

fillAddressField(addressField);
value = toString();
}

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 @@ -55,4 +84,4 @@ public int 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);
}
}
8 changes: 4 additions & 4 deletions src/seedu/addressbook/data/person/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public class Email {
*/
public Email(String email, boolean isPrivate) throws IllegalValueException {
this.isPrivate = isPrivate;
email = email.trim();
if (!isValidEmail(email)) {
String trimmedEmail = email.trim();
if (!isValidEmail(trimmedEmail)) {
throw new IllegalValueException(MESSAGE_EMAIL_CONSTRAINTS);
}
this.value = email;
this.value = trimmedEmail;
}

/**
Expand Down Expand Up @@ -58,4 +58,4 @@ public int 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
6 changes: 3 additions & 3 deletions src/seedu/addressbook/data/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class Phone {
*/
public Phone(String phone, boolean isPrivate) throws IllegalValueException {
this.isPrivate = isPrivate;
phone = phone.trim();
if (!isValidPhone(phone)) {
String trimmedPhone = phone.trim();
if (!isValidPhone(trimmedPhone)) {
throw new IllegalValueException(MESSAGE_PHONE_CONSTRAINTS);
}
this.value = phone;
this.value = trimmedPhone;
}

/**
Expand Down
17 changes: 17 additions & 0 deletions src/seedu/addressbook/data/person/PostalCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package seedu.addressbook.data.person;

public class PostalCode {
private int postalCode;

public PostalCode(String postalCode){
setPostalCode(postalCode);
}

public int getPostalCode(){
return postalCode;
}

public void setPostalCode(String postalCode){
this.postalCode = Integer.parseInt(postalCode);
}
}
3 changes: 2 additions & 1 deletion src/seedu/addressbook/data/person/ReadOnlyPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public interface ReadOnlyPerson {
UniqueTagList getTags();

/**
* Returns true if the values inside this object is same as those of the other (Note: interfaces cannot override .equals)
* Returns true if the values inside this object is same as those of the other
* (Note: interfaces cannot override .equals)
*/
default boolean isSameStateAs(ReadOnlyPerson other) {
return other == this // short circuit if same object
Expand Down
Loading