]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/StandardStatement.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / StandardStatement.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.common;
13
14 import org.simantics.db.Resource;
15 import org.simantics.db.Statement;
16
17 public final class StandardStatement implements Statement, Comparable<Statement> {
18         
19     final private Resource s;
20     final private Resource p;
21     final private Resource o;
22     
23     public StandardStatement(final Resource s, final Resource p, final Resource o) {
24         this.s = s;
25         this.p = p;
26         this.o = o;
27     }
28     
29     @Override
30     public Resource getObject() {
31         return o;
32     }
33
34     @Override
35     final public Resource getPredicate() {
36         return p;
37     }
38
39     @Override
40     final public Resource getSubject() {
41         return s;
42     }
43
44     @Override
45     public boolean isAsserted(Resource testSubject) {
46         return !s.equals(testSubject);
47     }
48     
49     @Override
50     final public int hashCode() {
51         return 41 * ( 31 * s.hashCode() + p.hashCode()) + o.hashCode();
52     }
53
54     @Override
55     public boolean equals(Object object) {
56         if (this == object)
57             return true;
58         else if (object == null)
59             return false;
60         else if (!(object instanceof Statement))
61             return false;
62         Statement r = (Statement)object;
63         return s.equalsResource(r.getSubject()) && p.equalsResource(r.getPredicate()) && o.equalsResource(r.getObject());
64     }
65     
66     @Override
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());
74     }
75
76 }
77