Skip to content

Commit

Permalink
Merge pull request #153 from OscarWang114/collate-portfolio
Browse files Browse the repository at this point in the history
Collate code and update portfolio
  • Loading branch information
Juxarius authored Nov 9, 2017
2 parents 93dbc73 + f55a362 commit fa9ba22
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 82 deletions.
116 changes: 77 additions & 39 deletions collated/main/OscarWang114.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,26 @@ public interface ThrowingConsumer<T> extends Consumer<T> {
* Creates an insurance in Lisa
*/
public class AddLifeInsuranceCommand extends UndoableCommand {
public static final String[] COMMAND_WORDS = {"addli", "ali", "+"};
public static final String[] COMMAND_WORDS = {"addli", "ali", "+li"};
public static final String COMMAND_WORD = "addli";

public static final String MESSAGE_USAGE = concatenateCommandWords(COMMAND_WORDS)
+ ": Adds an insurance to Lisa. "
+ "Parameters: "
+ PREFIX_NAME + "INSURANCE_NAME "
+ PREFIX_OWNER + "OWNER "
+ PREFIX_INSURED + "INSURED "
+ PREFIX_BENEFICIARY + "BENEFICIARY "
+ PREFIX_CONTRACT + "CONTRACT"
+ PREFIX_CONTRACT + "CONTRACT "
+ PREFIX_PREMIUM + "PREMIUM "
+ PREFIX_SIGNING_DATE + "SIGNING_DATE "
+ PREFIX_EXPIRY_DATE + "EXPIRY_DATE\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_OWNER + "Alex Yeoh"
+ PREFIX_NAME + "Life Insurance "
+ PREFIX_OWNER + "Alex Yeoh "
+ PREFIX_INSURED + "John Doe "
+ PREFIX_BENEFICIARY + "Mary Jane "
+ PREFIX_CONTRACT + "normal_plan.pdf"
+ PREFIX_CONTRACT + "normal_plan.pdf "
+ PREFIX_PREMIUM + "500 "
+ PREFIX_SIGNING_DATE + "01 11 2017 "
+ PREFIX_EXPIRY_DATE + "01 11 2018 ";
Expand Down Expand Up @@ -155,25 +157,23 @@ public class AddLifeInsuranceCommand extends UndoableCommand {
//TODO: need to compare every nonstatic class member.
}

/**
* Check if all the Person parameters required to create an insurance are inside the list
*/
public void isAnyPersonInList(List<ReadOnlyPerson> list, LifeInsurance lifeInsurance) {
String ownerName = lifeInsurance.getOwner().getName();
String insuredName = lifeInsurance.getInsured().getName();
String beneficiaryName = lifeInsurance.getBeneficiary().getName();
for (ReadOnlyPerson person: list) {
String lowerCaseName = person.getName().toString().toLowerCase();
if (lowerCaseName.equals(ownerName)) {
lifeInsurance.getOwner().setPerson(person);
}
if (lowerCaseName.equals(insuredName)) {
lifeInsurance.getInsured().setPerson(person);
}
if (lowerCaseName.equals(beneficiaryName)) {
lifeInsurance.getBeneficiary().setPerson(person);
}
}
```
###### /java/seedu/address/logic/Logic.java
``` java
/** Returns an unmodifiable view of the list of insurances */
ObservableList<ReadOnlyInsurance> getFilteredInsuranceList();
```
###### /java/seedu/address/logic/LogicManager.java
``` java
@Override
public ObservableList<ReadOnlyInsurance> getFilteredInsuranceList() {
return model.getFilteredInsuranceList();
}
//

@Override
public ListElementPointer getHistorySnapshot() {
return new ListElementPointer(history.getHistory());
}
}
```
Expand Down Expand Up @@ -206,12 +206,17 @@ public class AddLifeInsuranceCommand extends UndoableCommand {
.ifPresent(addPersonOptionalFieldDescriptor::setEmail);
ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS))
.ifPresent(addPersonOptionalFieldDescriptor::setAddress);
```
###### \java\seedu\address\logic\parser\AddCommandParser.java
``` java
ParserUtil.parseDateOfBirth(argMultimap.getValue(PREFIX_DOB))
.ifPresent(addPersonOptionalFieldDescriptor::setDateOfBirth);
ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER))
.ifPresent(addPersonOptionalFieldDescriptor::setGender);

Phone phone = addPersonOptionalFieldDescriptor.getPhone();
Email email = addPersonOptionalFieldDescriptor.getEmail();
Address address = addPersonOptionalFieldDescriptor.getAddress();
DateOfBirth dob = addPersonOptionalFieldDescriptor.getDateOfBirth();
Gender gender = addPersonOptionalFieldDescriptor.getGender();

ReadOnlyPerson person = new Person(name, phone, email, address, dob, gender, tagList);

return new AddCommand(person);
Expand Down Expand Up @@ -285,7 +290,8 @@ public class AddLifeInsuranceCommandParser implements Parser<AddLifeInsuranceCom
}
}
```
###### \java\seedu\address\logic\parser\ParserUtil.java

###### /java/seedu/address/logic/parser/ParserUtil.java
``` java
/**
* Parses a {@code Optional<String> owner} into an {@code Optional<String>} if {@code owner} is present.
Expand All @@ -311,8 +317,9 @@ public class AddLifeInsuranceCommandParser implements Parser<AddLifeInsuranceCom
requireNonNull(contract);
return contract.isPresent() ? Optional.of(contract.get()) : Optional.empty();
}

```
###### \java\seedu\address\model\AddressBook.java
###### /java/seedu/address/model/AddressBook.java
``` java
private final UniqueLifeInsuranceMap lifeInsuranceMap;
```
Expand Down Expand Up @@ -350,11 +357,11 @@ public class AddLifeInsuranceCommandParser implements Parser<AddLifeInsuranceCom
*/
public void syncMasterLifeInsuranceMap() {
lifeInsuranceMap.forEach((id, insurance) -> {
insurance.resetAllInsurancePerson();
String owner = insurance.getOwner().getName();
String insured = insurance.getInsured().getName();
String beneficiary = insurance.getBeneficiary().getName();
persons.forEach(person -> {
//person.clearLifeInsuranceIds();
if (person.getName().fullName.equals(owner)) {
insurance.setOwner(person);
person.addLifeInsuranceIds(id);
Expand All @@ -369,6 +376,7 @@ public class AddLifeInsuranceCommandParser implements Parser<AddLifeInsuranceCom
}
});
});
lifeInsuranceMap.syncMappedListWithInternalMap();
}

/**
Expand Down Expand Up @@ -547,7 +555,8 @@ public class UniqueLifeInsuranceList implements Iterable<LifeInsurance> {
*/
public class UniqueLifeInsuranceMap {

private final HashMap<UUID, LifeInsurance> internalMap = new HashMap<>();
private final ObservableMap<UUID, LifeInsurance> internalMap = FXCollections.observableHashMap();
private final ObservableList<ReadOnlyInsurance> internalList = FXCollections.observableArrayList();

/**
* Returns true if the map contains an equivalent UUID as the given argument.
Expand Down Expand Up @@ -600,6 +609,7 @@ public class UniqueLifeInsuranceMap {
public void setInsurances(UniqueLifeInsuranceMap replacement) {
this.internalMap.clear();
this.internalMap.putAll(replacement.internalMap);
syncMappedListWithInternalMap();
}

public void setInsurances(Map<UUID, ? extends ReadOnlyInsurance> insurances) throws DuplicateInsuranceException {
Expand All @@ -610,6 +620,41 @@ public class UniqueLifeInsuranceMap {
setInsurances(replacement);
}

/**
* Ensures that every insurance in the internalList:
* contains the same exact same collections of insurances as that of the insuranceMap.
*/
public void syncMappedListWithInternalMap() {
this.internalList.clear();
this.internalList.setAll(this.internalMap.values());
}
```
###### /java/seedu/address/model/insurance/UniqueLifeInsuranceMap.java
``` java
/**
* Returns the backing map as an unmodifiable {@code ObservableList}.
*/
public Map<UUID, ReadOnlyInsurance> asMap() {
assert CollectionUtil.elementsAreUnique(internalMap.values());
return Collections.unmodifiableMap(internalMap);
}

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

@Override
public int hashCode() {
return internalMap.hashCode();
}
```
###### /java/seedu/address/model/Model.java
``` java
/** Returns an unmodifiable view of the filtered insurance list */
ObservableList<ReadOnlyInsurance> getFilteredInsuranceList();
```
###### \java\seedu\address\model\person\Address.java
``` java
Expand Down Expand Up @@ -826,9 +871,8 @@ public class XmlAdaptedLifeInsurance {
final Phone phone = this.phone.equals("") ? new Phone() : new Phone(this.phone);
final Email email = this.email.equals("") ? new Email() : new Email(this.email);
final Address address = this.address.equals("") ? new Address() : new Address(this.address);
```
###### \java\seedu\address\storage\XmlAdaptedPerson.java
``` java
final DateOfBirth dob = this.dob.equals("") ? new DateOfBirth() : new DateOfBirth(this.dob);
final Gender gender = this.gender.equals("") ? new Gender() : new Gender(this.gender);
final Set<Tag> tags = new HashSet<>(personTags);
return new Person(name, phone, email, address, dob, gender, tags, personLifeInsuranceIds);
}
Expand Down Expand Up @@ -859,11 +903,6 @@ public class XmlAdaptedLifeInsurance {
```
###### \java\seedu\address\ui\InsuranceListPanel.java
``` java
/**
* The Insurance Panel of the App.
*/
public class InsuranceListPanel extends UiPart<Region> {

private static final String FXML = "InsuranceListPanel.fxml";
private final Logger logger = LogsCenter.getLogger(this.getClass());

Expand Down Expand Up @@ -900,7 +939,6 @@ public class InsuranceListPanel extends UiPart<Region> {
setEventHandlerForSelectionChangeEvent();

}

```
###### \java\seedu\address\ui\InsuranceProfile.java
``` java
Expand Down
54 changes: 35 additions & 19 deletions collated/test/OscarWang114.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,49 @@
public void parse_optionalFieldsMissing_success() {
// zero tags
Person expectedPerson = new PersonBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY)
.withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY).withDateOfBirth(VALID_DOB_AMY)
.withTags().build();
assertParseSuccess(parser, AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY + DOB_DESC_AMY, new AddCommand(expectedPerson));
.withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY)
.withDateOfBirth(VALID_DOB_AMY).withGender(VALID_GENDER_AMY).withTags().build();
assertParseSuccess(parser, AddCommand.COMMAND_WORD + NAME_DESC_AMY
+ PHONE_DESC_AMY + EMAIL_DESC_AMY + ADDRESS_DESC_AMY + DOB_DESC_AMY
+ GENDER_DESC_AMY, new AddCommand(expectedPerson));

// missing phone prefix
expectedPerson = new PersonBuilder().withName(VALID_NAME_AMY).withEmptyPhone()
.withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY).withDateOfBirth(VALID_DOB_AMY)
.withTags().build();
.withGender(VALID_GENDER_AMY).withTags().build();
assertParseSuccess(parser, AddCommand.COMMAND_WORD + NAME_DESC_AMY
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY + DOB_DESC_AMY, new AddCommand(expectedPerson));
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY + DOB_DESC_AMY + GENDER_DESC_AMY, new AddCommand(expectedPerson));

// missing email prefix
expectedPerson = new PersonBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY)
.withEmptyEmail().withAddress(VALID_ADDRESS_AMY).withDateOfBirth(VALID_DOB_AMY)
.withTags().build();
.withGender(VALID_GENDER_AMY).withTags().build();
assertParseSuccess(parser, AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ ADDRESS_DESC_AMY + DOB_DESC_AMY, new AddCommand(expectedPerson));
+ ADDRESS_DESC_AMY + DOB_DESC_AMY
+ GENDER_DESC_AMY, new AddCommand(expectedPerson));

// missing address prefix
expectedPerson = new PersonBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY)
.withEmail(VALID_EMAIL_AMY).withDateOfBirth(VALID_DOB_AMY)
.withEmptyAddress().withTags().build();
.withGender(VALID_GENDER_AMY).withEmptyAddress().withTags().build();
assertParseSuccess(parser, AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ EMAIL_DESC_AMY + DOB_DESC_AMY, new AddCommand(expectedPerson));
+ EMAIL_DESC_AMY + DOB_DESC_AMY
+ GENDER_DESC_AMY, new AddCommand(expectedPerson));

// missing date of birth prefix
expectedPerson = new PersonBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY)
.withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY)
.withEmptyDateOfBirth().withTags().build();
.withGender(VALID_GENDER_AMY).withEmptyDateOfBirth().withTags().build();
assertParseSuccess(parser, AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY, new AddCommand(expectedPerson));
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY
+ GENDER_DESC_AMY, new AddCommand(expectedPerson));

// missing gender prefix
expectedPerson = new PersonBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY)
.withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY).withDateOfBirth(VALID_DOB_AMY)
.withEmptyGender().withTags().build();
assertParseSuccess(parser, AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY + DOB_DESC_AMY, new AddCommand(expectedPerson));
}
```
###### /java/seedu/address/testutil/PersonBuilder.java
Expand Down Expand Up @@ -71,39 +82,44 @@
```
###### /java/seedu/address/testutil/TypicalPersons.java
``` java

public static final ReadOnlyPerson AMY_NO_PHONE = new PersonBuilder().withName(VALID_NAME_AMY).withEmptyPhone()
.withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY)
.withDateOfBirth(VALID_DOB_AMY).withTags(VALID_TAG_FRIEND).build();
.withDateOfBirth(VALID_DOB_AMY).withGender(VALID_GENDER_AMY).withTags(VALID_TAG_FRIEND).build();
public static final ReadOnlyPerson AMY_NO_EMAIL = new PersonBuilder().withName(VALID_NAME_AMY)
.withPhone(VALID_PHONE_AMY).withEmptyEmail().withAddress(VALID_ADDRESS_AMY)
.withDateOfBirth(VALID_DOB_AMY).withTags(VALID_TAG_FRIEND)
.build();
.withGender(VALID_GENDER_AMY).build();
public static final ReadOnlyPerson AMY_NO_ADDRESS = new PersonBuilder().withName(VALID_NAME_AMY)
.withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_AMY).withEmptyAddress()
.withDateOfBirth(VALID_DOB_AMY).withTags(VALID_TAG_FRIEND)
.build();
.withGender(VALID_GENDER_AMY).build();

```
###### /java/systemtests/AddCommandSystemTest.java
``` java
/* Case: missing phone -> added */
command = AddCommand.COMMAND_WORD + NAME_DESC_AMY + EMAIL_DESC_AMY
+ ADDRESS_DESC_AMY + DOB_DESC_AMY + TAG_DESC_FRIEND;
+ ADDRESS_DESC_AMY + DOB_DESC_AMY
+ GENDER_DESC_AMY + TAG_DESC_FRIEND;
assertCommandSuccess(command, AMY_NO_PHONE);

/* Case: missing email -> added */
command = AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ ADDRESS_DESC_AMY + DOB_DESC_AMY + TAG_DESC_FRIEND;
+ ADDRESS_DESC_AMY + DOB_DESC_AMY
+ GENDER_DESC_AMY + TAG_DESC_FRIEND;
assertCommandSuccess(command, AMY_NO_EMAIL);

/* Case: missing address -> added */
command = AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ EMAIL_DESC_AMY + DOB_DESC_AMY + TAG_DESC_FRIEND;
+ EMAIL_DESC_AMY + DOB_DESC_AMY
+ GENDER_DESC_AMY + TAG_DESC_FRIEND;
assertCommandSuccess(command, AMY_NO_ADDRESS);
```
###### /java/systemtests/AddCommandSystemTest.java
``` java
/* Case: missing name -> rejected */
command = AddCommand.COMMAND_WORD + PHONE_DESC_AMY + EMAIL_DESC_AMY
+ ADDRESS_DESC_AMY + DOB_DESC_AMY;
+ ADDRESS_DESC_AMY + GENDER_DESC_AMY + DOB_DESC_AMY;
assertCommandFailure(command, String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
```
Loading

0 comments on commit fa9ba22

Please sign in to comment.