]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/NewStatementImpl.java
Merge "Testing SonarQube with Simantics Platform SDK - still"
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / NewStatementImpl.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 fi.vtt.simantics.procore.internal;\r
13 \r
14 import org.simantics.db.Resource;\r
15 import org.simantics.db.Statement;\r
16 import org.simantics.db.impl.ResourceImpl;\r
17 \r
18 public class NewStatementImpl implements Statement {\r
19 \r
20     public final ResourceImpl subject;\r
21     public final ResourceImpl predicate;\r
22     public final ResourceImpl object;\r
23     \r
24     public NewStatementImpl(int id, ResourceImpl subject, ResourceImpl predicate, ResourceImpl object) {\r
25         if (null == subject)\r
26             throw new IllegalArgumentException();\r
27         if(null == predicate)\r
28             throw new IllegalArgumentException();\r
29         if(null == predicate)\r
30             throw new IllegalArgumentException();\r
31         this.subject = (ResourceImpl)subject;\r
32         this.predicate = (ResourceImpl)predicate;\r
33         this.object = (ResourceImpl)object;\r
34     }\r
35     @Override\r
36     final public Resource getObject() {\r
37         return object;\r
38     }\r
39 \r
40     @Override\r
41     final public Resource getPredicate() {\r
42         return predicate;\r
43     }\r
44 \r
45     @Override\r
46     final public Resource getSubject() {\r
47         return subject;\r
48     }\r
49 \r
50     public int hashCode()\r
51     {\r
52         // TODO: :)\r
53         int result = 6151 * ((int)(subject.id ^ (subject.id>>>32))*6151 + \r
54         (int)(predicate.id ^ (predicate.id>>>32))) +\r
55         (int)(object.id ^ (object.id>>>32)); \r
56         return result;\r
57         \r
58     }\r
59 \r
60     @Override\r
61     public boolean isAsserted(Resource testSubject) {\r
62         return !subject.equals(testSubject);\r
63     }\r
64     \r
65     public boolean equals(Object object)\r
66     {\r
67         if (this == object)\r
68             return true;\r
69         else if (object == null)\r
70             return false;\r
71         try {\r
72             Statement r = (Statement)object;\r
73             return subject.id == r.getSubject().getResourceId() &&\r
74             predicate.id == r.getPredicate().getResourceId() &&\r
75             this.object.id == r.getObject().getResourceId();\r
76         } catch (ClassCastException e) {\r
77             return false;\r
78         }\r
79     }\r
80     \r
81     \r
82 }\r