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