--- old/src/com/sun/javatest/util/PrefixMap.java 2018-06-19 01:10:18.000000000 +0100 +++ new/src/com/sun/javatest/util/PrefixMap.java 2018-06-19 01:10:17.000000000 +0100 @@ -38,7 +38,7 @@ * A map whose entries are stored in a parent map by prefixing * the key names with a specific string. */ -public class PrefixMap implements Map +public class PrefixMap implements Map { /** * Create a map whose entries are stored in a parent map @@ -47,14 +47,14 @@ * @param prefix the prefix with which to prefix the entries in the * parent map */ - public PrefixMap(Map map, String prefix) { + 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()); + for (Iterator i = map.keySet().iterator(); i.hasNext(); ) { + String key = i.next(); if (key.startsWith(prefix)) i.remove(); } @@ -80,27 +80,27 @@ } 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()); + for (Iterator> i = map.entrySet().iterator(); i.hasNext(); ) { + Map.Entry e = i.next(); + String key = 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()); + public Set> entrySet() { + Map m = new HashMap(); + for (Iterator> i = map.entrySet().iterator(); i.hasNext(); ) { + Map.Entry e = i.next(); + String key = e.getKey(); if (key.startsWith(prefix)) m.put(key.substring(prefix.length()), e.getValue()); } return m.entrySet(); } - public Object get(Object key) { + public V get(Object key) { return map.get(prefix + key); } @@ -109,37 +109,37 @@ } public boolean isEmpty() { - for (Iterator i = map.keySet().iterator(); i.hasNext(); ) { - String key = (String) (i.next()); + for (Iterator i = map.keySet().iterator(); i.hasNext(); ) { + String key = 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()); + public Set keySet() { + Set s = new HashSet<>(); + for (Iterator i = map.keySet().iterator(); i.hasNext(); ) { + String key = i.next(); if (key.startsWith(prefix)) s.add(key.substring(prefix.length())); } return s; } - public Object put(Object key, Object value) { + public V put(String key, V 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()); + + public void putAll(Map t) { + for (Iterator> i = t.entrySet().iterator(); i.hasNext(); ) { + Map.Entry e = i.next(); + String key = e.getKey(); put(key, e.getValue()); } } - public Object remove(Object key) { + public V remove(Object key) { return map.remove(prefix + key); } @@ -153,10 +153,10 @@ return n; } - public Collection values() { - Collection c = new Vector(); - for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) { - Map.Entry e = (Map.Entry) (i.next()); + public Collection values() { + Collection c = new Vector<>(); + for (Iterator> i = map.entrySet().iterator(); i.hasNext(); ) { + Map.Entry e = i.next(); String key = (String) (e.getKey()); if (key.startsWith(prefix)) c.add(e.getValue()); @@ -164,6 +164,6 @@ return c; } - private Map map; + private Map map; private String prefix; }