ListMap.java
2.8 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
/*
* Decompiled with CFR 0_118.
*/
package com.day.util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class ListMap {
private List list = new LinkedList();
private Map map = null;
public ListMap() {
this.map = new HashMap();
}
public ListMap(int size) {
this.map = new HashMap(size);
}
public int size() {
return this.list.size();
}
public Iterator iterator() {
return this.list.iterator();
}
public int put(Object key, Object value) {
if (this.map.get(key) != null) {
throw new IllegalArgumentException("Key '" + key + "' already exists in the ListMap.");
}
this.map.put(key, value);
this.list.add(new Entry(key, value));
return this.list.size() - 1;
}
public Object get(Object key) {
return this.map.get(key);
}
public Entry get(int index) {
return (Entry)this.list.get(index);
}
public boolean isEmpty() {
return this.list.isEmpty();
}
public void clear() {
this.list.clear();
this.map.clear();
}
public String toString() {
String buf = "";
Iterator listIf = this.list.iterator();
while (listIf.hasNext()) {
Entry entry = (Entry)listIf.next();
if (entry.val instanceof ListMap) {
buf = buf + "" + entry.key + "= (ListMap):\n" + ((ListMap)entry.val).toString(1);
continue;
}
buf = buf + "" + entry.key + "=" + entry.getValue() + "\n";
}
return buf;
}
private String toString(int indent) {
String buf = "";
String white = "";
for (int i = 0; i < indent; ++i) {
white = white + " ";
}
Iterator listIf = this.list.iterator();
while (listIf.hasNext()) {
Entry entry = (Entry)listIf.next();
if (entry.val instanceof ListMap) {
buf = buf + white + entry.key + "=\n" + ((ListMap)entry.val).toString(indent + 1);
continue;
}
buf = buf + white + entry.key + "=" + entry.val + "\n";
}
return buf;
}
public Entry getLast() {
if (this.list.size() == 0) {
return null;
}
return (Entry)this.list.get(this.list.size() - 1);
}
public class Entry {
private Object key;
private Object val;
public Entry(Object key, Object val) {
this.key = null;
this.val = null;
this.key = key;
this.val = val;
}
public Object getKey() {
return this.key;
}
public Object getValue() {
return this.val;
}
}
}