OSDN Git Service

0213a604f07ded5f617ac6973455aa2d0ee68ffc
[chemicraft/chemicraft.git] / common / pcc / chemicraft / util / ListHash.java
1 package pcc.chemicraft.util;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.HashMap;
6 import java.util.Iterator;
7 import java.util.List;
8 import java.util.ListIterator;
9 import java.util.Map;
10 import java.util.Set;
11
12 public class ListHash<K, E>
13 {
14         /**
15          * @author Ponkotate version:1.0.0 dev
16          *
17          *         Create ArrayList in HashMap.
18          */
19
20         protected ArrayList<K> keysList = new ArrayList<K>();
21         protected HashMap<K, ArrayList<E>> elementsHash = new HashMap<K, ArrayList<E>>();
22
23         public boolean add(K par1Key, E par2Element)
24         {
25                 try {
26                         return this.elementsHash.get(par1Key).add(par2Element);
27                 } catch (Exception e) {
28                         return this.put(par1Key, par2Element);
29                 }
30         }
31
32         public boolean addAll(K par1Key, Collection<? extends E> par2Collection)
33         {
34                 return this.elementsHash.get(par1Key).addAll(par2Collection);
35         }
36
37         public boolean addAll(K par1Key, int par2Index, Collection<? extends E> par3Collection)
38         {
39                 return this.elementsHash.get(par1Key).addAll(par2Index, par3Collection);
40         }
41
42         public void clear()
43         {
44                 this.elementsHash.clear();
45         }
46
47         public boolean containsKey(K par1Key)
48         {
49                 return this.elementsHash.containsKey(par1Key);
50         }
51
52         public boolean containsValue(K par1Key)
53         {
54                 return this.elementsHash.containsValue(par1Key);
55         }
56
57         public boolean contains(K par1Key, E par2Element)
58         {
59                 return this.elementsHash.get(par1Key).contains(par2Element);
60         }
61
62         public boolean containsAll(K par1Key, Collection<?> par2Collection)
63         {
64                 return this.elementsHash.get(par1Key).containsAll(par2Collection);
65         }
66
67         public Set<java.util.Map.Entry<K, E>> entrySet()
68         {
69                 return this.entrySet();
70         }
71
72         public K getKeyList(int par1Index)
73         {
74                 return this.keysList.get(par1Index);
75         }
76
77         public E get(K par1Key, int par2Index)
78         {
79                 return this.elementsHash.get(par1Key).get(par2Index);
80         }
81
82         public ArrayList<E> get(K par1Key) {
83                 return this.elementsHash.get(par1Key);
84         }
85
86         public int indexOf(K par1Key, E par2Element)
87         {
88                 return this.elementsHash.get(par1Key).indexOf(par2Element);
89         }
90
91         public boolean isKeysListEmpty(K par1Key)
92         {
93                 return this.elementsHash.get(par1Key).isEmpty();
94         }
95
96         public boolean isElementsHashEmpty()
97         {
98                 return this.elementsHash.isEmpty();
99         }
100
101         public Iterator<K> iterator()
102         {
103                 return this.keysList.iterator();
104         }
105
106         public Iterator<E> iterator(K par1Key)
107         {
108                 return this.elementsHash.get(par1Key).iterator();
109         }
110
111         public int lastIndexOf(K par1Key, E par2Element)
112         {
113                 return this.elementsHash.get(par1Key).lastIndexOf(par2Element);
114         }
115
116         public ListIterator<E> listIterator(K par1Key)
117         {
118                 return this.elementsHash.get(par1Key).listIterator();
119         }
120
121         public ListIterator<E> listIterator(K par1Key, int par2Index)
122         {
123                 return this.elementsHash.get(par1Key).listIterator(par2Index);
124         }
125
126         public Set<K> keySet()
127         {
128                 return this.elementsHash.keySet();
129         }
130
131         public boolean put(K par1Key, E par2Element)
132         {
133                 this.keysList.add(par1Key);
134
135                 ArrayList<E> elementList = new ArrayList<E>();
136                 this.elementsHash.put(par1Key, elementList);
137                 return this.add(par1Key, par2Element);
138         }
139
140         public void putAll(Map<? extends K, ? extends ArrayList<E>> par1Map)
141         {
142                 this.elementsHash.putAll(par1Map);
143         }
144
145         public ArrayList<E> remove(K par1Key)
146         {
147                 return this.elementsHash.remove(par1Key);
148         }
149
150         public boolean remove(K par1Key, E par2Element)
151         {
152                 return this.elementsHash.get(par1Key).remove(par2Element);
153         }
154
155         public E remove(K par1Key, int par2Index)
156         {
157                 return this.elementsHash.get(par1Key).remove(par2Index);
158         }
159
160         public boolean removeAll(K par1Key, Collection<?> par2Collection)
161         {
162                 return this.elementsHash.get(par1Key).removeAll(par2Collection);
163         }
164
165         public boolean retainAll(K par1Key, Collection<?> par2Collection)
166         {
167                 return this.elementsHash.get(par1Key).retainAll(par2Collection);
168         }
169
170         public E set(K par1Key, int par2Index, E par3Element)
171         {
172                 return this.elementsHash.get(par1Key).set(par2Index, par3Element);
173         }
174
175         public int sizeElementsHash()
176         {
177                 return this.elementsHash.size();
178         }
179
180         public int sizeKeysList()
181         {
182                 return this.keysList.size();
183         }
184
185         public int sizeElementsList(K par1Key)
186         {
187                 return this.elementsHash.get(par1Key).size();
188         }
189
190         public List<E> subList(K par1Key, int par2FromIndex, int par3ToIndex)
191         {
192                 return this.elementsHash.get(par1Key).subList(
193                                 par2FromIndex,
194                                 par3ToIndex);
195         }
196
197         public E[] toArray(K par1Key)
198         {
199                 return (E[])this.elementsHash.get(par1Key).toArray();
200         }
201
202         public <T> T[] toArray(K par1Key, T[] par2Array)
203         {
204                 return this.elementsHash.get(par1Key).toArray(par2Array);
205         }
206
207         public Collection<ArrayList<E>> values()
208         {
209                 return this.elementsHash.values();
210         }
211
212 }