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