1 7 package org.jboss.axis.utils; 8 9 11 import java.util.ArrayList ; 12 import java.util.Collection ; 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 import java.util.Set ; 17 18 23 public class LinkedHashMap implements Map 24 { 25 26 private HashMap delegate = new HashMap (); 27 private OrderedSet keys = new OrderedSet(); 28 29 public int size() 30 { 31 return delegate.size(); 32 } 33 34 public boolean isEmpty() 35 { 36 return delegate.isEmpty(); 37 } 38 39 public boolean containsKey(Object key) 40 { 41 return delegate.containsKey(key); 42 } 43 44 public boolean containsValue(Object value) 45 { 46 return delegate.containsValue(value); 47 } 48 49 public Object get(Object key) 50 { 51 return delegate.get(key); 52 } 53 54 public Object put(Object key, Object value) 55 { 56 Object obj = delegate.put(key, value); 57 keys.add(key); 58 return obj; 59 } 60 61 public Object remove(Object key) 62 { 63 Object obj = delegate.remove(key); 64 keys.remove(key); 65 return obj; 66 } 67 68 public void putAll(Map t) 69 { 70 Iterator it = t.keySet().iterator(); 71 while (it.hasNext()) 72 { 73 Object key = it.next(); 74 Object val = t.get(key); 75 put(key, val); 76 } 77 } 78 79 public void clear() 80 { 81 delegate.clear(); 82 keys.clear(); 83 } 84 85 public Set keySet() 86 { 87 OrderedSet set = new OrderedSet(); 88 set.addAll(keys); 89 return set; 90 } 91 92 public Collection values() 93 { 94 ArrayList list = new ArrayList (); 95 Iterator it = keySet().iterator(); 96 while (it.hasNext()) 97 { 98 Object key = it.next(); 99 Object val = get(key); 100 list.add(val); 101 } 102 return list; 103 } 104 105 public Set entrySet() 106 { 107 OrderedSet set = new OrderedSet(); 108 Iterator it = keySet().iterator(); 109 while (it.hasNext()) 110 { 111 Object key = it.next(); 112 Object val = get(key); 113 set.add(new Entry(key, val)); 114 } 115 return set; 116 } 117 118 public static class Entry implements Map.Entry 119 { 120 private Object key; 121 private Object val; 122 123 public Entry(Object key, Object val) 124 { 125 this.key = key; 126 this.val = val; 127 } 128 129 public Object getKey() 130 { 131 return key; 132 } 133 134 public Object getValue() 135 { 136 return val; 137 } 138 139 public Object setValue(Object value) 140 { 141 this.val = value; 142 return val; 143 } 144 } 145 146 public class OrderedSet implements Set 147 { 148 149 private ArrayList delegate = new ArrayList (); 150 151 public int size() 152 { 153 return delegate.size(); 154 } 155 156 public boolean isEmpty() 157 { 158 return delegate.isEmpty(); 159 } 160 161 public boolean contains(Object o) 162 { 163 return delegate.contains(o); 164 } 165 166 public Iterator iterator() 167 { 168 return delegate.iterator(); 169 } 170 171 public Object [] toArray() 172 { 173 return delegate.toArray(); 174 } 175 176 public Object [] toArray(Object a[]) 177 { 178 return delegate.toArray(a); 179 } 180 181 public boolean add(Object o) 182 { 183 return delegate.add(o); 184 } 185 186 public boolean remove(Object o) 187 { 188 return delegate.remove(o); 189 } 190 191 public boolean containsAll(Collection c) 192 { 193 return delegate.containsAll(c); 194 } 195 196 public boolean addAll(Collection c) 197 { 198 return delegate.addAll(c); 199 } 200 201 public boolean retainAll(Collection c) 202 { 203 return delegate.retainAll(c); 204 } 205 206 public boolean removeAll(Collection c) 207 { 208 return delegate.removeAll(c); 209 } 210 211 public void clear() 212 { 213 delegate.clear(); 214 } 215 } 216 } 217 | Popular Tags |