]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/StatementImpl.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / StatementImpl.java
diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/StatementImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/StatementImpl.java
new file mode 100644 (file)
index 0000000..29ba609
--- /dev/null
@@ -0,0 +1,149 @@
+/*******************************************************************************\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
+import org.simantics.db.procore.protocol.Constants;\r
+\r
+\r
+public abstract class StatementImpl implements Statement {\r
+    public final static StatementImpl[] NONE = new StatementImpl[0];\r
+    public final ResourceImpl subject;\r
+    public final ResourceImpl predicate;\r
+    protected ResourceImpl object;\r
+    public StatementImpl(ResourceImpl subject, ResourceImpl predicate) {\r
+        if (null == subject)\r
+            throw new IllegalArgumentException();\r
+        if(null == predicate)\r
+            throw new IllegalArgumentException();\r
+        this.subject = (ResourceImpl)subject;\r
+        this.predicate = (ResourceImpl)predicate;\r
+    }\r
+    \r
+    public ResourceImpl getObjectImpl() {\r
+        return object;\r
+    }\r
+    @Override\r
+    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
+    @Override\r
+    public boolean isAsserted(Resource testSubject) {\r
+       return !subject.equals(testSubject);\r
+    }\r
+    \r
+    public abstract boolean equals(long s, long p, long o);\r
+    \r
+  }\r
+\r
+final class StatementImplOld extends StatementImpl {\r
+    \r
+    public StatementImplOld(ResourceImpl subject, ResourceImpl predicate, ResourceImpl object) {\r
+        super(subject, predicate);\r
+        this.object = (ResourceImpl)object;\r
+    }\r
+    @Override\r
+    public int hashCode() {\r
+        return subject.hashCode() + (int)object.id; \r
+    }\r
+\r
+    @Override\r
+    public boolean equals(long s, long p, long o) {\r
+        return (subject.id == s) && (predicate.id == p) && (object.id == o);\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (this == obj)\r
+            return true;\r
+        else if (!(obj instanceof StatementImpl))\r
+            return false;\r
+        StatementImpl r = (StatementImpl)obj;\r
+        return r.equals(subject.id, predicate.id, object.id);\r
+    }\r
+}\r
+\r
+final class StatementImplNew extends StatementImpl {\r
+    public final long objectResourceId;\r
+    public final long objectClusterId;\r
+    public final GraphSession graphSession;\r
+    public StatementImplNew(ResourceImpl subject, ResourceImpl predicate, long id, long cluster, GraphSession graphSession) {\r
+        super(subject, predicate);\r
+        this.object = null;\r
+        this.objectResourceId = id;\r
+        if (Constants.ReservedClusterId == cluster)\r
+            throw new IllegalArgumentException("Argh!");\r
+        this.objectClusterId = cluster;\r
+        this.graphSession = graphSession;\r
+    }\r
+\r
+    @Override\r
+    final public Resource getObject() {\r
+//        if (null == object)\r
+//            try {\r
+//                object = graphSession.getResourceOrThrow(objectResourceId, objectClusterId);\r
+//            } catch (ResourceNotFoundException e) {\r
+//                e.printStackTrace();\r
+//                return null;\r
+//            }\r
+//        return object;\r
+       throw new Error("No can do.");\r
+    }\r
+\r
+    @Override\r
+    public ResourceImpl getObjectImpl() {\r
+//        if (null == object)\r
+//            try {\r
+//                object = graphSession.getResourceOrThrow(objectResourceId, objectClusterId);\r
+//            } catch (ResourceNotFoundException e) {\r
+//                e.printStackTrace();\r
+//                return null;\r
+//            }\r
+//        return object;\r
+       throw new Error("No can do.");\r
+    }\r
+\r
+    @Override\r
+    public int hashCode() {\r
+        return subject.hashCode() + (int)objectResourceId; \r
+    }\r
+\r
+    @Override\r
+    public boolean equals(long s, long p, long o) {\r
+        return (subject.id == s) && (predicate.id == p) && (objectResourceId == o);\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (this == obj)\r
+            return true;\r
+        else if (obj == null)\r
+            return false;\r
+        else if (StatementImpl.class != obj.getClass())\r
+            return false;\r
+        StatementImpl r = (StatementImpl)obj;\r
+        return r.equals(subject.id, predicate.id, objectResourceId);\r
+    }\r
+}\r