]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/connection/EndKeyOf.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / connection / EndKeyOf.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.connection;\r
13 \r
14 import org.simantics.g2d.diagram.handler.Topology.Connection;\r
15 import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd;\r
16 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
17 \r
18 /**\r
19  * @author Tuukka Lehtonen\r
20  */\r
21 public class EndKeyOf extends KeyOf {\r
22 \r
23     private final EdgeEnd end;\r
24     private int hash;\r
25 \r
26     private static final EndKeyOf  BEGIN = new EndKeyOf(EdgeEnd.Begin, Connection.class);\r
27     private static final EndKeyOf  END   = new EndKeyOf(EdgeEnd.End, Connection.class);\r
28     public static final EndKeyOf[] KEYS  = { BEGIN, END };\r
29 \r
30     public static EndKeyOf get(EdgeEnd end) {\r
31         switch (end) {\r
32             case Begin: return BEGIN;\r
33             case End: return END;\r
34             default: throw new IllegalArgumentException("unrecognized EdgeEnd value: " + end);\r
35         }\r
36     }\r
37 \r
38     private EndKeyOf(EdgeEnd end, Class<?> clazz) {\r
39         super(clazz);\r
40         this.end = end;\r
41         hash = end.hashCode();\r
42     }\r
43 \r
44     public EdgeEnd getEnd() {\r
45         return end;\r
46     }\r
47 \r
48     @Override\r
49     public int hashCode() {\r
50         return hash;\r
51     }\r
52 \r
53     @Override\r
54     public boolean equals(Object obj) {\r
55         if (!(obj instanceof EndKeyOf))\r
56             return false;\r
57         EndKeyOf other = (EndKeyOf) obj;\r
58         if (!other.end.equals(end)) return false;\r
59         return true;\r
60     }\r
61 \r
62     @Override\r
63     public String toString() {\r
64         return getClass().getSimpleName() + "[" + end + "]";\r
65     }\r
66 \r
67 }