1 16 package scriptella.util; 17 18 import java.io.IOException ; 19 import java.io.InputStream ; 20 import java.util.Collection ; 21 import java.util.LinkedHashMap ; 22 import java.util.Map ; 23 import java.util.Properties ; 24 import java.util.Set ; 25 26 34 public class PropertiesMap implements Map <String , Object > { 35 private Map <String , Object > props; 36 37 public PropertiesMap() { 38 props = new LinkedHashMap <String , Object >(); 39 } 40 41 public PropertiesMap(int initialCapacity) { 42 props = new LinkedHashMap <String , Object >(initialCapacity); 43 } 44 45 public PropertiesMap(Map <String , ?> props) { 46 this(props.size()); 47 putAll(props); 48 } 49 50 public int size() { 51 return props.size(); 52 } 53 54 public boolean isEmpty() { 55 return props.isEmpty(); 56 } 57 58 public boolean containsKey(Object key) { 59 return props.containsKey(key); 60 } 61 62 public boolean containsValue(Object value) { 63 return props.containsValue(value); 64 } 65 66 public Object get(Object key) { 67 return props.get(key); 68 } 69 70 79 public Object put(String key, Object value) { 80 Object old = props.get(key); 81 if (old==null) { 82 props.put(key, value); 83 } 84 return old; 85 } 86 87 public Object remove(Object key) { 88 return props.remove(key); 89 } 90 91 public void putAll(Map <? extends String , ? extends Object > t) { 92 for (Entry<? extends String , ? extends Object > entry : t.entrySet()) { 93 put(entry.getKey(), entry.getValue()); 94 } 95 } 96 97 public void clear() { 98 props.clear(); 99 } 100 101 public Set <String > keySet() { 102 return props.keySet(); 103 } 104 105 public Collection <Object > values() { 106 return props.values(); 107 } 108 109 public Set <Entry<String , Object >> entrySet() { 110 return props.entrySet(); 111 } 112 113 public boolean equals(Object o) { 114 return props.equals(o); 115 } 116 117 public int hashCode() { 118 return props.hashCode(); 119 } 120 121 128 public void load(InputStream is) throws IOException { 129 Properties tmp = new Properties () { 131 public Object put(final Object k, final Object v) { 132 return PropertiesMap.this.put((String ) k, v); 133 } 134 }; 135 tmp.load(is); 136 } 137 138 139 public String toString() { 140 return String.valueOf(props); 141 } 142 } 143 | Popular Tags |