Last change
on this file since 193 was
193,
checked in by Maciej Komosinski, 10 years ago
|
Set svn:eol-style native for all textual files
|
-
Property svn:eol-style set to
native
|
File size:
1.1 KB
|
Line | |
---|
1 | package com.framsticks.util; |
---|
2 | |
---|
3 | import java.util.Collections; |
---|
4 | import java.util.HashMap; |
---|
5 | import java.util.HashSet; |
---|
6 | import java.util.Map; |
---|
7 | import java.util.Set; |
---|
8 | |
---|
9 | public class DoubleMap<K, V> { |
---|
10 | |
---|
11 | protected final Map<K, V> byId = new HashMap<>(); |
---|
12 | protected final Map<K, V> byName = new HashMap<>(); |
---|
13 | protected final Set<V> values = new HashSet<>(); |
---|
14 | |
---|
15 | public int size() { |
---|
16 | return values.size(); |
---|
17 | } |
---|
18 | |
---|
19 | public void put(K id, K name, V value) { |
---|
20 | values.add(value); |
---|
21 | if (id != null) { |
---|
22 | byId.put(id, value); |
---|
23 | } |
---|
24 | if (name != null) { |
---|
25 | byName.put(name, value); |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | public boolean containsValue(V value) { |
---|
30 | return values.contains(value); |
---|
31 | |
---|
32 | } |
---|
33 | |
---|
34 | public boolean containsKey(K identifier) { |
---|
35 | return byId.containsKey(identifier) || byName.containsKey(identifier); |
---|
36 | } |
---|
37 | |
---|
38 | public V get(K identifier) { |
---|
39 | if (byId.containsKey(identifier)) { |
---|
40 | return byId.get(identifier); |
---|
41 | } |
---|
42 | if (byName.containsKey(identifier)) { |
---|
43 | return byName.get(identifier); |
---|
44 | } |
---|
45 | return null; |
---|
46 | } |
---|
47 | |
---|
48 | public Set<V> getValues() { |
---|
49 | return Collections.unmodifiableSet(values); |
---|
50 | } |
---|
51 | |
---|
52 | public Map<K, V> getValuesById() { |
---|
53 | return Collections.unmodifiableMap(byId); |
---|
54 | } |
---|
55 | |
---|
56 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.