]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java
Handle asserted property statements
[simantics/interop.git] / org.simantics.interop / src / org / simantics / interop / test / GraphChanges.java
index b25eea87d49795573a2f26e2f33566d66fdd3f53..48f43596fe0ce69cd82f85af2a917f31f8b7a247 100644 (file)
@@ -9,7 +9,6 @@ import org.simantics.db.Statement;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.utils.datastructures.BijectionMap;
-import org.simantics.utils.datastructures.Pair;
 
 public class GraphChanges {
        
@@ -17,12 +16,104 @@ public class GraphChanges {
        private Resource r2;
        private List<Statement> deletions;
        private List<Statement> additions;
-       private List<Pair<Statement,Statement>> modifications;
+       private List<Modification> modifications;
        
        private BijectionMap<Resource, Resource> comparable;
        
+       public static class Modification {
+               Resource leftSub;
+               Resource rightSub;
+               Statement leftStm;
+               Statement rightStm;
+
+               
+               int hashCode;
+               
+               public Modification(Resource leftSub, Resource rightSub, Statement leftStm, Statement rightStm) {
+                       super();
+                       this.leftSub = leftSub;
+                       this.rightSub = rightSub;
+                       this.leftStm = leftStm;
+                       this.rightStm = rightStm;
+                       
+                       hashCode = leftSub.hashCode() + rightSub.hashCode();
+                       if (leftStm != null)
+                               hashCode += leftStm.hashCode();
+                       if (rightStm != null)
+                               hashCode += rightStm.hashCode();
+               }
+
+               public boolean isLeftAsserted() {
+                       return !leftSub.equals(leftStm.getSubject());
+               }
+               
+               public boolean isRightAsserted() {
+                       return !rightSub.equals(rightStm.getSubject());
+               }
+
+               public Resource getLeftSub() {
+                       return leftSub;
+               }
+
+               public void setLeftSub(Resource leftSub) {
+                       this.leftSub = leftSub;
+               }
+
+               public Resource getRightSub() {
+                       return rightSub;
+               }
+
+               public void setRightSub(Resource rightSub) {
+                       this.rightSub = rightSub;
+               }
+
+               public Statement getLeftStm() {
+                       return leftStm;
+               }
+
+               public void setLeftStm(Statement leftStm) {
+                       this.leftStm = leftStm;
+               }
+
+               public Statement getRightStm() {
+                       return rightStm;
+               }
+
+               public void setRightStm(Statement rightStm) {
+                       this.rightStm = rightStm;
+               }
+               
+               @Override
+               public boolean equals(Object obj) {
+                       if (obj.getClass() != this.getClass())
+                               return false;
+                       Modification other = (Modification)obj;
+                       if (!leftSub.equals(other.leftSub))
+                               return false;
+                       if (!rightSub.equals(other.rightSub))
+                               return false;
+                       if (leftStm != null) {
+                               if (!leftStm.equals(other.leftStm))
+                                       return false;
+                       } else if (other.leftStm != null)
+                               return false;
+                       if (rightStm != null) {
+                               if (!rightStm.equals(other.rightStm))
+                                       return false;
+                       } else if (other.rightStm != null)
+                               return false;
+                       return true;
+               }
+               
+               @Override
+               public int hashCode() {
+                       return hashCode;
+               }
+
+       }
+       
        public GraphChanges(Resource r1, Resource r2, List<Statement> deletions, List<Statement> additions,
-                       List<Pair<Statement, Statement>> modifications, BijectionMap<Resource, Resource> comparable) {
+                       List<Modification> modifications, BijectionMap<Resource, Resource> comparable) {
                super();
                this.r1 = r1;
                this.r2 = r2;
@@ -48,7 +139,7 @@ public class GraphChanges {
                return deletions;
        }
        
-       public List<Pair<Statement, Statement>> getModifications() {
+       public List<Modification> getModifications() {
                return modifications;
        }
        
@@ -73,17 +164,17 @@ public class GraphChanges {
                                   stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
        }
                sb.append("Mod:\n");
-               for (Pair<Statement, Statement> mod :modifications) {
+               for (Modification mod :modifications) {
                        {
-                               Statement stm = mod.first;
-                               sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+
+                               Statement stm = mod.getLeftStm();
+                               sb.append(NameUtils.getSafeName(graph, mod.getLeftSub()) + " "+
                                                   NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
                                           NameUtils.getSafeName(graph, stm.getObject()) + " (" +
                                           stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
                        }
                        {
-                               Statement stm = mod.second;
-                               sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+
+                               Statement stm = mod.getRightStm();
+                               sb.append(NameUtils.getSafeName(graph, mod.getRightSub()) + " "+
                                                   NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
                                           NameUtils.getSafeName(graph, stm.getObject()) + " (" +
                                           stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");