|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.util; |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| public class ObjectIdentityMap |
|
25 |
| { |
|
26 |
| private int _pairCount = 0; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| private Object[] _pairs; |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
5670
| public void put(Object key, Object value)
|
|
41 |
| { |
|
42 |
5670
| for (int i = 0; i < _pairCount; i++)
|
|
43 |
| { |
|
44 |
17373
| int index = 2 * i;
|
|
45 |
| |
|
46 |
17373
| if (_pairs[index] == key)
|
|
47 |
| { |
|
48 |
0
| _pairs[index + 1] = value;
|
|
49 |
0
| return;
|
|
50 |
| } |
|
51 |
| } |
|
52 |
| |
|
53 |
5670
| expandPairsIfNeeded();
|
|
54 |
| |
|
55 |
5670
| int index = 2 * _pairCount;
|
|
56 |
| |
|
57 |
5670
| _pairs[index] = key;
|
|
58 |
5670
| _pairs[index + 1] = value;
|
|
59 |
| |
|
60 |
5670
| _pairCount++;
|
|
61 |
| } |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
8253
| public Object get(Object key)
|
|
70 |
| { |
|
71 |
8253
| for (int i = 0; i < _pairCount; i++)
|
|
72 |
| { |
|
73 |
25626
| int index = 2 * i;
|
|
74 |
| |
|
75 |
25626
| if (_pairs[index] == key)
|
|
76 |
| { |
|
77 |
849
| return _pairs[index + 1];
|
|
78 |
| } |
|
79 |
| } |
|
80 |
| |
|
81 |
7404
| return null;
|
|
82 |
| } |
|
83 |
| |
|
84 |
5670
| private void expandPairsIfNeeded()
|
|
85 |
| { |
|
86 |
5670
| int currentSize = _pairs == null ? 0 : _pairs.length;
|
|
87 |
| |
|
88 |
5670
| int newLength = 2 * (_pairCount + 1);
|
|
89 |
| |
|
90 |
5670
| if (newLength >= currentSize)
|
|
91 |
| { |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
1917
| int newSize = Math.max(10, 2 * currentSize);
|
|
96 |
| |
|
97 |
1917
| Object[] newPairsArray = new Object[newSize];
|
|
98 |
| |
|
99 |
1917
| if (currentSize > 0)
|
|
100 |
675
| System.arraycopy(_pairs, 0, newPairsArray, 0, currentSize);
|
|
101 |
| |
|
102 |
1917
| _pairs = newPairsArray;
|
|
103 |
| } |
|
104 |
| } |
|
105 |
| } |