--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package fi.vtt.simantics.procore.internal;\r
+\r
+import org.simantics.db.ChangeSet.StatementChange;\r
+import org.simantics.db.Resource;\r
+\r
+/**\r
+ * Intentionally implements hashCode and equals so that the {@link #claim}\r
+ * field is not counted as an ID of this instance.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+final class StatementChangeImpl implements StatementChange {\r
+\r
+ private final Resource s;\r
+ private final Resource p;\r
+ private final Resource o;\r
+\r
+ /**\r
+ * Intentionally left package-modifiable through {@link #setClaim(boolean)}\r
+ * as an implementation-internal optimization by allowing reuse of the same\r
+ * StatementChangeImpl instance.\r
+ */\r
+ private boolean claim;\r
+\r
+ public StatementChangeImpl(final SessionImplSocket session, final int s, final int p, final int o, boolean claim) {\r
+ this.s = session.getResource(s);\r
+ this.p = session.getResource(p);\r
+ this.o = session.getResource(o);\r
+ this.claim = claim;\r
+ }\r
+ public StatementChangeImpl(final Resource s, final Resource p, final Resource o, boolean claim) {\r
+ this.s = s;\r
+ this.p = p;\r
+ this.o = o;\r
+ this.claim = claim;\r
+ }\r
+\r
+ @Override\r
+ public Resource getObject() {\r
+ return o;\r
+ }\r
+\r
+ @Override\r
+ final public Resource getPredicate() {\r
+ return p;\r
+ }\r
+\r
+ @Override\r
+ final public Resource getSubject() {\r
+ return s;\r
+ }\r
+\r
+ void setClaim(boolean claim) {\r
+ this.claim = claim;\r
+ }\r
+\r
+ public boolean isClaim() {\r
+ return claim;\r
+ }\r
+\r
+ @Override\r
+ public boolean isAsserted(Resource testSubject) {\r
+ return !s.equals(testSubject);\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ return hashCode(s, p, o);\r
+ }\r
+ \r
+ public static int hashCode(Resource s, Resource p, Resource o) {\r
+ return 41 * ( 31 * s.hashCode() + p.hashCode()) + o.hashCode();\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object object) {\r
+ if (this == object)\r
+ return true;\r
+ else if (object == null)\r
+ return false;\r
+ else if (StatementChangeImpl.class != object.getClass())\r
+ return false;\r
+ StatementChangeImpl r = (StatementChangeImpl) object;\r
+ return getSubject().equals(r.getSubject())\r
+ && getPredicate().equals(r.getPredicate())\r
+ && getObject().equals(r.getObject());\r
+ }\r
+}\r
+\r