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 org.simantics.db.common;
\r
14 import org.simantics.db.Resource;
\r
15 import org.simantics.db.Statement;
\r
17 public final class StandardStatement implements Statement, Comparable<Statement> {
\r
19 final private Resource s;
\r
20 final private Resource p;
\r
21 final private Resource o;
\r
23 public StandardStatement(final Resource s, final Resource p, final Resource o) {
\r
30 public Resource getObject() {
\r
35 final public Resource getPredicate() {
\r
40 final public Resource getSubject() {
\r
45 public boolean isAsserted(Resource testSubject) {
\r
46 return !s.equals(testSubject);
\r
50 final public int hashCode() {
\r
51 return 41 * ( 31 * s.hashCode() + p.hashCode()) + o.hashCode();
\r
55 public boolean equals(Object object) {
\r
58 else if (object == null)
\r
60 else if (!(object instanceof Statement))
\r
62 Statement r = (Statement)object;
\r
63 return s.equalsResource(r.getSubject()) && p.equalsResource(r.getPredicate()) && o.equalsResource(r.getObject());
\r
67 public int compareTo(Statement other) {
\r
68 Statement impl = (Statement)other;
\r
69 int result = s.compareTo(impl.getSubject());
\r
70 if(result != 0) return result;
\r
71 result = p.compareTo(impl.getPredicate());
\r
72 if(result != 0) return result;
\r
73 return o.compareTo(impl.getObject());
\r