1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*
* Copyright (c) 2009, 2011, 2012, 2015 Eike Stepper (Loehne, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eike Stepper - initial API and implementation
*/
package org.eclipse.net4j.util.collection;
import java.util.HashMap;
import java.util.Map;
/**
* @author Eike Stepper
* @since 2.0
* @deprecated As of 3.6 use {@link BidiMap}.
*/
@Deprecated
public class BidiMapper<T1, T2>
{
private Map<T1, T2> map1 = new HashMap<T1, T2>();
private Map<T2, T1> map2 = new HashMap<T2, T1>();
public BidiMapper()
{
}
public synchronized void map(T1 v1, T2 v2)
{
map1.put(v1, v2);
map2.put(v2, v1);
}
public synchronized int size()
{
return map1.size();
}
public synchronized void clear()
{
map1.clear();
map2.clear();
}
public synchronized T2 lookup1(T1 v1)
{
return map1.get(v1);
}
public synchronized T1 lookup2(T2 v2)
{
return map2.get(v2);
}
public synchronized boolean remove1(T1 v1)
{
T2 v2 = map1.remove(v1);
if (v2 != null)
{
map2.remove(v2);
return true;
}
return false;
}
public synchronized boolean remove2(T2 v2)
{
T1 v1 = map2.remove(v2);
if (v1 != null)
{
map1.remove(v1);
return true;
}
return false;
}
}
|