1+ package com .blogspot .e_kanivets .moneytracker .repo ;
2+
3+ import android .database .sqlite .SQLiteOpenHelper ;
4+ import android .support .annotation .NonNull ;
5+ import android .support .annotation .Nullable ;
6+
7+ import java .util .List ;
8+
9+ /**
10+ * Interface that represents a contract of access to abstract storage with CRUD operations.
11+ * Created on 2/15/16.
12+ *
13+ * @author Evgenii Kanivets
14+ */
15+ public interface IRepo <T > {
16+ /**
17+ * Creates a record with given fields values in storage.
18+ *
19+ * @param instance is entity instance to be created.
20+ * @return created record or null if can't create.
21+ */
22+ @ Nullable
23+ T create (T instance );
24+
25+ /**
26+ * Reads a record from storage.
27+ *
28+ * @param id is identification number of record to be read.
29+ * @return read record or null if one not exist.
30+ */
31+ @ Nullable
32+ T read (long id );
33+
34+ /**
35+ * Updates a record in storage.
36+ *
37+ * @param instance is entity instance to be updated.
38+ * @return updated record or null if can't update.
39+ */
40+ @ Nullable
41+ T update (T instance );
42+
43+ /**
44+ * Deletes a record from storage.
45+ *
46+ * @param instance is entity instance to be deleted.
47+ * @return true if deleted or false if not.
48+ */
49+ boolean delete (T instance );
50+
51+ /**
52+ * Reads all records from storage.
53+ *
54+ * @return list of all records. List can't be null, but may be zero sized.
55+ */
56+ @ NonNull
57+ List <T > readAll ();
58+
59+ /**
60+ * Reads all records from storage that matches given condition. The same as in standard Android
61+ * {@link SQLiteOpenHelper}.
62+ *
63+ * @param condition is a string of selection. For example - "time BETWEEN ? AND ?".
64+ * @param args is a string array with data to be inserted in condition string instead of '?'.
65+ * @return list of matched records. List can't be null, but may be zero sized.
66+ */
67+ @ NonNull
68+ List <T > readWithCondition (String condition , String [] args );
69+ }
0 commit comments