]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/MappingUtils.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / graph / rules / domain / MappingUtils.java
index 5e97f852dea2a17f79596a90580b927074de5117..a0d0d4dac2df176cc881fb9759f4173a911a1db1 100644 (file)
@@ -1,92 +1,92 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2013 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.objmap.graph.rules.domain;\r
-\r
-import java.util.Arrays;\r
-import java.util.Collection;\r
-\r
-import org.apache.log4j.Logger;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-\r
-/**\r
- * Static utility methods for rule implementations.\r
- * @author Hannu Niemistö\r
- */\r
-public class MappingUtils {\r
-\r
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");\r
-    \r
-    /**\r
-     * Adds and removes statements to/from the database so that <code>objects</code>\r
-     * will be exactly the objects connected to <code>subject</code> by <code>predicate</code>.\r
-     * Returns true if the method made modifications to the database.\r
-     */\r
-       public static boolean synchronizeStatements(WriteGraph g, Resource subject, Resource predicate, Resource[] objects,\r
-               boolean deleteExtraObjects) \r
-               throws DatabaseException {\r
-               Collection<Resource> currentObjects0 = g.getObjects(subject, predicate);\r
-               Resource[] currentObjects = currentObjects0.toArray(new Resource[currentObjects0.size()]);\r
-               \r
-               Arrays.sort(objects);\r
-               Arrays.sort(currentObjects);\r
-               \r
-               boolean modified = false;\r
-               int i=0, j=0;   \r
-               if(currentObjects.length > 0 && objects.length > 0)\r
-               while(true) {\r
-                       int cmp = currentObjects[i].compareTo(objects[j]);\r
-                       if(cmp < 0) {\r
-                           LOGGER.info("            remove statement");\r
-                           if(deleteExtraObjects)\r
-                               g.deny(currentObjects[i]);\r
-                           else\r
-                               g.denyStatement(subject, predicate, currentObjects[i]);                                 \r
-                               modified = true;\r
-                               ++i;\r
-                               if(i >= currentObjects.length)\r
-                                       break;\r
-                       }\r
-                       else if(cmp > 0) {\r
-                           LOGGER.info("            add statement");\r
-                               g.claim(subject, predicate, objects[j]);\r
-                               modified = true;\r
-                               ++j;\r
-                               if(j >= objects.length)\r
-                                       break;\r
-                       }\r
-                       else {\r
-                               ++i; ++j;\r
-                               if(i >= currentObjects.length)\r
-                                       break;\r
-                               if(j >= objects.length)\r
-                                       break;\r
-                       }\r
-               }\r
-               while(i < currentObjects.length) {\r
-                   if(deleteExtraObjects)\r
-                g.deny(currentObjects[i]);\r
-            else\r
-                g.denyStatement(subject, predicate, currentObjects[i]);\r
-                       modified = true;\r
-                       ++i;\r
-               }\r
-               while(j < objects.length) {\r
-                       g.claim(subject, predicate, objects[j]);\r
-                       modified = true;\r
-                       ++j;\r
-               }\r
-               return modified;\r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2013 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.objmap.graph.rules.domain;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+
+/**
+ * Static utility methods for rule implementations.
+ * @author Hannu Niemistö
+ */
+public class MappingUtils {
+
+    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
+    
+    /**
+     * Adds and removes statements to/from the database so that <code>objects</code>
+     * will be exactly the objects connected to <code>subject</code> by <code>predicate</code>.
+     * Returns true if the method made modifications to the database.
+     */
+       public static boolean synchronizeStatements(WriteGraph g, Resource subject, Resource predicate, Resource[] objects,
+               boolean deleteExtraObjects) 
+               throws DatabaseException {
+               Collection<Resource> currentObjects0 = g.getObjects(subject, predicate);
+               Resource[] currentObjects = currentObjects0.toArray(new Resource[currentObjects0.size()]);
+               
+               Arrays.sort(objects);
+               Arrays.sort(currentObjects);
+               
+               boolean modified = false;
+               int i=0, j=0;   
+               if(currentObjects.length > 0 && objects.length > 0)
+               while(true) {
+                       int cmp = currentObjects[i].compareTo(objects[j]);
+                       if(cmp < 0) {
+                           LOGGER.info("            remove statement");
+                           if(deleteExtraObjects)
+                               g.deny(currentObjects[i]);
+                           else
+                               g.denyStatement(subject, predicate, currentObjects[i]);                                 
+                               modified = true;
+                               ++i;
+                               if(i >= currentObjects.length)
+                                       break;
+                       }
+                       else if(cmp > 0) {
+                           LOGGER.info("            add statement");
+                               g.claim(subject, predicate, objects[j]);
+                               modified = true;
+                               ++j;
+                               if(j >= objects.length)
+                                       break;
+                       }
+                       else {
+                               ++i; ++j;
+                               if(i >= currentObjects.length)
+                                       break;
+                               if(j >= objects.length)
+                                       break;
+                       }
+               }
+               while(i < currentObjects.length) {
+                   if(deleteExtraObjects)
+                g.deny(currentObjects[i]);
+            else
+                g.denyStatement(subject, predicate, currentObjects[i]);
+                       modified = true;
+                       ++i;
+               }
+               while(j < objects.length) {
+                       g.claim(subject, predicate, objects[j]);
+                       modified = true;
+                       ++j;
+               }
+               return modified;
+       }
+
+}