Skip to content

Commit 10ba16d

Browse files
authored
Merge pull request nus-cs2103-AY2021S1#61 from yyutong/add-expense.Expense
Add expense.expense
2 parents 804bf7b + 99995a5 commit 10ba16d

6 files changed

Lines changed: 207 additions & 0 deletions

File tree

src/main/java/seedu/address/logic/parser/ParserUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
package seedu.address.logic.parser;
23

34
import static java.util.Objects.requireNonNull;

src/main/java/seedu/address/model/person/Description.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public static boolean isValidDescription(String test) {
3737
return test.matches(VALIDATION_REGEX);
3838
}
3939

40+
public boolean isEmpty() {
41+
return value == null
42+
? true
43+
: false;
44+
}
45+
4046
@Override
4147
public String toString() {
4248
return value;
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package seedu.address.model.person;
2+
3+
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
4+
5+
import java.util.Objects;
6+
7+
public class Expense {
8+
9+
// Identity fields
10+
private final Amount amount;
11+
private final Date date;
12+
private final Category category;
13+
private final Description description;
14+
15+
/**
16+
* Every field must be present and not null.
17+
*/
18+
public Expense(Amount amount, Date date, Category category, Description description) {
19+
requireAllNonNull(amount, date, category);
20+
this.amount = amount;
21+
this.date = date;
22+
this.category = category;
23+
this.description = description;
24+
}
25+
26+
public Amount getAmount() {
27+
return this.amount;
28+
}
29+
30+
public Date getDate() {
31+
return this.date;
32+
}
33+
34+
public Category getCategory() {
35+
return this.category;
36+
}
37+
38+
public Description getDescription() {
39+
return this.description;
40+
}
41+
42+
43+
/**
44+
* Returns true if both persons of the same name have at least one other identity field that is the same.
45+
* This defines a weaker notion of equality between two persons.
46+
*/
47+
public boolean isSameExpense(Expense otherExpense) {
48+
if (otherExpense == this) {
49+
return true;
50+
}
51+
52+
return otherExpense != null
53+
&& otherExpense.getAmount().equals(this.getAmount())
54+
&& otherExpense.getDate().equals(this.getDate())
55+
&& otherExpense.getCategory().equals(this.getCategory())
56+
&& otherExpense.getDescription().equals(this.getDescription());
57+
}
58+
59+
/**
60+
* Returns true if both persons have the same identity and data fields.
61+
* This defines a stronger notion of equality between two persons.
62+
*/
63+
@Override
64+
public boolean equals(Object other) {
65+
if (other == this) {
66+
return true;
67+
}
68+
69+
if (!(other instanceof Expense)) {
70+
return false;
71+
}
72+
73+
Expense otherExpense = (Expense) other;
74+
return otherExpense.getAmount().equals(getAmount())
75+
&& otherExpense.getDate().equals(getDate())
76+
&& otherExpense.getCategory().equals(getCategory())
77+
&& otherExpense.getDescription().equals(getDescription());
78+
}
79+
80+
@Override
81+
public int hashCode() {
82+
// use this method for custom fields hashing instead of implementing your own
83+
return Objects.hash(amount, date, category, description);
84+
}
85+
86+
@Override
87+
public String toString() {
88+
final StringBuilder builder = new StringBuilder();
89+
90+
if (description.isEmpty()) {
91+
builder.append(" Amount: ")
92+
.append(this.getAmount())
93+
.append(" Date: ")
94+
.append(this.getDate())
95+
.append(" Category: ")
96+
.append(this.getCategory());
97+
return builder.toString();
98+
} else {
99+
builder.append(" Amount: ")
100+
.append(this.getAmount())
101+
.append(" Date: ")
102+
.append(this.getDate())
103+
.append(" Category: ")
104+
.append(this.getCategory())
105+
.append(" Description: ")
106+
.append(this.getDescription());
107+
return builder.toString();
108+
}
109+
}
110+
111+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package seedu.address.model.person;
2+
3+
4+
public class ExpenseTest {
5+
6+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package seedu.address.testutil;
2+
3+
import seedu.address.model.person.Amount;
4+
import seedu.address.model.person.Category;
5+
import seedu.address.model.person.Date;
6+
import seedu.address.model.person.Description;
7+
import seedu.address.model.person.Expense;
8+
9+
/**
10+
* A utility class to help with building Person objects.
11+
*/
12+
public class ExpenseBuilder {
13+
14+
public static final Double DEFAULT_AMOUNT = 10.0;
15+
public static final String DEFAULT_DATE = "2020-10-07";
16+
public static final String DEFAULT_CATEGORY = "FOOD";
17+
public static final String DEFAULT_DESCRIPTION = "123, Jurong West Ave 6, #08-111";
18+
private Amount amount;
19+
private Date date;
20+
private Category category;
21+
private Description description;
22+
23+
/**
24+
* Creates a {@code PersonBuilder} with the default details.
25+
*/
26+
public ExpenseBuilder() {
27+
amount = new Amount(DEFAULT_AMOUNT);
28+
date = new Date(DEFAULT_DATE);
29+
category = new Category(DEFAULT_CATEGORY);
30+
description = new Description(DEFAULT_DESCRIPTION);
31+
}
32+
33+
/**
34+
* Initializes the PersonBuilder with the data of {@code personToCopy}.
35+
*/
36+
public ExpenseBuilder(Expense expenseToCopy) {
37+
amount = expenseToCopy.getAmount();
38+
date = expenseToCopy.getDate();
39+
category = expenseToCopy.getCategory();
40+
description = expenseToCopy.getDescription();
41+
}
42+
43+
/**
44+
* Sets the {@code Name} of the {@code Person} that we are building.
45+
*/
46+
public ExpenseBuilder withAmount(Double amount) {
47+
this.amount = new Amount(amount);
48+
return this;
49+
}
50+
51+
/**
52+
* Sets the {@code Address} of the {@code Person} that we are building.
53+
*/
54+
public ExpenseBuilder withDate(String date) {
55+
return this;
56+
}
57+
58+
/**
59+
* Sets the {@code Phone} of the {@code Person} that we are building.
60+
*/
61+
public ExpenseBuilder withCategory(String category) {
62+
this.category = new Category(category);
63+
return this;
64+
}
65+
66+
/**
67+
* Sets the {@code Email} of the {@code Person} that we are building.
68+
*/
69+
public ExpenseBuilder withDescription(String description) {
70+
this.description = new Description(description);
71+
return this;
72+
}
73+
74+
public Expense build() {
75+
return new Expense(amount, date, category, description);
76+
}
77+
78+
}
79+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package seedu.address.testutil;
2+
3+
public class TypicalExpense {
4+
}

0 commit comments

Comments
 (0)