--- /dev/null
+/*******************************************************************************\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