-/*******************************************************************************\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.db.impl.graph;\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.impl.support.ResourceSupport;\r
-\r
-public final class InternalStatement implements Statement, Comparable<Statement> {\r
- \r
- final ResourceSupport support;\r
- final int s;\r
- final int p;\r
- final int o;\r
- \r
- public InternalStatement(ResourceSupport support, final int s, final int p, final int o) {\r
- this.support = support;\r
- this.s = s;\r
- this.p = p;\r
- this.o = o;\r
- }\r
- \r
- @Override\r
- public Resource getSubject() {\r
- return new ResourceImpl(support, s);\r
- }\r
-\r
- @Override\r
- public Resource getPredicate() {\r
- return new ResourceImpl(support, p);\r
- }\r
-\r
- @Override\r
- public Resource getObject() {\r
- return new ResourceImpl(support, o);\r
- }\r
-\r
- @Override\r
- public boolean isAsserted(Resource subject) {\r
- return ((ResourceImpl)subject).id != s;\r
- }\r
- \r
- @Override\r
- final public int hashCode() {\r
- return 41 * ( 31 * s + p) + o;\r
- }\r
-\r
- final private int id(Resource r) {\r
- return ((ResourceImpl)r).id;\r
- }\r
- \r
- @Override\r
- public boolean equals(Object object) {\r
- if (this == object)\r
- return true;\r
- else if (object == null)\r
- return false;\r
- else if (!(object instanceof Statement))\r
- return false;\r
- Statement r = (Statement)object;\r
- return s == id(r.getSubject()) && p == id(r.getPredicate()) && o== id(r.getObject());\r
- }\r
- \r
- @Override\r
- public int compareTo(Statement other) {\r
- int result = compare(s,id(other.getSubject()));\r
- if(result != 0) return result;\r
- result = compare(p,id(other.getPredicate()));\r
- if(result != 0) return result;\r
- return compare(o,id(other.getObject()));\r
- }\r
-\r
- private int compare(int x, int y) {\r
- return (x < y) ? -1 : ((x == y) ? 0 : 1);\r
- }\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.db.impl.graph;
+
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.impl.ResourceImpl;
+import org.simantics.db.impl.support.ResourceSupport;
+
+public final class InternalStatement implements Statement, Comparable<Statement> {
+
+ final ResourceSupport support;
+ final int s;
+ final int p;
+ final int o;
+
+ public InternalStatement(ResourceSupport support, final int s, final int p, final int o) {
+ this.support = support;
+ this.s = s;
+ this.p = p;
+ this.o = o;
+ }
+
+ @Override
+ public Resource getSubject() {
+ return new ResourceImpl(support, s);
+ }
+
+ @Override
+ public Resource getPredicate() {
+ return new ResourceImpl(support, p);
+ }
+
+ @Override
+ public Resource getObject() {
+ return new ResourceImpl(support, o);
+ }
+
+ @Override
+ public boolean isAsserted(Resource subject) {
+ return ((ResourceImpl)subject).id != s;
+ }
+
+ @Override
+ final public int hashCode() {
+ return 41 * ( 31 * s + p) + o;
+ }
+
+ final private int id(Resource r) {
+ return ((ResourceImpl)r).id;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (this == object)
+ return true;
+ else if (object == null)
+ return false;
+ else if (!(object instanceof Statement))
+ return false;
+ Statement r = (Statement)object;
+ return s == id(r.getSubject()) && p == id(r.getPredicate()) && o== id(r.getObject());
+ }
+
+ @Override
+ public int compareTo(Statement other) {
+ int result = compare(s,id(other.getSubject()));
+ if(result != 0) return result;
+ result = compare(p,id(other.getPredicate()));
+ if(result != 0) return result;
+ return compare(o,id(other.getObject()));
+ }
+
+ private int compare(int x, int y) {
+ return (x < y) ? -1 : ((x == y) ? 0 : 1);
+ }
+
+}
+