1
+ package com .example .expenses .repository ;
2
+
3
+ import com .example .expenses .model .Expense ;
4
+ import com .example .expenses .model .Person ;
5
+
6
+ import java .util .List ;
7
+ import java .util .Optional ;
8
+
9
+ /**
10
+ * DataRepository:
11
+ * I define the protocol -- the set of methods -- that other parts of the application can use to
12
+ * persist instances of the domain model (Persons, Expenses).
13
+ * <p>
14
+ * My name, {@code DataRepository}, is intended to indicate the abstract idea that <em>this</em>
15
+ * is where data lives, without binding to any specific implementation like memory, file or database.
16
+ * <p>
17
+ */
18
+ public interface DataRepository {
19
+
20
+ /**
21
+ * Add a new Person instance to the datastore. If the Person passed to this method already exists
22
+ * in the repository, we'll return that instance and ignore the request.
23
+ * If you ask for a {@literal null} Person, it will throw a NullPointerException.
24
+ * @param person A non-null Person instance.
25
+ * @return The Person instance you added or that already existed in the repository.
26
+ */
27
+ Person addPerson (Person person );
28
+
29
+ /**
30
+ * Find a Person instance with the given email address.
31
+ * @param email Email address of the Person we want to find.
32
+ * @return An Optional containing the Person if they exist in the repository, empty otherwise.
33
+ */
34
+ Optional <Person > findPerson ( String email );
35
+
36
+ /**
37
+ * Answer with a List of all Person instances in the repository.
38
+ * @return A set of Person instances, possible empty, but never {@literal null}.
39
+ */
40
+ List <Person > allPersons ();
41
+
42
+ /**
43
+ * Add a new Expense instance to the repository.
44
+ * If this expense's id is null, then it will be filled in with a random UUID.
45
+ * If this expense's data is null,k then it will be filled in with today's date.
46
+ * @param expense A non-null Expense instance
47
+ * @return The Expense instance you added
48
+ */
49
+ Expense addExpense (Expense expense );
50
+
51
+ /**
52
+ * Finds all the expenses paid for by specified person.
53
+ * @param person the non-null Person instance that must match the Expense's paidByPerson field.
54
+ * @return A set of Expense instances, possible empty, but never {@literal null}. Sorted ascending according to date.
55
+ */
56
+ List <Expense > findExpensesPaidBy (Person person );
57
+
58
+ /**
59
+ * Answer with a List of all Expense instances in the repository.
60
+ * @return A set of Expense instances, possible empty, but never {@literal null}. Sorted ascending according to date.
61
+ */
62
+ List <Expense > allExpenses ();
63
+
64
+ }
0 commit comments