Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BidiMap |
|
| 1.0;1 |
1 | /******************************************************************************* | |
2 | * Copyright (c) 2008-2009 SWTBot Committers and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Ketan Padegaonkar - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.swtbot.swt.finder.utils; | |
12 | ||
13 | import java.util.HashMap; | |
14 | import java.util.Iterator; | |
15 | import java.util.Map.Entry; | |
16 | ||
17 | /** | |
18 | * <b>Note: This is not error proof, and adding the same key twice with a different value will have uncertain | |
19 | * results.</b> | |
20 | * | |
21 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
22 | * @version $Id$ | |
23 | * @noinstantiate This class is not intended to be instantiated by clients. | |
24 | * @noextend This class is not intended to be subclassed by clients. | |
25 | */ | |
26 | public class BidiMap<K, V> implements Iterable<Entry<K, V>> { | |
27 | ||
28 | private final HashMap<K, V> forward; | |
29 | private final HashMap<V, K> reverse; | |
30 | ||
31 | 7 | public BidiMap() { |
32 | 7 | forward = new HashMap<K, V>(); |
33 | 7 | reverse = new HashMap<V, K>(); |
34 | 7 | } |
35 | ||
36 | public void put(K k, V v) { | |
37 | 282 | forward.put(k, v); |
38 | 282 | reverse.put(v, k); |
39 | 282 | } |
40 | ||
41 | public K getKey(V v) { | |
42 | 6573 | return reverse.get(v); |
43 | } | |
44 | ||
45 | public int size() { | |
46 | 0 | return forward.size(); |
47 | } | |
48 | ||
49 | public Iterator<Entry<K, V>> iterator() { | |
50 | 1 | return forward.entrySet().iterator(); |
51 | } | |
52 | ||
53 | public V getValue(K k) { | |
54 | 86 | return forward.get(k); |
55 | } | |
56 | ||
57 | } |