-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjf_LinkedHashMap.cls
More file actions
100 lines (85 loc) · 2.56 KB
/
Copy pathjf_LinkedHashMap.cls
File metadata and controls
100 lines (85 loc) · 2.56 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
public with sharing class jf_LinkedHashMap {
private Map<String, Object> innerMap = new Map<String, Object>();
private List<String> linkedKeyList = new List<String>();
private boolean putOrder;
private boolean accessOrder;
public jf_LinkedHashMap() {
this.putOrder = false;
this.accessOrder = false;
}
public jf_LinkedHashMap(boolean putOrder, boolean accessOrder) {
this.putOrder = putOrder;
this.accessOrder = accessOrder;
}
public void clear() {
this.innerMap.clear();
this.linkedKeyList.clear();
}
public boolean containsKey(String key) {
return this.innerMap.containsKey(key);
}
public object get(String key) {
if (this.accessOrder) {
this.tailKey(key);
}
return this.innerMap.get(key);
}
public object get(Integer index) {
if (index >= 0 && index < this.linkedKeyList.size()) {
return this.get(this.linkedKeyList[index]);
}
return null;
}
public Integer hashCode() {
return this.innerMap.hashCode();
}
public Set<String> keySet() {
return this.innerMap.keySet();
}
public List<String> keyList() {
return this.linkedKeyList;
}
public void put(String key, Object value) {
if (this.innerMap.containsKey(key)) {
if (this.putOrder) {
this.tailKey(key);
}
this.innerMap.put(key, value);
}
else {
this.innerMap.put(key, value);
this.linkedKeyList.add(key);
}
}
public List<Object> values() {
List<Object> vl = new List<Object>();
for (String key : this.linkedKeyList) {
vl.add(this.innerMap.get(key));
}
return vl;
}
public Integer size() {
return this.innerMap.size();
}
public void remove(String key) {
for (Integer i = 0; i < linkedKeyList.size(); i++) {
if (this.linkedKeyList.get(i) == key) {
this.innerMap.remove(key);
this.linkedKeyList.remove(i);
}
}
}
public void remove(Integer index) {
if (index >= 0 && index < this.linkedKeyList.size()) {
this.remove(this.linkedKeyList[index]);
}
}
private void tailKey(String key) {
for (Integer i = 0; i < linkedKeyList.size(); i++) {
if (this.linkedKeyList.get(i) == key) {
this.linkedKeyList.remove(i);
this.linkedKeyList.add(key);
}
}
}
}