]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/UniqueTerminalDataImpl.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / UniqueTerminalDataImpl.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.element.handler.impl;
13
14 import java.util.Collection;
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.simantics.g2d.diagram.handler.Topology.Terminal;
19 import org.simantics.g2d.element.IElement;
20 import org.simantics.g2d.element.handler.TerminalData;
21 import org.simantics.utils.datastructures.hints.IHintContext.Key;
22
23 /**
24  * TerminalDataImpl that is used in ElementClass
25  * 
26  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
27  *
28  */
29 public class UniqueTerminalDataImpl implements TerminalData {
30
31     private static final long serialVersionUID = -2131030904280472077L;
32
33     private final Map<Terminal,Map<Key,Object>> terminals = new HashMap<Terminal, Map<Key,Object>>();
34
35     public UniqueTerminalDataImpl(Collection<? extends Terminal> terminals) {
36         for (Terminal t : terminals) {
37             this.terminals.put(t, new HashMap<Key, Object>(2));
38         }
39     }
40
41
42
43     @Override
44     public <T> T getHint(IElement e, Terminal t, Key key) {
45         Map<Key,Object> data = terminals.get(t);
46         if (data != null)
47             return (T)data.get(key);
48         return null;
49     }
50
51     @Override
52     public void setHint(IElement e, Terminal t, Key key, Object value) {
53         Map<Key,Object> data = terminals.get(t);
54         data.put(key, value);
55     }
56
57 }