1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.common;
14 import org.simantics.db.Resource;
15 import org.simantics.db.Statement;
17 public final class StandardStatement implements Statement, Comparable<Statement> {
19 final private Resource s;
20 final private Resource p;
21 final private Resource o;
23 public StandardStatement(final Resource s, final Resource p, final Resource o) {
30 public Resource getObject() {
35 final public Resource getPredicate() {
40 final public Resource getSubject() {
45 public boolean isAsserted(Resource testSubject) {
46 return !s.equals(testSubject);
50 final public int hashCode() {
51 return 41 * ( 31 * s.hashCode() + p.hashCode()) + o.hashCode();
55 public boolean equals(Object object) {
58 else if (object == null)
60 else if (!(object instanceof Statement))
62 Statement r = (Statement)object;
63 return s.equalsResource(r.getSubject()) && p.equalsResource(r.getPredicate()) && o.equalsResource(r.getObject());
67 public int compareTo(Statement other) {
68 Statement impl = (Statement)other;
69 int result = s.compareTo(impl.getSubject());
70 if(result != 0) return result;
71 result = p.compareTo(impl.getPredicate());
72 if(result != 0) return result;
73 return o.compareTo(impl.getObject());