]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/NewStatementImpl.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / NewStatementImpl.java
diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/NewStatementImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/NewStatementImpl.java
new file mode 100644 (file)
index 0000000..b4ff7c3
--- /dev/null
@@ -0,0 +1,82 @@
+/*******************************************************************************\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 fi.vtt.simantics.procore.internal;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.impl.ResourceImpl;\r
+\r
+public class NewStatementImpl implements Statement {\r
+\r
+    public final ResourceImpl subject;\r
+    public final ResourceImpl predicate;\r
+    public final ResourceImpl object;\r
+    \r
+    public NewStatementImpl(int id, ResourceImpl subject, ResourceImpl predicate, ResourceImpl object) {\r
+        if (null == subject)\r
+            throw new IllegalArgumentException();\r
+        if(null == predicate)\r
+            throw new IllegalArgumentException();\r
+        if(null == predicate)\r
+            throw new IllegalArgumentException();\r
+        this.subject = (ResourceImpl)subject;\r
+        this.predicate = (ResourceImpl)predicate;\r
+        this.object = (ResourceImpl)object;\r
+    }\r
+    @Override\r
+    final public Resource getObject() {\r
+        return object;\r
+    }\r
+\r
+    @Override\r
+    final public Resource getPredicate() {\r
+        return predicate;\r
+    }\r
+\r
+    @Override\r
+    final public Resource getSubject() {\r
+        return subject;\r
+    }\r
+\r
+    public int hashCode()\r
+    {\r
+       // TODO: :)\r
+        int result = 6151 * ((int)(subject.id ^ (subject.id>>>32))*6151 + \r
+        (int)(predicate.id ^ (predicate.id>>>32))) +\r
+        (int)(object.id ^ (object.id>>>32)); \r
+        return result;\r
+        \r
+    }\r
+\r
+    @Override\r
+    public boolean isAsserted(Resource testSubject) {\r
+       return !subject.equals(testSubject);\r
+    }\r
+    \r
+    public boolean equals(Object object)\r
+    {\r
+        if (this == object)\r
+            return true;\r
+        else if (object == null)\r
+            return false;\r
+        try {\r
+            Statement r = (Statement)object;\r
+            return subject.id == r.getSubject().getResourceId() &&\r
+            predicate.id == r.getPredicate().getResourceId() &&\r
+            this.object.id == r.getObject().getResourceId();\r
+        } catch (ClassCastException e) {\r
+            return false;\r
+        }\r
+    }\r
+    \r
+    \r
+}\r