Package: UnitOfWorkChangeSetImpl
UnitOfWorkChangeSetImpl
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
UnitOfWorkChangeSetImpl() |
|
|
|
|
|
||||||||||||||||||||
addDeletedObjectChangeSet(ObjectChangeSet) |
|
|
|
|
|
||||||||||||||||||||
addNewObjectChangeSet(ObjectChangeSet) |
|
|
|
|
|
||||||||||||||||||||
addObjectChangeSet(ObjectChangeSet) |
|
|
|
|
|
||||||||||||||||||||
cancelObjectChanges(Object) |
|
|
|
|
|
||||||||||||||||||||
getDeletedObjects() |
|
|
|
|
|
||||||||||||||||||||
getExistingObjectChanges(Object) |
|
|
|
|
|
||||||||||||||||||||
getExistingObjectsChanges() |
|
|
|
|
|
||||||||||||||||||||
getNewObjects() |
|
|
|
|
|
||||||||||||||||||||
hasChanges() |
|
|
|
|
|
||||||||||||||||||||
hasDeleted() |
|
|
|
|
|
||||||||||||||||||||
hasNew() |
|
|
|
|
|
Coverage
1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.sessions.change;
16:
17: import cz.cvut.kbss.jopa.sessions.ObjectChangeSet;
18: import cz.cvut.kbss.jopa.sessions.UnitOfWorkChangeSet;
19:
20: import java.util.*;
21:
22: public class UnitOfWorkChangeSetImpl implements UnitOfWorkChangeSet {
23:
24: private final Set<ObjectChangeSet> deletedObjects;
25: private final Map<Object, ObjectChangeSet> objectChanges;
26: private final Set<ObjectChangeSet> newObjectChanges;
27:
28: public UnitOfWorkChangeSetImpl() {
29: this.objectChanges = new HashMap<>();
30: this.deletedObjects = new HashSet<>();
31: this.newObjectChanges = new HashSet<>();
32: }
33:
34: @Override
35: public void addObjectChangeSet(ObjectChangeSet objectChangeSet) {
36:• if (objectChangeSet.isNew()) {
37: addNewObjectChangeSet(objectChangeSet);
38: } else {
39: objectChanges.put(objectChangeSet.getChangedObject(), objectChangeSet);
40: }
41: }
42:
43: @Override
44: public void addDeletedObjectChangeSet(ObjectChangeSet deletedObject) {
45: deletedObjects.add(deletedObject);
46: }
47:
48: @Override
49: public void addNewObjectChangeSet(ObjectChangeSet newObject) {
50: newObject.setNew(true);
51: newObjectChanges.add(newObject);
52: }
53:
54: @Override
55: public Collection<ObjectChangeSet> getExistingObjectsChanges() {
56: return Collections.unmodifiableCollection(objectChanges.values());
57: }
58:
59: @Override
60: public void cancelObjectChanges(Object original) {
61: objectChanges.remove(original);
62: }
63:
64: @Override
65: public ObjectChangeSet getExistingObjectChanges(Object original) {
66: return objectChanges.get(original);
67: }
68:
69: @Override
70: public Set<ObjectChangeSet> getDeletedObjects() {
71: return this.deletedObjects;
72: }
73:
74: @Override
75: public Set<ObjectChangeSet> getNewObjects() {
76: return this.newObjectChanges;
77: }
78:
79: @Override
80: public boolean hasDeleted() {
81:• return !deletedObjects.isEmpty();
82: }
83:
84: @Override
85: public boolean hasChanges() {
86:• return hasDeleted() || hasNew() || !objectChanges.isEmpty();
87: }
88:
89: @Override
90: public boolean hasNew() {
91:• return !this.newObjectChanges.isEmpty();
92: }
93: }