1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.diagram.content;
14 import java.util.HashMap;
17 import org.simantics.db.Resource;
20 * terminal <-> connection point
22 * @author Tuukka Lehtonen
24 public class TerminalMap {
26 public static final TerminalMap EMPTY = new TerminalMap(0) {
27 public void put(Resource terminal, Resource connectionPoint) {
28 throw new UnsupportedOperationException("immutable TerminalMap");
32 private final Map<Resource, Resource> leftToRight;
33 private final Map<Resource, Resource> rightToLeft;
35 public TerminalMap(int initialCapacity) {
36 leftToRight = new HashMap<Resource, Resource>(initialCapacity);
37 rightToLeft = new HashMap<Resource, Resource>(initialCapacity);
40 public Resource getConnectionPoint(Resource terminal) {
41 return leftToRight.get(terminal);
44 public Resource getTerminal(Resource connectionPoint) {
45 return rightToLeft.get(connectionPoint);
48 public void put(Resource terminal, Resource connectionPoint) {
49 leftToRight.put(terminal, connectionPoint);
50 rightToLeft.put(connectionPoint, terminal);