Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit 9b76a04

Browse files
author
Evgenii Kanivets
committed
#9[30m]. Add IRepo interface.
1 parent cb1d2f9 commit 9b76a04

File tree

1 file changed

+69
-0
lines changed
  • app/src/main/java/com/blogspot/e_kanivets/moneytracker/repo

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)