X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Fconnection%2FTerminalKeyOf.java;h=df54a8bc240394ec0b9642351bc3b221b663cf3f;hb=197f65594b46aaa087ac4d9bb6cb5514376377ca;hp=8a2d7bf66bc767e7e170c6eea03f24e4cf7c9300;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/connection/TerminalKeyOf.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/connection/TerminalKeyOf.java index 8a2d7bf66..df54a8bc2 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/connection/TerminalKeyOf.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/connection/TerminalKeyOf.java @@ -1,88 +1,88 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g2d.connection; - -import org.simantics.g2d.diagram.handler.Topology.Terminal; -import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd; -import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; - -/** - * This hint key is used for representing a terminal within an element that is - * connected to an edge. The key is identified by two things: the connected - * terminal and a secondary data object that can be used to make the key unique - * for an edge in cases where several connections to the same terminal are - * possible. A good option is to use the back-end object of the edge element - * itself, which naturally makes the key unique for that particular edge. - * - *
- * This key has a counterpart, {@link EndKeyOf} that is used in edge elements to - * connect both the {@link EdgeEnd#Begin} and {@link EdgeEnd#End} ends of the - * edge to element terminals. To actually represent the connection, you should - * give the same value object for this hint pair. - *
- * - * @author Tuukka Lehtonen - */ -public class TerminalKeyOf extends KeyOf { - - private final Terminal terminal; - private final Object data; - private int hash; - - /** - * @param t the terminal this connector hint represents - * @param data a secondary data object for making the key unique for a - * single edge connected to the specified terminal. Use a - *null
value only if you consider the terminal to allow
- * only one connected edge.
- * @param clazz the allowed class of the value object.
- */
- public TerminalKeyOf(Terminal t, Object data, Class> clazz) {
- super(clazz);
- this.terminal = t;
- this.data = data;
- this.hash = t.hashCode() ^ clazz.hashCode();
- if (data != null)
- this.hash = this.hash * 31 + data.hashCode();
- }
-
- public Terminal getTerminal() {
- return terminal;
- }
-
- public Object getData() {
- return data;
- }
-
- @Override
- public int hashCode() {
- return hash;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!(obj instanceof TerminalKeyOf))
- return false;
- TerminalKeyOf other = (TerminalKeyOf) obj;
- if (!terminal.equals(other.terminal))
- return false;
- return (data == null) ? other.data == null : data.equals(other.data);
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "[terminal=" + terminal + ", data=" + data + "]";
- }
-
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g2d.connection;
+
+import org.simantics.g2d.diagram.handler.Topology.Terminal;
+import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd;
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
+
+/**
+ * This hint key is used for representing a terminal within an element that is
+ * connected to an edge. The key is identified by two things: the connected
+ * terminal and a secondary data object that can be used to make the key unique
+ * for an edge in cases where several connections to the same terminal are
+ * possible. A good option is to use the back-end object of the edge element
+ * itself, which naturally makes the key unique for that particular edge.
+ *
+ * + * This key has a counterpart, {@link EndKeyOf} that is used in edge elements to + * connect both the {@link EdgeEnd#Begin} and {@link EdgeEnd#End} ends of the + * edge to element terminals. To actually represent the connection, you should + * give the same value object for this hint pair. + *
+ * + * @author Tuukka Lehtonen + */ +public class TerminalKeyOf extends KeyOf { + + private final Terminal terminal; + private final Object data; + private int hash; + + /** + * @param t the terminal this connector hint represents + * @param data a secondary data object for making the key unique for a + * single edge connected to the specified terminal. Use a + *null
value only if you consider the terminal to allow
+ * only one connected edge.
+ * @param clazz the allowed class of the value object.
+ */
+ public TerminalKeyOf(Terminal t, Object data, Class> clazz) {
+ super(clazz);
+ this.terminal = t;
+ this.data = data;
+ this.hash = t.hashCode() ^ clazz.hashCode();
+ if (data != null)
+ this.hash = this.hash * 31 + data.hashCode();
+ }
+
+ public Terminal getTerminal() {
+ return terminal;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ @Override
+ public int hashCode() {
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof TerminalKeyOf))
+ return false;
+ TerminalKeyOf other = (TerminalKeyOf) obj;
+ if (!terminal.equals(other.terminal))
+ return false;
+ return (data == null) ? other.data == null : data.equals(other.data);
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "[terminal=" + terminal + ", data=" + data + "]";
+ }
+
}
\ No newline at end of file