]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
ResourceComparator initialization method 17/3617/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 25 Nov 2019 12:36:34 +0000 (14:36 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 25 Nov 2019 12:36:34 +0000 (14:36 +0200)
gitlab #16

Change-Id: I11df4cd5e5ae0f81f3ad929fe6944883b7ed4670

org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java
org.simantics.interop/src/org/simantics/interop/test/NameComparator.java
org.simantics.interop/src/org/simantics/interop/test/ResourceComparator.java

index 8701ebecee88376bd852e5a080844d170d8df6aa..b000c58f191624df7d138a73580c183ad94df34c 100644 (file)
@@ -227,6 +227,14 @@ public class GraphComparator {
                
                comparator.setComparator(this);
                
+               session.syncRequest(new ReadRequest() {
+            
+            @Override
+            public void run(ReadGraph graph) throws DatabaseException {
+                comparator.initialize(graph, r1, r2);
+            }
+        });
+               
                addComparable(r1, r2);
                
                final Stack<Resource> objectsLeft = new Stack<Resource>();
index 125d05912b6d443a7687f8635b9d2023b7759bf0..1467404b2808e9910bbf354c0fcbed10420ce180 100644 (file)
@@ -1,59 +1,58 @@
-package org.simantics.interop.test;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
-import org.simantics.db.exception.ServiceException;\r
-import org.simantics.layer0.Layer0;\r
-\r
-/**\r
- * Object comparator that uses type and name of objects to check if objects are comparable.\r
- * If objects have no name, compare returns unreliable as result.\r
- *  \r
- * \r
- * Difference value is amount of properties that have different values.\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class NameComparator extends TypeComparator {\r
-       \r
-       @Override\r
-       public int compare(ReadGraph g, Resource o1, Resource o2)\r
-                       throws DatabaseException {\r
-               if (!compareType(g,o1, o2)) {\r
-                       return Integer.MAX_VALUE;\r
-               }\r
-               if (hasName(g, o1, o2)) {\r
-                       if(!compareName(g, o1, o2))\r
-                               return Integer.MAX_VALUE;\r
-                       return propsDiffCount(g,o1, o2);\r
-               }\r
-               return 0;\r
-               \r
-       }\r
-       \r
-       protected boolean compareName(ReadGraph g, Resource o1, Resource o2) throws ManyObjectsForFunctionalRelationException, ServiceException {\r
-               Layer0 l0 = Layer0.getInstance(g);\r
-               String n1 = g.getPossibleRelatedValue(o1, l0.HasName);\r
-               String n2 = g.getPossibleRelatedValue(o2, l0.HasName);\r
-               if (n1 != null && n2 != null)\r
-                       return n1.equals(n2);\r
-               if (n1 == null && n2 == null)\r
-                       return true;\r
-               return false;\r
-                       \r
-       }\r
-       \r
-       protected boolean hasName(ReadGraph g, Resource o1, Resource o2) throws ManyObjectsForFunctionalRelationException, ServiceException {\r
-               Layer0 l0 = Layer0.getInstance(g);\r
-               String n1 = g.getPossibleRelatedValue(o1, l0.HasName);\r
-               String n2 = g.getPossibleRelatedValue(o2, l0.HasName);\r
-               if (n1 != null && n2 != null)\r
-                       return true;\r
-               return false;\r
-                       \r
-       }\r
-\r
-}\r
+package org.simantics.interop.test;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+
+/**
+ * Object comparator that uses type and name of objects to check if objects are comparable.
+ * If objects have no name, compare returns unreliable as result.
+ *  
+ * 
+ * Difference value is amount of properties that have different values.
+ * 
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class NameComparator extends TypeComparator {
+       
+       @Override
+       public int compare(ReadGraph g, Resource o1, Resource o2)
+                       throws DatabaseException {
+               if (!compareType(g,o1, o2)) {
+                       return Integer.MAX_VALUE;
+               }
+               if (hasName(g, o1, o2)) {
+                       if(!compareName(g, o1, o2))
+                               return Integer.MAX_VALUE;
+                       return propsDiffCount(g,o1, o2);
+               }
+               return 0;
+               
+       }
+       
+       protected boolean compareName(ReadGraph g, Resource o1, Resource o2) throws DatabaseException {
+               Layer0 l0 = Layer0.getInstance(g);
+               String n1 = g.getPossibleRelatedValue(o1, l0.HasName, Bindings.STRING);
+               String n2 = g.getPossibleRelatedValue(o2, l0.HasName, Bindings.STRING);
+               if (n1 != null && n2 != null)
+                       return n1.equals(n2);
+               if (n1 == null && n2 == null)
+                       return true;
+               return false;
+                       
+       }
+       
+       protected boolean hasName(ReadGraph g, Resource o1, Resource o2) throws DatabaseException {
+               Layer0 l0 = Layer0.getInstance(g);
+               String n1 = g.getPossibleRelatedValue(o1, l0.HasName, Bindings.STRING);
+               String n2 = g.getPossibleRelatedValue(o2, l0.HasName, Bindings.STRING);
+               if (n1 != null && n2 != null)
+                       return true;
+               return false;
+                       
+       }
+
+}
index f65617cb1dac8fe22e76a95173f5616d6ec54c9e..8234998ad546067365c4439bf9c2431c97d5bc4a 100644 (file)
@@ -21,6 +21,16 @@ public abstract class ResourceComparator {
                return comparator;
        }
        
+       /**
+        * Optional initialization method for overriding implementations.
+        * 
+        * @param g
+     * @param r1 root 1
+     * @param r2 root 2
+        */
+       public void initialize(ReadGraph g, Resource r1, Resource r2) throws DatabaseException {
+           
+       }
        
        /**
         * Compares two resources and returns numeric value of differences, minimum value is 1.