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