KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > core > util > OrderRetainingMap


1 package com.thoughtworks.xstream.core.util;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.ArrayList JavaDoc;
6 import java.util.Collection JavaDoc;
7 import java.util.Collections JavaDoc;
8 import java.util.Set JavaDoc;
9 import java.util.TreeSet JavaDoc;
10
11 public class OrderRetainingMap extends HashMap JavaDoc {
12
13     private Set JavaDoc keyOrder = new ArraySet();
14     private List JavaDoc valueOrder = new ArrayList JavaDoc();
15     
16     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
17         keyOrder.add(key);
18         valueOrder.add(value);
19         return super.put(key, value);
20     }
21
22     public Collection JavaDoc values() {
23         return Collections.unmodifiableList(valueOrder);
24     }
25
26     public Set JavaDoc keySet() {
27         return Collections.unmodifiableSet(keyOrder);
28     }
29
30     public Set JavaDoc entrySet() {
31         throw new UnsupportedOperationException JavaDoc();
32     }
33
34     private static class ArraySet extends ArrayList JavaDoc implements Set JavaDoc {
35     }
36
37 }
38
Popular Tags