1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package fi.vtt.simantics.procore.internal;
\r
14 import org.simantics.db.Resource;
\r
15 import org.simantics.db.Statement;
\r
16 import org.simantics.db.impl.ResourceImpl;
\r
17 import org.simantics.db.procore.protocol.Constants;
\r
20 public abstract class StatementImpl implements Statement {
\r
21 public final static StatementImpl[] NONE = new StatementImpl[0];
\r
22 public final ResourceImpl subject;
\r
23 public final ResourceImpl predicate;
\r
24 protected ResourceImpl object;
\r
25 public StatementImpl(ResourceImpl subject, ResourceImpl predicate) {
\r
26 if (null == subject)
\r
27 throw new IllegalArgumentException();
\r
28 if(null == predicate)
\r
29 throw new IllegalArgumentException();
\r
30 this.subject = (ResourceImpl)subject;
\r
31 this.predicate = (ResourceImpl)predicate;
\r
34 public ResourceImpl getObjectImpl() {
\r
38 public Resource getObject() {
\r
43 final public Resource getPredicate() {
\r
48 final public Resource getSubject() {
\r
53 public boolean isAsserted(Resource testSubject) {
\r
54 return !subject.equals(testSubject);
\r
57 public abstract boolean equals(long s, long p, long o);
\r
61 final class StatementImplOld extends StatementImpl {
\r
63 public StatementImplOld(ResourceImpl subject, ResourceImpl predicate, ResourceImpl object) {
\r
64 super(subject, predicate);
\r
65 this.object = (ResourceImpl)object;
\r
68 public int hashCode() {
\r
69 return subject.hashCode() + (int)object.id;
\r
73 public boolean equals(long s, long p, long o) {
\r
74 return (subject.id == s) && (predicate.id == p) && (object.id == o);
\r
78 public boolean equals(Object obj) {
\r
81 else if (!(obj instanceof StatementImpl))
\r
83 StatementImpl r = (StatementImpl)obj;
\r
84 return r.equals(subject.id, predicate.id, object.id);
\r
88 final class StatementImplNew extends StatementImpl {
\r
89 public final long objectResourceId;
\r
90 public final long objectClusterId;
\r
91 public final GraphSession graphSession;
\r
92 public StatementImplNew(ResourceImpl subject, ResourceImpl predicate, long id, long cluster, GraphSession graphSession) {
\r
93 super(subject, predicate);
\r
95 this.objectResourceId = id;
\r
96 if (Constants.ReservedClusterId == cluster)
\r
97 throw new IllegalArgumentException("Argh!");
\r
98 this.objectClusterId = cluster;
\r
99 this.graphSession = graphSession;
\r
103 final public Resource getObject() {
\r
104 // if (null == object)
\r
106 // object = graphSession.getResourceOrThrow(objectResourceId, objectClusterId);
\r
107 // } catch (ResourceNotFoundException e) {
\r
108 // e.printStackTrace();
\r
112 throw new Error("No can do.");
\r
116 public ResourceImpl getObjectImpl() {
\r
117 // if (null == object)
\r
119 // object = graphSession.getResourceOrThrow(objectResourceId, objectClusterId);
\r
120 // } catch (ResourceNotFoundException e) {
\r
121 // e.printStackTrace();
\r
125 throw new Error("No can do.");
\r
129 public int hashCode() {
\r
130 return subject.hashCode() + (int)objectResourceId;
\r
134 public boolean equals(long s, long p, long o) {
\r
135 return (subject.id == s) && (predicate.id == p) && (objectResourceId == o);
\r
139 public boolean equals(Object obj) {
\r
142 else if (obj == null)
\r
144 else if (StatementImpl.class != obj.getClass())
\r
146 StatementImpl r = (StatementImpl)obj;
\r
147 return r.equals(subject.id, predicate.id, objectResourceId);
\r