]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/binaryPredicates/CompositePredicate.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.layer0.utils / src / org / simantics / layer0 / utils / binaryPredicates / CompositePredicate.java
index 88000f680cb630e581d2ca9aaad3a8d5f3b044a9..1d67c7d1eed9800be8526d8ddf9d49d93b8b6a5a 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 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.layer0.utils.binaryPredicates;\r
-\r
-import java.util.Collection;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.utils.datastructures.Pair;\r
-\r
-public class CompositePredicate extends BinaryPredicate {\r
-       IBinaryPredicate first;\r
-       IBinaryPredicate second;\r
-       \r
-       int hasStatementDirection;\r
-       int getStatementsDirection;\r
-       \r
-       public CompositePredicate(IBinaryPredicate first, IBinaryPredicate second) {\r
-               this.first = first;\r
-               this.second = second;           \r
-               if(first.supportsGetStatements() && second.supportsGetObjects())\r
-                       getStatementsDirection = 1;\r
-               else if(second.supportsGetStatements() && first.supportsGetSubjects())\r
-                       getStatementsDirection = 2;\r
-               else\r
-                       this.getStatementsDirection = 0;\r
-               if(first.supportsGetObjects())\r
-                       hasStatementDirection = 1;\r
-               else if(second.supportsGetSubjects())\r
-                       hasStatementDirection = 2;\r
-               else\r
-                       throw new IllegalArgumentException("Cannot compose binary predicates such that the first one does not support getObjects and the second one does not support getSubjects.");\r
-       }\r
-\r
-       @Override\r
-       public Collection<Resource> getObjects(ReadGraph g, Resource subject) throws DatabaseException {\r
-               Set<Resource> result = new HashSet<Resource>();\r
-               for(Resource r : first.getObjects(g, subject))\r
-                       result.addAll(second.getObjects(g, r));\r
-               return result;\r
-       }\r
-\r
-       @Override\r
-       public Collection<Pair<Resource, Resource>> getStatements(ReadGraph g) throws DatabaseException {\r
-               Set<Pair<Resource, Resource>> result = \r
-                       new HashSet<Pair<Resource, Resource>>();\r
-               if(getStatementsDirection == 1)\r
-                       for(Pair<Resource, Resource> p : first.getStatements(g))\r
-                               for(Resource r : second.getObjects(g, p.second))\r
-                                       result.add(new Pair<Resource, Resource>(p.first, r));\r
-               else if(getStatementsDirection == 2)\r
-                       for(Pair<Resource, Resource> p : second.getStatements(g))\r
-                               for(Resource r : second.getSubjects(g, p.first))\r
-                                       result.add(new Pair<Resource, Resource>(r, p.second));\r
-               else\r
-                       throw new UnsupportedOperationException();\r
-               return result;\r
-       }\r
-\r
-       @Override\r
-       public Collection<Resource> getSubjects(ReadGraph g, Resource object) throws DatabaseException {\r
-               Set<Resource> result = new HashSet<Resource>();\r
-               for(Resource r : second.getSubjects(g, object))\r
-                       result.addAll(first.getSubjects(g, r));\r
-               return result;\r
-       }\r
-\r
-       @Override\r
-       public boolean has(ReadGraph g, Resource subject, Resource object) throws DatabaseException {\r
-               if(hasStatementDirection == 1) {\r
-                       for(Resource r : first.getObjects(g, subject))\r
-                               if(second.has(g, r, object))\r
-                                       return true;\r
-               }\r
-               else {\r
-                       for(Resource r : second.getSubjects(g, object))\r
-                               if(second.has(g, subject, r))\r
-                                       return true;\r
-               }\r
-               return false;\r
-       }\r
-\r
-       @Override\r
-       public void add(WriteGraph g, Resource subject, Resource object) {\r
-               throw new UnsupportedOperationException();\r
-       }\r
-\r
-       @Override\r
-       public void remove(WriteGraph g, Resource subject, Resource object) {\r
-               throw new UnsupportedOperationException();\r
-       }\r
-\r
-       @Override\r
-       public boolean supportsAdditions() {\r
-               return false;\r
-       }\r
-\r
-       @Override\r
-       public boolean supportsGetObjects() {\r
-               return first.supportsGetObjects() && second.supportsGetObjects();\r
-       }\r
-\r
-       @Override\r
-       public boolean supportsGetStatements() {\r
-               return getStatementsDirection != 0;\r
-       }\r
-\r
-       @Override\r
-       public boolean supportsGetSubjects() {\r
-               return first.supportsGetSubjects() && second.supportsGetSubjects();\r
-       }\r
-\r
-       @Override\r
-       public boolean supportsRemovals() {             \r
-               return false;\r
-       }\r
-\r
-       @Override\r
-       public int hashCode() {\r
-               final int prime = 31;\r
-               int result = 1;\r
-               result = prime * result + ((first == null) ? 0 : first.hashCode());\r
-               result = prime * result + ((second == null) ? 0 : second.hashCode());\r
-               return result;\r
-       }\r
-\r
-       @Override\r
-       public boolean equals(Object obj) {\r
-               if (this == obj)\r
-                       return true;\r
-               if (obj == null)\r
-                       return false;\r
-               if (getClass() != obj.getClass())\r
-                       return false;\r
-               CompositePredicate other = (CompositePredicate) obj;\r
-               if (first == null) {\r
-                       if (other.first != null)\r
-                               return false;\r
-               } else if (!first.equals(other.first))\r
-                       return false;\r
-               if (second == null) {\r
-                       if (other.second != null)\r
-                               return false;\r
-               } else if (!second.equals(other.second))\r
-                       return false;\r
-               return true;\r
-       }       \r
-       \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 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.layer0.utils.binaryPredicates;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.simantics.db.Resource;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.utils.datastructures.Pair;
+
+public class CompositePredicate extends BinaryPredicate {
+       IBinaryPredicate first;
+       IBinaryPredicate second;
+       
+       int hasStatementDirection;
+       int getStatementsDirection;
+       
+       public CompositePredicate(IBinaryPredicate first, IBinaryPredicate second) {
+               this.first = first;
+               this.second = second;           
+               if(first.supportsGetStatements() && second.supportsGetObjects())
+                       getStatementsDirection = 1;
+               else if(second.supportsGetStatements() && first.supportsGetSubjects())
+                       getStatementsDirection = 2;
+               else
+                       this.getStatementsDirection = 0;
+               if(first.supportsGetObjects())
+                       hasStatementDirection = 1;
+               else if(second.supportsGetSubjects())
+                       hasStatementDirection = 2;
+               else
+                       throw new IllegalArgumentException("Cannot compose binary predicates such that the first one does not support getObjects and the second one does not support getSubjects.");
+       }
+
+       @Override
+       public Collection<Resource> getObjects(ReadGraph g, Resource subject) throws DatabaseException {
+               Set<Resource> result = new HashSet<Resource>();
+               for(Resource r : first.getObjects(g, subject))
+                       result.addAll(second.getObjects(g, r));
+               return result;
+       }
+
+       @Override
+       public Collection<Pair<Resource, Resource>> getStatements(ReadGraph g) throws DatabaseException {
+               Set<Pair<Resource, Resource>> result = 
+                       new HashSet<Pair<Resource, Resource>>();
+               if(getStatementsDirection == 1)
+                       for(Pair<Resource, Resource> p : first.getStatements(g))
+                               for(Resource r : second.getObjects(g, p.second))
+                                       result.add(new Pair<Resource, Resource>(p.first, r));
+               else if(getStatementsDirection == 2)
+                       for(Pair<Resource, Resource> p : second.getStatements(g))
+                               for(Resource r : second.getSubjects(g, p.first))
+                                       result.add(new Pair<Resource, Resource>(r, p.second));
+               else
+                       throw new UnsupportedOperationException();
+               return result;
+       }
+
+       @Override
+       public Collection<Resource> getSubjects(ReadGraph g, Resource object) throws DatabaseException {
+               Set<Resource> result = new HashSet<Resource>();
+               for(Resource r : second.getSubjects(g, object))
+                       result.addAll(first.getSubjects(g, r));
+               return result;
+       }
+
+       @Override
+       public boolean has(ReadGraph g, Resource subject, Resource object) throws DatabaseException {
+               if(hasStatementDirection == 1) {
+                       for(Resource r : first.getObjects(g, subject))
+                               if(second.has(g, r, object))
+                                       return true;
+               }
+               else {
+                       for(Resource r : second.getSubjects(g, object))
+                               if(second.has(g, subject, r))
+                                       return true;
+               }
+               return false;
+       }
+
+       @Override
+       public void add(WriteGraph g, Resource subject, Resource object) {
+               throw new UnsupportedOperationException();
+       }
+
+       @Override
+       public void remove(WriteGraph g, Resource subject, Resource object) {
+               throw new UnsupportedOperationException();
+       }
+
+       @Override
+       public boolean supportsAdditions() {
+               return false;
+       }
+
+       @Override
+       public boolean supportsGetObjects() {
+               return first.supportsGetObjects() && second.supportsGetObjects();
+       }
+
+       @Override
+       public boolean supportsGetStatements() {
+               return getStatementsDirection != 0;
+       }
+
+       @Override
+       public boolean supportsGetSubjects() {
+               return first.supportsGetSubjects() && second.supportsGetSubjects();
+       }
+
+       @Override
+       public boolean supportsRemovals() {             
+               return false;
+       }
+
+       @Override
+       public int hashCode() {
+               final int prime = 31;
+               int result = 1;
+               result = prime * result + ((first == null) ? 0 : first.hashCode());
+               result = prime * result + ((second == null) ? 0 : second.hashCode());
+               return result;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (this == obj)
+                       return true;
+               if (obj == null)
+                       return false;
+               if (getClass() != obj.getClass())
+                       return false;
+               CompositePredicate other = (CompositePredicate) obj;
+               if (first == null) {
+                       if (other.first != null)
+                               return false;
+               } else if (!first.equals(other.first))
+                       return false;
+               if (second == null) {
+                       if (other.second != null)
+                               return false;
+               } else if (!second.equals(other.second))
+                       return false;
+               return true;
+       }       
+       
+}