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

[T3A2][F11-A1]Anshul Aggarwal #1699

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 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
b046a9d
Lab part 3
aanshul20 Feb 2, 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
}


}
}
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/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));
}
}
21 changes: 18 additions & 3 deletions src/seedu/addressbook/data/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,31 @@ public class Address {

public final String value;
private boolean isPrivate;

Block block;
Street street;
Unit unit;
PostalCode postalCode;


/**
* Validates given address.
*
* @throws IllegalValueException if given address string is invalid.
*/
public Address(String address, boolean isPrivate) throws IllegalValueException {
String trimmedAddress = address.trim();
this.isPrivate = isPrivate;
if (!isValidAddress(address)) {
if (!isValidAddress(trimmedAddress)) {
throw new IllegalValueException(MESSAGE_ADDRESS_CONSTRAINTS);
}
this.value = address;
this.value = trimmedAddress;
String[] temp = value.split(",");
block = new Block(temp[0].trim());
street = new Street(temp[1].trim());
unit = new Unit(temp[2].trim());
postalCode = new PostalCode(temp[3].trim());

}

/**
Expand Down Expand Up @@ -55,4 +68,6 @@ public int hashCode() {
public boolean isPrivate() {
return isPrivate;
}
}
}


7 changes: 7 additions & 0 deletions src/seedu/addressbook/data/person/Block.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package seedu.addressbook.data.person;

public class Block{
public final String value;
public Block(String block)
{value = block;}
}
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
7 changes: 7 additions & 0 deletions src/seedu/addressbook/data/person/PostalCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package seedu.addressbook.data.person;

public class PostalCode{
public final String value;
public PostalCode( String address )
{value = address;}
}
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
7 changes: 7 additions & 0 deletions src/seedu/addressbook/data/person/Street.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package seedu.addressbook.data.person;

public class Street{
public final String value;
public Street( String street )
{value = street;}
}
15 changes: 14 additions & 1 deletion src/seedu/addressbook/data/person/UniquePersonList.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package seedu.addressbook.data.person;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import seedu.addressbook.common.Utils;
import seedu.addressbook.data.exception.DuplicateDataException;

import java.util.*;


/**
* A list of persons. Does not allow null elements or duplicates.
Expand Down Expand Up @@ -118,4 +125,10 @@ public Iterator<Person> iterator() {
return internalList.iterator();
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof UniquePersonList // instanceof handles nulls
&& this.internalList.equals(((UniquePersonList) other).internalList));
}
}
7 changes: 7 additions & 0 deletions src/seedu/addressbook/data/person/Unit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package seedu.addressbook.data.person;

public class Unit{
public final String value;
public Unit(String unit)
{value = unit;}
}
6 changes: 3 additions & 3 deletions src/seedu/addressbook/data/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class Tag {
* @throws IllegalValueException if the given tag name string is invalid.
*/
public Tag(String name) throws IllegalValueException {
name = name.trim();
if (!isValidTagName(name)) {
String trimmedName = name.trim();
if (!isValidTagName(trimmedName)) {
throw new IllegalValueException(MESSAGE_TAG_CONSTRAINTS);
}
this.tagName = name;
this.tagName = trimmedName;
}

/**
Expand Down
21 changes: 18 additions & 3 deletions src/seedu/addressbook/data/tag/UniqueTagList.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package seedu.addressbook.data.tag;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import seedu.addressbook.common.Utils;
import seedu.addressbook.data.exception.DuplicateDataException;

import java.util.*;

/**
* A list of tags. Does not allow nulls or duplicates.
Expand Down Expand Up @@ -126,8 +134,8 @@ public void mergeFrom(UniqueTagList tags) {
* @throws TagNotFoundException if no such Tag could be found in the list.
*/
public void remove(Tag toRemove) throws TagNotFoundException {
final boolean TagFoundAndDeleted = internalList.remove(toRemove);
if (!TagFoundAndDeleted) {
final boolean tagFoundAndDeleted = internalList.remove(toRemove);
if (!tagFoundAndDeleted) {
throw new TagNotFoundException();
}
}
Expand All @@ -152,4 +160,11 @@ public Iterator<Tag> iterator() {
return internalList.iterator();
}

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

}
Loading