-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
SaveRequest.kt
57 lines (44 loc) · 1.6 KB
/
SaveRequest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.alexstyl.contactstore
import com.alexstyl.contactstore.ContactOperation.Delete
import com.alexstyl.contactstore.ContactOperation.Insert
import com.alexstyl.contactstore.ContactOperation.Update
/**
* A [SaveRequest] is responsible of keeping track of any contact modifications you want to perform.
*
* @see [ContactStore.execute]
*/
class SaveRequest {
private val _requests = mutableListOf<ContactOperation>()
val requests: List<ContactOperation>
get() = _requests.toList()
/**
* Updates an existing contact. The passing [MutableContact] must have a valid contactId.
*
* Only the values contained in the contacts' [MutableContact.columns], will be updated.
* Use [ContactStore.fetchContacts] passing the columns you need to update, in order to get a contact with the respective columns.
*
* This is done to prevent accidental value overrides.
*/
fun update(mutableContact: MutableContact) {
_requests.add(Update(mutableContact))
}
fun insert(mutableContact: MutableContact) {
_requests.add(Insert(mutableContact))
}
fun delete(contactId: Long) {
_requests.add(Delete(contactId))
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as SaveRequest
if (_requests != other._requests) return false
return true
}
override fun hashCode(): Int {
return _requests.hashCode()
}
override fun toString(): String {
return "SaveRequest(_requests=$_requests)"
}
}