]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/content/TerminalMap.java
45ed01a21f7ee137a1f724a2895b0a2664425b91
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / content / TerminalMap.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.diagram.content;
13
14 import java.util.HashMap;
15 import java.util.Map;
16
17 import org.simantics.db.Resource;
18
19 /**
20  * terminal <-> connection point
21  * 
22  * @author Tuukka Lehtonen
23  */
24 public class TerminalMap {
25
26     public static final TerminalMap EMPTY = new TerminalMap(0) {
27         public void put(Resource terminal, Resource connectionPoint) {
28             throw new UnsupportedOperationException("immutable TerminalMap");
29         }
30     };
31
32     private final Map<Resource, Resource> leftToRight;
33     private final Map<Resource, Resource> rightToLeft;
34
35     public TerminalMap(int initialCapacity) {
36         leftToRight = new HashMap<Resource, Resource>(initialCapacity);
37         rightToLeft = new HashMap<Resource, Resource>(initialCapacity);
38     }
39
40     public Resource getConnectionPoint(Resource terminal) {
41         return leftToRight.get(terminal);
42     }
43
44     public Resource getTerminal(Resource connectionPoint) {
45         return rightToLeft.get(connectionPoint);
46     }
47
48     public void put(Resource terminal, Resource connectionPoint) {
49         leftToRight.put(terminal, connectionPoint);
50         rightToLeft.put(connectionPoint, terminal);
51     }
52
53 }