1 /*******************************************************************************
2 * Copyright (c) 2007, 2018 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 * Semantum Oy - Added getTerminals & getConnectionPoints
12 *******************************************************************************/
13 package org.simantics.diagram.content;
15 import java.util.HashMap;
19 import org.simantics.db.Resource;
22 * terminal <-> connection point
24 * @author Tuukka Lehtonen
26 public class TerminalMap {
28 public static final TerminalMap EMPTY = new TerminalMap(0) {
29 public void put(Resource terminal, Resource connectionPoint) {
30 throw new UnsupportedOperationException("immutable TerminalMap");
34 private final Map<Resource, Resource> leftToRight;
35 private final Map<Resource, Resource> rightToLeft;
37 public TerminalMap(int initialCapacity) {
38 leftToRight = new HashMap<Resource, Resource>(initialCapacity);
39 rightToLeft = new HashMap<Resource, Resource>(initialCapacity);
42 public Resource getConnectionPoint(Resource terminal) {
43 return leftToRight.get(terminal);
46 public Resource getTerminal(Resource connectionPoint) {
47 return rightToLeft.get(connectionPoint);
50 public void put(Resource terminal, Resource connectionPoint) {
51 leftToRight.put(terminal, connectionPoint);
52 rightToLeft.put(connectionPoint, terminal);
58 public Set<Resource> getTerminals() {
59 return leftToRight.keySet();
65 public Set<Resource> getConnectionPoints() {
66 return rightToLeft.keySet();