]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/content/TerminalMap.java
Added new diagram element transformation function rotateToNeighborSlope
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / content / TerminalMap.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2018 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  *     Semantum Oy - Added getTerminals & getConnectionPoints
12  *******************************************************************************/
13 package org.simantics.diagram.content;
14
15 import java.util.HashMap;
16 import java.util.Map;
17 import java.util.Set;
18
19 import org.simantics.db.Resource;
20
21 /**
22  * terminal <-> connection point
23  * 
24  * @author Tuukka Lehtonen
25  */
26 public class TerminalMap {
27
28     public static final TerminalMap EMPTY = new TerminalMap(0) {
29         public void put(Resource terminal, Resource connectionPoint) {
30             throw new UnsupportedOperationException("immutable TerminalMap");
31         }
32     };
33
34     private final Map<Resource, Resource> leftToRight;
35     private final Map<Resource, Resource> rightToLeft;
36
37     public TerminalMap(int initialCapacity) {
38         leftToRight = new HashMap<Resource, Resource>(initialCapacity);
39         rightToLeft = new HashMap<Resource, Resource>(initialCapacity);
40     }
41
42     public Resource getConnectionPoint(Resource terminal) {
43         return leftToRight.get(terminal);
44     }
45
46     public Resource getTerminal(Resource connectionPoint) {
47         return rightToLeft.get(connectionPoint);
48     }
49
50     public void put(Resource terminal, Resource connectionPoint) {
51         leftToRight.put(terminal, connectionPoint);
52         rightToLeft.put(connectionPoint, terminal);
53     }
54
55     /**
56      * @since 1.36.0
57      */
58     public Set<Resource> getTerminals() {
59         return leftToRight.keySet();
60     }
61
62     /**
63      * @since 1.36.0
64      */
65     public Set<Resource> getConnectionPoints() {
66         return rightToLeft.keySet();
67     }
68
69 }