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