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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package fi.vtt.simantics.procore.internal;
\r
14 import org.simantics.db.ChangeSet.StatementChange;
\r
15 import org.simantics.db.Resource;
\r
18 * Intentionally implements hashCode and equals so that the {@link #claim}
\r
19 * field is not counted as an ID of this instance.
\r
21 * @author Tuukka Lehtonen
\r
23 final class StatementChangeImpl implements StatementChange {
\r
25 private final Resource s;
\r
26 private final Resource p;
\r
27 private final Resource o;
\r
30 * Intentionally left package-modifiable through {@link #setClaim(boolean)}
\r
31 * as an implementation-internal optimization by allowing reuse of the same
\r
32 * StatementChangeImpl instance.
\r
34 private boolean claim;
\r
36 public StatementChangeImpl(final SessionImplSocket session, final int s, final int p, final int o, boolean claim) {
\r
37 this.s = session.getResource(s);
\r
38 this.p = session.getResource(p);
\r
39 this.o = session.getResource(o);
\r
42 public StatementChangeImpl(final Resource s, final Resource p, final Resource o, boolean claim) {
\r
50 public Resource getObject() {
\r
55 final public Resource getPredicate() {
\r
60 final public Resource getSubject() {
\r
64 void setClaim(boolean claim) {
\r
68 public boolean isClaim() {
\r
73 public boolean isAsserted(Resource testSubject) {
\r
74 return !s.equals(testSubject);
\r
78 public int hashCode() {
\r
79 return hashCode(s, p, o);
\r
82 public static int hashCode(Resource s, Resource p, Resource o) {
\r
83 return 41 * ( 31 * s.hashCode() + p.hashCode()) + o.hashCode();
\r
87 public boolean equals(Object object) {
\r
90 else if (object == null)
\r
92 else if (StatementChangeImpl.class != object.getClass())
\r
94 StatementChangeImpl r = (StatementChangeImpl) object;
\r
95 return getSubject().equals(r.getSubject())
\r
96 && getPredicate().equals(r.getPredicate())
\r
97 && getObject().equals(r.getObject());
\r