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