Skip to content

Commit

Permalink
Merge branch 'v1'
Browse files Browse the repository at this point in the history
  • Loading branch information
SoilChang committed Mar 12, 2018
2 parents 7a8ed69 + 4ee17b3 commit ebec8b9
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 59 deletions.
10 changes: 4 additions & 6 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.*;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.person.Person;
Expand All @@ -24,14 +20,16 @@ public class AddCommand extends UndoableCommand {
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_INCOME + "INCOME "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";
+ PREFIX_TAG + "owesMoney "
+ PREFIX_INCOME + "29000 ";

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
6 changes: 5 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_INCOME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -21,6 +22,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Income;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
Expand All @@ -43,6 +45,7 @@ public class EditCommand extends UndoableCommand {
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_INCOME + "INCOME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
Expand Down Expand Up @@ -107,8 +110,9 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Income updatedIncome = new Income(20000.0);

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedIncome);
}

@Override
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_INCOME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -15,6 +16,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Income;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
Expand All @@ -28,13 +30,14 @@ public class AddCommandParser implements Parser<AddCommand> {
/**
* Parses the given {@code String} of arguments in the context of the AddCommand
* and returns an AddCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_INCOME, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_INCOME)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}
Expand All @@ -44,9 +47,10 @@ public AddCommand parse(String args) throws ParseException {
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE)).get();
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL)).get();
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS)).get();
Income income = ParserUtil.parseIncome(argMultimap.getValue(PREFIX_INCOME)).get();
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, address, tagList);
Person person = new Person(name, phone, email, address, tagList, income);

return new AddCommand(person);
} catch (IllegalValueException ive) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_INCOME = new Prefix("i/");

}
25 changes: 25 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Income;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.Tag;
Expand Down Expand Up @@ -139,6 +140,30 @@ public static Optional<Email> parseEmail(Optional<String> email) throws IllegalV
return email.isPresent() ? Optional.of(parseEmail(email.get())) : Optional.empty();
}

/**
* Parses a {@code String value} into an {@code value}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws IllegalValueException if the given {@code value} is invalid.
*/
public static Income parseIncome(String income) throws IllegalValueException {
requireNonNull(income);
Double trimmedIncome = Double.parseDouble(income.trim());
if (!Income.isValidIncome(trimmedIncome)) {
throw new IllegalValueException(Income.MESSAGE_INCOME_CONSTRAINTS);
}
return new Income(trimmedIncome);
}

/**
* Parses a {@code Optional<String> value} into an {@code Optional<value>} if {@code value} is present.
* See header comment of this class regarding the use of {@code Optional} parameters.
*/
public static Optional<Income> parseIncome(Optional<String> income) throws IllegalValueException {
requireNonNull(income);
return income.isPresent() ? Optional.of(parseIncome(income.get())) : Optional.empty();
}

/**
* Parses a {@code String tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public class AddressBook implements ReadOnlyAddressBook {
*
* Note that non-static init blocks are not recommended to use. There are other ways to avoid duplication
* among constructors.
*/
{
*/ {
persons = new UniquePersonList();
tags = new UniqueTagList();
}

public AddressBook() {}
public AddressBook() {
}

/**
* Creates an AddressBook using the Persons and Tags in the {@code toBeCopied}
Expand Down Expand Up @@ -98,9 +98,8 @@ public void addPerson(Person p) throws DuplicatePersonException {
* {@code AddressBook}'s tag list will be updated with the tags of {@code editedPerson}.
*
* @throws DuplicatePersonException if updating the person's details causes the person to be equivalent to
* another existing person in the list.
* @throws PersonNotFoundException if {@code target} could not be found in the list.
*
* another existing person in the list.
* @throws PersonNotFoundException if {@code target} could not be found in the list.
* @see #syncWithMasterTagList(Person)
*/
public void updatePerson(Person target, Person editedPerson)
Expand All @@ -115,9 +114,10 @@ public void updatePerson(Person target, Person editedPerson)
}

/**
* Updates the master tag list to include tags in {@code person} that are not in the list.
* @return a copy of this {@code person} such that every tag in this person points to a Tag object in the master
* list.
* Updates the master tag list to include tags in {@code person} that are not in the list.
*
* @return a copy of this {@code person} such that every tag in this person points to a Tag object in the master
* list.
*/
private Person syncWithMasterTagList(Person person) {
final UniqueTagList personTags = new UniqueTagList(person.getTags());
Expand All @@ -132,11 +132,12 @@ private Person syncWithMasterTagList(Person person) {
final Set<Tag> correctTagReferences = new HashSet<>();
personTags.forEach(tag -> correctTagReferences.add(masterTagObjects.get(tag)));
return new Person(
person.getName(), person.getPhone(), person.getEmail(), person.getAddress(), correctTagReferences);
person.getName(), person.getPhone(), person.getEmail(), person.getAddress(), correctTagReferences, person.getIncome());
}

/**
* Removes {@code key} from this {@code AddressBook}.
*
* @throws PersonNotFoundException if the {@code key} is not in this {@code AddressBook}.
*/
public boolean removePerson(Person key) throws PersonNotFoundException {
Expand All @@ -157,7 +158,7 @@ public void addTag(Tag t) throws UniqueTagList.DuplicateTagException {

@Override
public String toString() {
return persons.asObservableList().size() + " persons, " + tags.asObservableList().size() + " tags";
return persons.asObservableList().size() + " persons, " + tags.asObservableList().size() + " tags";
// TODO: refine later
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void updatePerson(Person target, Person editedPerson)
requireAllNonNull(target, editedPerson);

addressBook.updatePerson(target, editedPerson);
indicateAddressBookChanged();
this.indicateAddressBookChanged();
}

//=========== Filtered Person List Accessors =============================================================
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/seedu/address/model/person/Income.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,41 @@


/**
* Represents a Person's income in the address book
* Represents a Person's value in the address book
* Guarantees: immutable; is valid as declare in {@link #isValidIncome(float)}}
*/
public class Income {
public static final String MESSAGE_INCOME_CONSTRAITS =
"Person income must be positive numerical numbers, floating point value";
public static final String MESSAGE_INCOME_CONSTRAINTS =
"Person value must be positive numerical numbers, floating point value";

public final float income;
public final Double value;

/**
* @param income a valid income
* @param value a valid value
*/
public Income(float income) {
requireNonNull(income);
checkArgument(this.isValidIncome(income), this.MESSAGE_INCOME_CONSTRAITS);
this.income = income;
public Income(Double value) {
requireNonNull(value);
checkArgument(this.isValidIncome(value), this.MESSAGE_INCOME_CONSTRAINTS);
this.value = value;
}


private static boolean isValidIncome(float income) {
public static boolean isValidIncome(Double income) {
return (income >= 0);
}

@Override
public String toString() {
NumberFormat format = NumberFormat.getCurrencyInstance(Locale.US);
return format.format(this.income);
return format.format(this.value);
}


@Override
public boolean equals(Object other) {
return other == this
|| (other instanceof Income
&& this.income == ((Income) other).income);
&& this.value == ((Income) other).value);
}

}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Person {
/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags) {
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags, Income income) {
requireAllNonNull(name, phone, email, address, tags);
this.name = name;
this.age = new Age(12);
Expand All @@ -36,7 +36,7 @@ public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tag
this.address = address;
// protect internal tags from changes in the arg list
this.tags = new UniqueTagList(tags);
this.income = new Income(29000);
this.income = income;
}

public Name getName() {
Expand Down
39 changes: 20 additions & 19 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Income;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
Expand All @@ -18,25 +19,25 @@
*/
public class SampleDataUtil {
public static Person[] getSamplePersons() {
return new Person[] {
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("[email protected]"),
new Address("Blk 30 Geylang Street 29, #06-40"),
getTagSet("friends")),
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("[email protected]"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
getTagSet("colleagues", "friends")),
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("[email protected]"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
getTagSet("neighbours")),
new Person(new Name("David Li"), new Phone("91031282"), new Email("[email protected]"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
getTagSet("family")),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("[email protected]"),
new Address("Blk 47 Tampines Street 20, #17-35"),
getTagSet("classmates")),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("[email protected]"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
getTagSet("colleagues"))
return new Person[]{
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("[email protected]"),
new Address("Blk 30 Geylang Street 29, #06-40"),
getTagSet("friends"), new Income(2000.00)),
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("[email protected]"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
getTagSet("colleagues", "friends"), new Income(2200.00)),
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("[email protected]"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
getTagSet("neighbours"), new Income(34550.00)),
new Person(new Name("David Li"), new Phone("91031282"), new Email("[email protected]"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
getTagSet("family"), new Income(202323.00)),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("[email protected]"),
new Address("Blk 47 Tampines Street 20, #17-35"),
getTagSet("classmates"), new Income(5000.00)),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("[email protected]"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
getTagSet("colleagues"), new Income(7000.00))
};
}

Expand Down
Loading

0 comments on commit ebec8b9

Please sign in to comment.