Skip to content

Commit

Permalink
Merge pull request #76 from KhoonSun47/branch-add-json
Browse files Browse the repository at this point in the history
Branch-Add-Json
  • Loading branch information
felixchanyy authored Mar 28, 2024
2 parents 9501a41 + fdc068f commit 0658640
Show file tree
Hide file tree
Showing 33 changed files with 500 additions and 294 deletions.
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static String getErrorMessageForDuplicatePrefixes(Prefix... duplicatePref
}

/**
* Formats the {@code person} for display to the user.
* Formats the {@code person} for display to the user, differentiating between Buyer and Seller.
*/
public static String format(Person person) {
final StringBuilder builder = new StringBuilder();
Expand All @@ -47,5 +47,4 @@ public static String format(Person person) {
person.getTags().forEach(builder::append);
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AddBuyerCommand extends Command {
+ PREFIX_TAG + "owesMoney";

public static final String MESSAGE_SUCCESS = "New buyer added: %1$s";
public static final String MESSAGE_DUPLICATE_BUYER = "This buyer already exists in EstateEase";
public static final String MESSAGE_DUPLICATE_BUYER = "This person already exists in EstateEase";

private final Person buyerToAdd;

Expand Down
99 changes: 0 additions & 99 deletions src/main/java/seedu/address/logic/commands/AddCommand.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class AddSellerCommand extends Command {
+ PREFIX_TAG + "owesMoney ";

public static final String MESSAGE_SUCCESS = "New seller added= %1$s";
public static final String MESSAGE_DUPLICATE_SELLER = "This seller already exists in EstateEase";
public static final String MESSAGE_DUPLICATE_SELLER = "This person already exists in EstateEase";

private final Person sellerToAdd;

Expand Down
7 changes: 0 additions & 7 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
String updatedHouse = editPersonDescriptor.getHousingType().orElse(personToEdit.getHousingType());
/*
Street updatedStreet = editPersonDescriptor.getStreet().orElse(personToEdit.getStreet());
Level updatedLevel = editPersonDescriptor.getLevel().orElse(personToEdit.getLevel());
Block updatedBlock = editPersonDescriptor.getBlock().orElse(personToEdit.getBlock());
UnitNumber unitNumber = editPersonDescriptor.getUnitNumber().orElse(personToEdit.getUnitNumber());
PostalCode postalCode = editPersonDescriptor.getPostalCode().orElse(personToEdit.getPostalCode());
*/
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

return new Person(updatedName, updatedPhone, updatedEmail, updatedHouse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

import seedu.address.logic.commands.AddBuyerCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Buyer;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.Tag;

Expand Down Expand Up @@ -45,9 +45,8 @@ public AddBuyerCommand parse(String args) throws ParseException {
String housingType = ParserUtil.parseHousing(argMultimap.getValue(PREFIX_HOUSING_TYPE).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

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

return new AddBuyerCommand(person);
Buyer buyer = new Buyer(name, phone, email, housingType, tagList);
return new AddBuyerCommand(buyer);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class AddSellerCommandParser implements Parser<AddSellerCommand> {
public AddSellerCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_HOUSING_TYPE, PREFIX_LEVEL,
PREFIX_BLOCK, PREFIX_STREET, PREFIX_UNITNUMBER, PREFIX_POSTALCODE, PREFIX_TAG);
PREFIX_HOUSING_TYPE, PREFIX_LEVEL, PREFIX_BLOCK, PREFIX_STREET,
PREFIX_UNITNUMBER, PREFIX_POSTALCODE, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_HOUSING_TYPE,
PREFIX_POSTALCODE, PREFIX_STREET, PREFIX_UNITNUMBER) || !argMultimap.getPreamble().isEmpty()) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/seedu/address/model/house/House.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.model.house;

import seedu.address.commons.util.ToStringBuilder;

/**
* Represents a House.
* Guarantees: details are present and not null, field values are validated, immutable.
Expand Down Expand Up @@ -141,6 +143,10 @@ public boolean equals(Object other) {
*/
@Override
public String toString() {
return "House Address: " + this.unitNumber + ", " + this.street + ", S" + this.postalCode;
return new ToStringBuilder(this)
.add("Unit Number", unitNumber)
.add("Street", street)
.add("Postal Code", postalCode)
.toString();
}
}
6 changes: 5 additions & 1 deletion src/main/java/seedu/address/model/house/Landed.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.model.house;

import seedu.address.commons.util.ToStringBuilder;

/**
* Represents a landed house.
*/
Expand All @@ -23,6 +25,8 @@ public Landed(UnitNumber unitNumber, PostalCode postalCode, Street street) {
*/
@Override
public String toString() {
return "Landed House: " + super.toString();
ToStringBuilder builder = new ToStringBuilder(this);
// For now, it just appends the super class's toString method.
return "Landed House: " + builder.toString() + ", " + super.toString();
}
}
13 changes: 10 additions & 3 deletions src/main/java/seedu/address/model/house/NonLanded.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.model.house;

import seedu.address.commons.util.ToStringBuilder;

/**
* Represents a non-landed house.
*/
Expand Down Expand Up @@ -70,8 +72,13 @@ public Level getLevel() {
*/
@Override
public String toString() {
String blockLevelInfo = (block != null ? "Block: " + block.value + ", " : "")
+ (level != null ? "Level: " + level.value + ", " : "");
return "Non-Landed House: " + blockLevelInfo + super.toString();
ToStringBuilder builder = new ToStringBuilder(this);
if (block != null) {
builder.add("Block", block);
}
if (level != null) {
builder.add("Level", level);
}
return "Non-Landed House: " + builder.toString() + ", " + super.toString();
}
}
12 changes: 0 additions & 12 deletions src/main/java/seedu/address/model/person/Buyer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Set;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -22,15 +21,4 @@ public class Buyer extends Person {
public Buyer(Name name, Phone phone, Email email, String housingType, Set<Tag> tags) {
super(name, phone, email, housingType, tags);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("name", super.getName())
.add("phone", super.getPhone())
.add("email", super.getEmail())
.add("housing type", super.getHousingType())
.add("tags", super.getTags())
.toString();
}
}
1 change: 0 additions & 1 deletion src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,4 @@ public String toString() {
.add("tags", tags)
.toString();
}

}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Seller.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public void addHouse(House house) {
* @return An ArrayList containing House objects.
*/
public ArrayList<House> getHouses() {
return new ArrayList<>(houses); // Returns a copy of the houses list
return new ArrayList<>(houses);
}
}
78 changes: 55 additions & 23 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,80 @@
package seedu.address.model.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.house.Block;
import seedu.address.model.house.House;
import seedu.address.model.house.Level;
import seedu.address.model.house.NonLanded;
import seedu.address.model.house.PostalCode;
import seedu.address.model.house.Street;
import seedu.address.model.house.UnitNumber;
import seedu.address.model.person.Buyer;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Seller;
import seedu.address.model.tag.Tag;

/**
* Contains utility methods for populating {@code AddressBook} with sample data.
*/
public class SampleDataUtil {
public static Person[] getSamplePersons() {
return new Person[] {
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"),
"HDB",
getTagSet("friends")),
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"),
"Condominium",
getTagSet("colleagues", "friends")),
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"),
"HDB",
getTagSet("neighbours")),
new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"),
"HDB",
getTagSet("family")),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"),
"HDB",
getTagSet("classmates")),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"),
"HDB",
getTagSet("colleagues"))
public static Buyer[] getSampleBuyers() {
return new Buyer[] {
new Buyer(new Name("Alex Yeoh"), new Phone("87438807"),
new Email("alexyeoh@example.com"), "HDB",
getTagSet("friends")),
new Buyer(new Name("Bernice Yu"), new Phone("99272758"),
new Email("berniceyu@example.com"), "Condominium",
getTagSet("colleagues", "friends")),
new Buyer(new Name("Charlotte Oliveiro"), new Phone("93210283"),
new Email("charlotte@example.com"), "HDB",
getTagSet("neighbours")),
};
}

public static Seller[] getSampleSellers() {
ArrayList<House> davidLiHouses = new ArrayList<>();
davidLiHouses.add(new NonLanded(new Block("51"), new Level("3"), new PostalCode("098703"),
new Street("Ang Mo Kio Avenue 1"), new UnitNumber("02")));
ArrayList<House> irfanHouses = new ArrayList<>();
irfanHouses.add(new NonLanded(new Block("52"), new Level("4"), new PostalCode("098713"),
new Street("Ang Mo Kio Avenue 2"), new UnitNumber("03")));
ArrayList<House> royHouses = new ArrayList<>();
royHouses.add(new NonLanded(new Block("53"), new Level("5"), new PostalCode("098723"),
new Street("Ang Mo Kio Avenue 3"), new UnitNumber("04")));
royHouses.add(new NonLanded(new Block("54"), new Level("6"), new PostalCode("098724"),
new Street("Toa Payoh Avenue 4"), new UnitNumber("05")));

return new Seller[] {
new Seller(new Name("David Li"), new Phone("91031282"),
new Email("lidavid@example.com"), "HDB",
davidLiHouses,
getTagSet("family")),
new Seller(new Name("Irfan Ibrahim"), new Phone("92492021"),
new Email("irfan@example.com"), "Condominium",
irfanHouses,
getTagSet("classmates")),
new Seller(new Name("Roy Balakrishnan"), new Phone("92624417"),
new Email("royb@example.com"), "HDB",
royHouses,
getTagSet("colleagues"))
};
}

public static ReadOnlyAddressBook getSampleAddressBook() {
AddressBook sampleAb = new AddressBook();
for (Person samplePerson : getSamplePersons()) {
sampleAb.addPerson(samplePerson);
for (Buyer sampleBuyer : getSampleBuyers()) {
sampleAb.addPerson(sampleBuyer);
}
for (Seller sampleSeller : getSampleSellers()) {
sampleAb.addPerson(sampleSeller);
}
return sampleAb;
}
Expand Down
Loading

0 comments on commit 0658640

Please sign in to comment.