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.interop.update.model.ModelUpdate.ChangeFilter;
14 import org.simantics.utils.datastructures.Pair;
16 public class UpdateList {
17 private HashSet<PropertyChange> changes;
20 changes = new HashSet<>();
23 public UpdateList(Collection<PropertyChange> changes) {
24 this.changes = new HashSet<>(changes);
27 public UpdateList(GraphChanges graphChanges, Collection<Pair<Statement, Statement>> coll) {
28 this.changes = new HashSet<>();
29 for (Pair<Statement, Statement> p : coll) {
30 changes.add(create(graphChanges, p));
34 protected PropertyChange create(GraphChanges changes, Pair<Statement, Statement> change) {
35 return new PropertyChange(changes, change);
38 public Collection<PropertyChange> getChanges() {
42 public void addChange(PropertyChange change) {
46 public void removeChange(PropertyChange change) {
47 changes.remove(change);
50 public Collection<PropertyChange> getSelected() {
51 HashSet<PropertyChange> selected = new HashSet<>();
52 for (PropertyChange c : selected) {
59 public void clearSelected() {
60 for (PropertyChange c : changes)
64 public PropertyChange getChange(ReadGraph g, Statement s) throws DatabaseException {
65 for (PropertyChange c : changes) {
66 if (s.equals(c.pair.first))
68 if (s.equals(c.pair.second))
74 public Collection<PropertyChange> getChanges(ReadGraph g, Resource r) throws DatabaseException{
75 List<PropertyChange> list = new ArrayList<>();
76 for (PropertyChange pair : changes) {
77 if (pair.getFirst() != null) {
78 if (pair.getFirst().getSubject().equals(r)) {
82 if (pair.getFirst().getObject().equals(r)) {
87 if (pair.getSecond() != null) {
88 if (pair.getSecond().getSubject().equals(r)) {
92 if (pair.getSecond().getObject().equals(r)) {