< prev index next >
src/com/sun/javatest/util/PrefixMap.java
Print this page
*** 36,62 ****
/**
* A map whose entries are stored in a parent map by prefixing
* the key names with a specific string.
*/
! public class PrefixMap implements Map
{
/**
* Create a map whose entries are stored in a parent map
* by prefixing the key names with a specific string.
* @param map the parent map
* @param prefix the prefix with which to prefix the entries in the
* parent map
*/
! public PrefixMap(Map map, String prefix) {
this.map = map;
this.prefix = prefix + ".";
}
public void clear() {
! for (Iterator i = map.keySet().iterator(); i.hasNext(); ) {
! String key = (String) (i.next());
if (key.startsWith(prefix))
i.remove();
}
}
--- 36,62 ----
/**
* A map whose entries are stored in a parent map by prefixing
* the key names with a specific string.
*/
! public class PrefixMap<V> implements Map<String, V>
{
/**
* Create a map whose entries are stored in a parent map
* by prefixing the key names with a specific string.
* @param map the parent map
* @param prefix the prefix with which to prefix the entries in the
* parent map
*/
! public PrefixMap(Map<String, V> map, String prefix) {
this.map = map;
this.prefix = prefix + ".";
}
public void clear() {
! for (Iterator<String> i = map.keySet().iterator(); i.hasNext(); ) {
! String key = i.next();
if (key.startsWith(prefix))
i.remove();
}
}
*** 78,147 ****
public boolean containsKey(Object key) {
return map.containsKey(prefix + key);
}
public boolean containsValue(Object value) {
! for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) {
! Map.Entry e = (Map.Entry) (i.next());
! String key = (String) (e.getKey());
if (key.startsWith(prefix) && e.getValue().equals(value))
return true;
}
return false;
}
! public Set entrySet() {
! Map m = new HashMap();
! for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) {
! Map.Entry e = (Map.Entry) (i.next());
! String key = (String) (e.getKey());
if (key.startsWith(prefix))
m.put(key.substring(prefix.length()), e.getValue());
}
return m.entrySet();
}
! public Object get(Object key) {
return map.get(prefix + key);
}
public int hashCode() {
return (map.hashCode() + prefix.hashCode());
}
public boolean isEmpty() {
! for (Iterator i = map.keySet().iterator(); i.hasNext(); ) {
! String key = (String) (i.next());
if (key.startsWith(prefix))
return false;
}
return true;
}
! public Set keySet() {
! Set s = new HashSet();
! for (Iterator i = map.keySet().iterator(); i.hasNext(); ) {
! String key = (String) (i.next());
if (key.startsWith(prefix))
s.add(key.substring(prefix.length()));
}
return s;
}
! public Object put(Object key, Object value) {
return map.put(prefix + key, value);
}
! public void putAll(Map t) {
! for (Iterator i = t.entrySet().iterator(); i.hasNext(); ) {
! Map.Entry e = (Map.Entry) (i.next());
! String key = (String) (e.getKey());
put(key, e.getValue());
}
}
! public Object remove(Object key) {
return map.remove(prefix + key);
}
public int size() {
int n = 0;
--- 78,147 ----
public boolean containsKey(Object key) {
return map.containsKey(prefix + key);
}
public boolean containsValue(Object value) {
! for (Iterator<Map.Entry<String, V>> i = map.entrySet().iterator(); i.hasNext(); ) {
! Map.Entry<String, V> e = i.next();
! String key = e.getKey();
if (key.startsWith(prefix) && e.getValue().equals(value))
return true;
}
return false;
}
! public Set<Map.Entry<String, V>> entrySet() {
! Map<String, V> m = new HashMap<String, V>();
! for (Iterator<Map.Entry<String, V>> i = map.entrySet().iterator(); i.hasNext(); ) {
! Map.Entry<String, V> e = i.next();
! String key = e.getKey();
if (key.startsWith(prefix))
m.put(key.substring(prefix.length()), e.getValue());
}
return m.entrySet();
}
! public V get(Object key) {
return map.get(prefix + key);
}
public int hashCode() {
return (map.hashCode() + prefix.hashCode());
}
public boolean isEmpty() {
! for (Iterator<String> i = map.keySet().iterator(); i.hasNext(); ) {
! String key = i.next();
if (key.startsWith(prefix))
return false;
}
return true;
}
! public Set<String> keySet() {
! Set<String> s = new HashSet<>();
! for (Iterator<String> i = map.keySet().iterator(); i.hasNext(); ) {
! String key = i.next();
if (key.startsWith(prefix))
s.add(key.substring(prefix.length()));
}
return s;
}
! public V put(String key, V value) {
return map.put(prefix + key, value);
}
! public void putAll(Map<? extends String, ? extends V> t) {
! for (Iterator<? extends Entry<? extends String, ? extends V>> i = t.entrySet().iterator(); i.hasNext(); ) {
! Map.Entry<? extends String, ? extends V> e = i.next();
! String key = e.getKey();
put(key, e.getValue());
}
}
! public V remove(Object key) {
return map.remove(prefix + key);
}
public int size() {
int n = 0;
*** 151,169 ****
n++;
}
return n;
}
! public Collection values() {
! Collection c = new Vector();
! for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) {
! Map.Entry e = (Map.Entry) (i.next());
String key = (String) (e.getKey());
if (key.startsWith(prefix))
c.add(e.getValue());
}
return c;
}
! private Map map;
private String prefix;
}
--- 151,169 ----
n++;
}
return n;
}
! public Collection<V> values() {
! Collection<V> c = new Vector<>();
! for (Iterator<Map.Entry<String, V>> i = map.entrySet().iterator(); i.hasNext(); ) {
! Map.Entry<String, V> e = i.next();
String key = (String) (e.getKey());
if (key.startsWith(prefix))
c.add(e.getValue());
}
return c;
}
! private Map<String, V> map;
private String prefix;
}
< prev index next >