Skip to content

Commit

Permalink
Merge 3fdf653 into c663e60
Browse files Browse the repository at this point in the history
  • Loading branch information
prokarius committed Oct 25, 2018
2 parents c663e60 + 3fdf653 commit c89436c
Show file tree
Hide file tree
Showing 32 changed files with 428 additions and 250 deletions.
3 changes: 0 additions & 3 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_BIKE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LOANRATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LOANTIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
Expand All @@ -32,7 +31,6 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_BIKE + "BIKE "
+ PREFIX_LOANRATE + "LOANRATE "
+ PREFIX_LOANTIME + "LOANTIME "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
Expand All @@ -42,7 +40,6 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_BIKE + "Bike001 "
+ PREFIX_LOANRATE + "3.5 "
+ PREFIX_LOANTIME + "2018-10-01 12:00 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

Expand Down
34 changes: 22 additions & 12 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_BIKE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LOANRATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LOANTIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
Expand Down Expand Up @@ -54,7 +53,6 @@ public class EditCommand extends Command {
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_BIKE + "BIKE] "
+ "[" + PREFIX_LOANRATE + "LOANRATE] "
+ "[" + PREFIX_LOANTIME + "LOANTIME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
Expand Down Expand Up @@ -115,7 +113,8 @@ private static Loan createEditedLoan(Loan loanToEdit, EditLoanDescriptor editLoa
Address updatedAddress = editLoanDescriptor.getAddress().orElse(loanToEdit.getAddress());
Bike updatedBike = editLoanDescriptor.getBike().orElse(loanToEdit.getBike());
LoanRate updatedRate = editLoanDescriptor.getLoanRate().orElse(loanToEdit.getLoanRate());
LoanTime updatedTime = editLoanDescriptor.getLoanTime().orElse(loanToEdit.getLoanTime());
LoanTime updatedStartTime = editLoanDescriptor.getLoanStartTime().orElse(loanToEdit.getLoanStartTime());
LoanTime updatedEndTime = editLoanDescriptor.getLoanEndTime().orElse(loanToEdit.getLoanEndTime());
Set<Tag> updatedTags = editLoanDescriptor.getTags().orElse(loanToEdit.getTags());
LoanStatus updatedLoanStatus = editLoanDescriptor.getLoanStatus().orElse(loanToEdit.getLoanStatus());

Expand All @@ -126,8 +125,10 @@ private static Loan createEditedLoan(Loan loanToEdit, EditLoanDescriptor editLoa
updatedAddress,
updatedBike,
updatedRate,
updatedTime,
updatedLoanStatus, updatedTags
updatedStartTime,
updatedEndTime,
updatedLoanStatus,
updatedTags
);
}

Expand Down Expand Up @@ -161,7 +162,8 @@ public static class EditLoanDescriptor {
private Address address;
private Bike bike;
private LoanRate rate;
private LoanTime time;
private LoanTime startTime;
private LoanTime endTime;
private Set<Tag> tags;
private LoanStatus loanStatus;

Expand All @@ -179,7 +181,8 @@ public EditLoanDescriptor(EditLoanDescriptor toCopy) {
setAddress(toCopy.address);
setBike(toCopy.bike);
setLoanRate(toCopy.rate);
setLoanTime(toCopy.time);
setLoanStartTime(toCopy.startTime);
setLoanEndTime(toCopy.endTime);
setTags(toCopy.tags);
setLoanStatus(toCopy.loanStatus);
}
Expand Down Expand Up @@ -247,12 +250,20 @@ public Optional<LoanRate> getLoanRate() {
return Optional.ofNullable(rate);
}

public void setLoanTime(LoanTime time) {
this.time = time;
public void setLoanStartTime(LoanTime time) {
this.startTime = time;
}

public Optional<LoanTime> getLoanTime() {
return Optional.ofNullable(time);
public Optional<LoanTime> getLoanStartTime() {
return Optional.ofNullable(startTime);
}

public void setLoanEndTime(LoanTime time) {
this.endTime = time;
}

public Optional<LoanTime> getLoanEndTime() {
return Optional.ofNullable(endTime);
}

/**
Expand Down Expand Up @@ -302,7 +313,6 @@ && getEmail().equals(e.getEmail())
&& getAddress().equals(e.getAddress())
&& getBike().equals(e.getBike())
&& getLoanRate().equals(e.getLoanRate())
&& getLoanTime().equals(e.getLoanTime())
&& getTags().equals(e.getTags());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_BIKE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LOANRATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LOANTIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
Expand All @@ -21,7 +20,6 @@
import seedu.address.model.loan.Email;
import seedu.address.model.loan.Loan;
import seedu.address.model.loan.LoanRate;
import seedu.address.model.loan.LoanTime;
import seedu.address.model.loan.Name;
import seedu.address.model.loan.Nric;
import seedu.address.model.loan.Phone;
Expand All @@ -47,7 +45,6 @@ public AddCommand parse(String args) throws ParseException {
PREFIX_ADDRESS,
PREFIX_BIKE,
PREFIX_LOANRATE,
PREFIX_LOANTIME,
PREFIX_TAG);

if (!arePrefixesPresent(argMultimap,
Expand All @@ -57,8 +54,7 @@ public AddCommand parse(String args) throws ParseException {
PREFIX_EMAIL,
PREFIX_ADDRESS,
PREFIX_BIKE,
PREFIX_LOANRATE,
PREFIX_LOANTIME)
PREFIX_LOANRATE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}
Expand All @@ -70,10 +66,9 @@ public AddCommand parse(String args) throws ParseException {
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Bike bike = ParserUtil.parseBike(argMultimap.getValue(PREFIX_BIKE).get());
LoanRate rate = ParserUtil.parseLoanRate(argMultimap.getValue(PREFIX_LOANRATE).get());
LoanTime time = ParserUtil.parseLoanTime(argMultimap.getValue(PREFIX_LOANTIME).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Loan loan = new Loan(name, nric, phone, email, address, bike, rate, time, tagList);
Loan loan = new Loan(name, nric, phone, email, address, bike, rate, tagList);

return new AddCommand(loan);
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class CliSyntax {
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_BIKE = new Prefix("b/");
public static final Prefix PREFIX_LOANRATE = new Prefix("lr/");
public static final Prefix PREFIX_LOANTIME = new Prefix("lt/");
public static final Prefix PREFIX_TAG = new Prefix("t/");

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_BIKE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LOANRATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LOANTIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
Expand Down Expand Up @@ -37,7 +36,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_NRIC, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_BIKE, PREFIX_LOANRATE, PREFIX_LOANTIME, PREFIX_TAG);
PREFIX_BIKE, PREFIX_LOANRATE, PREFIX_TAG);

Index index;

Expand Down Expand Up @@ -69,9 +68,6 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_LOANRATE).isPresent()) {
editLoanDescriptor.setLoanRate(ParserUtil.parseLoanRate(argMultimap.getValue(PREFIX_LOANRATE).get()));
}
if (argMultimap.getValue(PREFIX_LOANTIME).isPresent()) {
editLoanDescriptor.setLoanTime(ParserUtil.parseLoanTime(argMultimap.getValue(PREFIX_LOANTIME).get()));
}
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editLoanDescriptor::setTags);

if (!editLoanDescriptor.isAnyFieldEdited()) {
Expand Down
78 changes: 54 additions & 24 deletions src/main/java/seedu/address/model/loan/Loan.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class Loan implements UniqueListItem<Loan> {

// Data fields
private final LoanRate rate;
private final LoanTime time;
private final LoanTime startTime;
private final LoanTime endTime; // Note that endTime can be null
private final Phone phone;
private final Email email;
private final Address address;
Expand All @@ -45,13 +46,30 @@ public Loan(Name name,
Address address,
Bike bike,
LoanRate rate,
LoanTime time,
LoanTime startTime,
LoanTime endTime,
LoanStatus loanStatus,
Set<Tag> tags) {
this(name, nric, phone, email, address, bike, rate, time, LoanStatus.ONGOING, tags);
// Note that endTime can be null. This loans in progress do not have an endTime.
requireAllNonNull(name, nric, phone, email, address, bike, rate, startTime, tags);
this.name = name;
this.nric = nric;
this.phone = phone;
this.email = email;
this.address = address;
this.bike = bike;
this.rate = rate;
this.startTime = startTime;
this.endTime = endTime;
this.tags.addAll(tags);

// Initialise the loan to be ongoing.
this.loanStatus = loanStatus;
}

/**
* Every field must be present and not null.
* This constructor is used for the add command
*/
public Loan(Name name,
Nric nric,
Expand All @@ -60,21 +78,28 @@ public Loan(Name name,
Address address,
Bike bike,
LoanRate rate,
LoanTime time,
LoanStatus loanStatus, Set<Tag> tags) {
requireAllNonNull(name, nric, phone, email, address, bike, rate, time, tags, loanStatus);
this.name = name;
this.nric = nric;
this.phone = phone;
this.email = email;
this.address = address;
this.bike = bike;
this.rate = rate;
this.time = time;
this.tags.addAll(tags);
Set<Tag> tags) {
this(name, nric, phone, email, address, bike, rate,
new LoanTime(), null, LoanStatus.ONGOING, tags);
}

// Initialise the loan to be ongoing.
this.loanStatus = loanStatus;
/**
* Every field must be present and not null.
* This constructor is used when you know the start and end times.
* If you know the end time, then the loan would be returned.
*/
public Loan(Name name,
Nric nric,
Phone phone,
Email email,
Address address,
Bike bike,
LoanRate rate,
LoanTime startTime,
LoanTime endTime,
Set<Tag> tags) {
this(name, nric, phone, email, address, bike, rate,
startTime, endTime, LoanStatus.RETURNED, tags);
}

public Name getName() {
Expand Down Expand Up @@ -109,8 +134,12 @@ public LoanRate getLoanRate() {
return rate;
}

public LoanTime getLoanTime() {
return time;
public LoanTime getLoanStartTime() {
return startTime;
}

public LoanTime getLoanEndTime() {
return endTime;
}

/**
Expand Down Expand Up @@ -151,7 +180,7 @@ public boolean isSame(Loan other) {
&& other.getNric().equals(getNric())
&& other.getBike().equals(getBike())
&& (other.getEmail().equals(getEmail()) || other.getPhone().equals(getPhone())
|| other.getLoanRate().equals(getLoanRate()) || other.getLoanTime().equals(getLoanTime()));
|| other.getLoanRate().equals(getLoanRate()) || other.getLoanStartTime().equals(getLoanStartTime()));
}

/**
Expand All @@ -177,14 +206,13 @@ public boolean equals(Object other) {
&& otherLoan.getLoanStatus().equals(getLoanStatus())
&& otherLoan.getBike().equals(getBike())
&& otherLoan.getLoanRate().equals(getLoanRate())
&& otherLoan.getLoanTime().equals(getLoanTime())
&& otherLoan.getTags().equals(getTags());
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, nric, phone, email, address, bike, rate, time, tags, loanStatus);
return Objects.hash(name, nric, phone, email, address, bike, rate, startTime, endTime, loanStatus, tags);
}

@Override
Expand All @@ -205,8 +233,10 @@ public String toString() {
.append(getBike())
.append(" LoanRate: ")
.append(getLoanRate())
.append(" LoanTime: ")
.append(getLoanTime())
.append(" LoanStartTime: ")
.append(getLoanStartTime())
.append(" LoanEndTime: ")
.append(getLoanEndTime())
.append(" Tags: ");
getTags().forEach(builder::append);
return builder.toString();
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/seedu/address/model/loan/LoanTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,18 @@ public String toString() {

return dateTimeFormatter.format(value);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof LoanTime)) {
return false;
}

return this.value.getEpochSecond() == ((LoanTime) other).value.getEpochSecond();

}
}
12 changes: 6 additions & 6 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ public static Loan[] getSampleLoans() {
new Loan(new Name("Alex Yeoh"), new Nric("S9013904E"), new Phone("87438807"),
new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"),
new Bike(new Name("Bike001")), new LoanRate("12.9"), new LoanTime("2010-12-25 04:09"),
getTagSet("friends")),
new LoanTime("2010-12-25 05:09"), getTagSet("friends")),
new Loan(new Name("Bernice Yu"), new Nric("T0213176A"), new Phone("99272758"),
new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
new Bike(new Name("Bike002")), new LoanRate("1.95"), new LoanTime("2010-12-25 14:09"),
getTagSet("colleagues", "friends")),
new LoanTime("2010-12-26 08:34"), getTagSet("colleagues", "friends")),
new Loan(new Name("Charlotte Oliveiro"), new Nric("F9576390K"), new Phone("93210283"),
new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
new Bike(new Name("Silver Surfer")), new LoanRate("3.90"), new LoanTime("04:55"),
getTagSet("neighbours")),
new LoanTime("09:42"), getTagSet("neighbours")),
new Loan(new Name("David Li"), new Nric("G0846554T"), new Phone("91031282"),
new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
new Bike(new Name("Blue Ocean")), new LoanRate("33"), new LoanTime("12:21"),
getTagSet("family")),
new LoanTime("19:21"), getTagSet("family")),
new Loan(new Name("Irfan Ibrahim"), new Nric("S8830104H"), new Phone("92492021"),
new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"),
new Bike(new Name("Bike013")), new LoanRate("6.7"), new LoanTime("2018-01-30 15:10"),
getTagSet("classmates")),
new LoanTime("2018-01-31 15:10"), getTagSet("classmates")),
new Loan(new Name("Roy Balakrishnan"), new Nric("S7588900C"), new Phone("92624417"),
new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"),
new Bike(new Name("Bike099")), new LoanRate("3.95"), new LoanTime("2018-10-20 20:10"),
getTagSet("colleagues"))
new LoanTime("2018-01-30 11:17"), getTagSet("colleagues"))
};
}

Expand Down
Loading

0 comments on commit c89436c

Please sign in to comment.