1 package org.simantics.interop.update.model;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.HashSet;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.Statement;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.interop.test.GraphChanges;
13 import org.simantics.utils.datastructures.Pair;
15 public class UpdateList {
16 private HashSet<PropertyChange> changes;
19 changes = new HashSet<>();
22 public UpdateList(Collection<PropertyChange> changes) {
23 this.changes = new HashSet<>(changes);
26 public UpdateList(GraphChanges graphChanges, Collection<Pair<Statement, Statement>> coll) {
27 this.changes = new HashSet<>();
28 for (Pair<Statement, Statement> p : coll) {
29 changes.add(create(graphChanges, p));
33 protected PropertyChange create(GraphChanges changes, Pair<Statement, Statement> change) {
34 return new PropertyChange(changes, change);
37 public Collection<PropertyChange> getChanges() {
41 public void addChange(PropertyChange change) {
45 public void removeChange(PropertyChange change) {
46 changes.remove(change);
49 public Collection<PropertyChange> getSelected() {
50 HashSet<PropertyChange> selected = new HashSet<>();
51 for (PropertyChange c : selected) {
58 public void clearSelected() {
59 for (PropertyChange c : changes)
63 public PropertyChange getChange(ReadGraph g, Statement s) throws DatabaseException {
64 for (PropertyChange c : changes) {
65 if (s.equals(c.pair.first))
67 if (s.equals(c.pair.second))
73 public Collection<PropertyChange> getChanges(ReadGraph g, Resource r) throws DatabaseException{
74 List<PropertyChange> list = new ArrayList<>();
75 for (PropertyChange pair : changes) {
76 if (pair.getFirst() != null) {
77 if (pair.getFirst().getSubject().equals(r)) {
81 if (pair.getFirst().getObject().equals(r)) {
86 if (pair.getSecond() != null) {
87 if (pair.getSecond().getSubject().equals(r)) {
91 if (pair.getSecond().getObject().equals(r)) {