+/*******************************************************************************\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.common;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+\r
+public final class StandardStatement implements Statement, Comparable<Statement> {\r
+ \r
+ final private Resource s;\r
+ final private Resource p;\r
+ final private Resource o;\r
+ \r
+ public StandardStatement(final Resource s, final Resource p, final Resource o) {\r
+ this.s = s;\r
+ this.p = p;\r
+ this.o = o;\r
+ }\r
+ \r
+ @Override\r
+ public Resource getObject() {\r
+ return o;\r
+ }\r
+\r
+ @Override\r
+ final public Resource getPredicate() {\r
+ return p;\r
+ }\r
+\r
+ @Override\r
+ final public Resource getSubject() {\r
+ return s;\r
+ }\r
+\r
+ @Override\r
+ public boolean isAsserted(Resource testSubject) {\r
+ return !s.equals(testSubject);\r
+ }\r
+ \r
+ @Override\r
+ final public int hashCode() {\r
+ return 41 * ( 31 * s.hashCode() + p.hashCode()) + o.hashCode();\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.equalsResource(r.getSubject()) && p.equalsResource(r.getPredicate()) && o.equalsResource(r.getObject());\r
+ }\r
+ \r
+ @Override\r
+ public int compareTo(Statement other) {\r
+ Statement impl = (Statement)other; \r
+ int result = s.compareTo(impl.getSubject());\r
+ if(result != 0) return result;\r
+ result = p.compareTo(impl.getPredicate());\r
+ if(result != 0) return result;\r
+ return o.compareTo(impl.getObject());\r
+ }\r
+\r
+}\r
+\r