OrderedStringKeyMap.java
4.74 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* Decompiled with CFR 0_118.
*/
package com.day.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
public class OrderedStringKeyMap {
private final ArrayList list = new ArrayList();
private final HashMap map = new HashMap();
public int size() {
return this.list.size();
}
public boolean isEmpty() {
return this.list.isEmpty();
}
public boolean contains(Object o) {
return this.map.containsValue(o);
}
public boolean contains(String key) {
return this.map.containsKey(key);
}
public boolean containsValue(Object o) {
return this.map.containsValue(o);
}
public boolean containsKey(String key) {
return this.map.containsKey(key);
}
public Object get(String key) {
return this.map.get(key);
}
public Object get(int index) {
return this.list.get(index);
}
public Iterator iterator() {
return this.list.iterator();
}
public Iterator iterator(boolean reverse) {
return reverse ? new ReverseListIterator(this.list) : this.list.iterator();
}
public Iterator keys() {
return this.map.keySet().iterator();
}
public Object[] toArray() {
return this.list.toArray();
}
public Object[] toArray(Object[] a) {
return this.list.toArray(a);
}
public void clear() {
this.list.clear();
this.map.clear();
}
public Object put(String key, Object value) {
Object old = this.map.put(key, value);
if (old != null) {
this.list.remove(old);
}
this.list.add(value);
return old;
}
public Object set(String key, Object value) {
Object old = this.map.put(key, value);
if (old != null) {
int idx = this.list.indexOf(old);
this.list.remove(old);
this.list.add(idx, value);
} else {
this.list.add(value);
}
return old;
}
public int indexOf(Object value) {
return this.list.indexOf(value);
}
public Object put(String key, Object value, int index) {
Object old = this.map.remove(key);
if (old != null) {
this.list.remove(old);
}
this.list.add(index, value);
this.map.put(key, value);
return old;
}
public Object put(String key, Object value, String above) {
Object old = this.map.remove(key);
if (old != null) {
this.list.remove(old);
}
int index = above == null ? -1 : this.list.indexOf(this.map.get(above));
this.map.put(key, value);
if (index < 0) {
this.list.add(value);
} else {
this.list.add(index, value);
}
return old;
}
public Object remove(String key) {
Object old = this.map.remove(key);
if (old != null) {
this.list.remove(old);
}
return old;
}
public Object remove(int index) {
Object old = this.list.remove(index);
if (old != null) {
this.map.remove(old);
}
return old;
}
public Object lastElement() {
if (this.list.isEmpty()) {
return null;
}
return this.list.get(this.list.size() - 1);
}
public void move(String key, String above) {
Object aboveElem;
Object elem = this.map.get(key);
if (elem == null) {
throw new NoSuchElementException(key);
}
if (key.equals(above)) {
return;
}
if (above == null || above.equals("") || (aboveElem = this.map.get(above)) == null) {
this.list.remove(elem);
this.list.add(elem);
} else {
this.list.remove(elem);
this.list.add(this.list.indexOf(aboveElem), elem);
}
}
public Set entrySet() {
return this.map.entrySet();
}
public Set keySet() {
return this.map.keySet();
}
private static final class ReverseListIterator
implements Iterator {
private final List list;
private int pos;
public ReverseListIterator(List list) {
this.list = list;
this.pos = list.size() - 1;
}
public boolean hasNext() {
return this.pos >= 0;
}
public Object next() throws NoSuchElementException {
if (this.pos < 0) {
throw new NoSuchElementException();
}
return this.list.get(this.pos--);
}
public void remove() {
throw new UnsupportedOperationException();
}
}
}