Index: /luni/src/main/java/java/util/Observable.java =================================================================== --- /luni/src/main/java/java/util/Observable.java (revision 410712) +++ /luni/src/main/java/java/util/Observable.java (working copy) @@ -22,7 +22,7 @@ */ public class Observable { - Vector observers = new Vector(); + Vector observers = new Vector(); boolean changed = false; @@ -107,13 +107,14 @@ * @param data * the argument passed to update() */ - public void notifyObservers(Object data) { + public void notifyObservers(Object data) { if (changed) { // Must clone the vector in case deleteObserver is called - Vector clone = (Vector) observers.clone(); + Vector clone = (Vector)observers.clone(); int size = clone.size(); - for (int i = 0; i < size; i++) - ((Observer) clone.elementAt(i)).update(this, data); + for (int i = 0; i < size; i++) { + clone.elementAt(i).update(this, data); + } clearChanged(); } } Index: /luni/src/main/java/java/util/PropertyResourceBundle.java =================================================================== --- /luni/src/main/java/java/util/PropertyResourceBundle.java (revision 410712) +++ /luni/src/main/java/java/util/PropertyResourceBundle.java (working copy) @@ -29,7 +29,6 @@ * @since 1.1 */ public class PropertyResourceBundle extends ResourceBundle { - //TODO Generify when Properties is generified Properties resources; /** @@ -53,9 +52,9 @@ */ public Enumeration getKeys() { if (parent == null) - return resources.keys(); + return (Enumeration)resources.propertyNames(); return new Enumeration() { - Enumeration local = resources.keys(); + Enumeration local = (Enumeration)resources.propertyNames(); Enumeration pEnum = parent.getKeys(); Index: /luni/src/main/java/java/util/Hashtable.java =================================================================== --- /luni/src/main/java/java/util/Hashtable.java (revision 410712) +++ /luni/src/main/java/java/util/Hashtable.java (working copy) @@ -42,7 +42,7 @@ transient int elementCount; - transient Entry[] elementData; + transient Entry[] elementData; private float loadFactor; @@ -57,12 +57,12 @@ private static final Enumeration emptyEnumerator = new Hashtable(0) .getEmptyEnumerator(); - private static Entry newEntry(Object key, Object value, int hash) { - return new Entry(key, value); + private static Entry newEntry(K key, V value, int hash) { + return new Entry(key, value); } private static class Entry extends MapEntry { - Entry next; + Entry next; final int hashcode; @@ -72,9 +72,9 @@ } public Object clone() { - Entry entry = (Entry) super.clone(); + Entry entry = (Entry) super.clone(); if (next != null) - entry.next = (Entry) next.clone(); + entry.next = (Entry) next.clone(); return entry; } @@ -90,7 +90,7 @@ return key.hashCode(); } - public boolean equalsKey(K aKey, int hash) { + public boolean equalsKey(Object aKey, int hash) { return hashcode == aKey.hashCode() && key.equals(aKey); } @@ -99,18 +99,18 @@ } } - private final class HashIterator implements Iterator { + private final class HashIterator implements Iterator { private int position, expectedModCount; - private MapEntry.Type type; + private final MapEntry.Type type; - private Entry lastEntry; + private Entry lastEntry; private int lastPosition; private boolean canRemove = false; - HashIterator(MapEntry.Type value) { + HashIterator(MapEntry.Type value) { type = value; position = lastSlot; expectedModCount = modCount; @@ -129,7 +129,7 @@ return false; } - public Object next() { + public E next() { if (expectedModCount == modCount) { if (lastEntry != null) { lastEntry = lastEntry.next; @@ -161,7 +161,7 @@ canRemove = false; synchronized (Hashtable.this) { boolean removed = false; - Entry entry = elementData[lastPosition]; + Entry entry = elementData[lastPosition]; if (entry == lastEntry) { elementData[lastPosition] = entry.next; removed = true; @@ -194,12 +194,12 @@ } } - private final class HashEnumerator implements Enumeration { + private final class HashEnumerator implements Enumeration { boolean key; int start; - Entry entry; + Entry entry; HashEnumerator(boolean isKey) { key = isKey; @@ -217,11 +217,11 @@ return false; } - public Object nextElement() { + public E nextElement() { if (hasMoreElements()) { Object result = key ? entry.key : entry.value; entry = entry.next; - return result; + return (E)result; } else throw new NoSuchElementException(); } @@ -244,7 +244,7 @@ public Hashtable(int capacity) { if (capacity >= 0) { elementCount = 0; - elementData = new Entry[capacity == 0 ? 1 : capacity]; + elementData = (Entry[])new Entry[capacity == 0 ? 1 : capacity]; firstSlot = elementData.length; loadFactor = 0.75f; computeMaxSize(); @@ -264,7 +264,7 @@ if (capacity >= 0 && loadFactor > 0) { elementCount = 0; firstSlot = capacity; - elementData = new Entry[capacity == 0 ? 1 : capacity]; + elementData = (Entry[])new Entry[capacity == 0 ? 1 : capacity]; this.loadFactor = loadFactor; computeMaxSize(); } else @@ -278,7 +278,7 @@ * @param map * the mappings to add */ - public Hashtable(Map map) { + public Hashtable(Map map) { this(map.size() < 6 ? 11 : (map.size() * 4 / 3) + 11); putAll(map); } @@ -310,12 +310,12 @@ */ public synchronized Object clone() { try { - Hashtable hashtable = (Hashtable) super.clone(); + Hashtable hashtable = (Hashtable) super.clone(); hashtable.elementData = elementData.clone(); - Entry entry; + Entry entry; for (int i = elementData.length; --i >= 0;) if ((entry = elementData[i]) != null) - hashtable.elementData[i] = (Entry) entry.clone(); + hashtable.elementData[i] = (Entry) entry.clone(); return hashtable; } catch (CloneNotSupportedException e) { return null; @@ -342,7 +342,7 @@ throw new NullPointerException(); for (int i = elementData.length; --i >= 0;) { - Entry entry = elementData[i]; + Entry entry = elementData[i]; while (entry != null) { if (value.equals(entry.value)) return true; @@ -390,16 +390,16 @@ * @see #size * @see Enumeration */ - public synchronized Enumeration elements() { + public synchronized Enumeration elements() { if (elementCount == 0) return emptyEnumerator; - return new HashEnumerator(false); + return new HashEnumerator(false); } /** * Answers a Set of the mappings contained in this Hashtable. Each element * in the set is a Map.Entry. The set is backed by this Hashtable so changes - * to one are relected by the other. The set does not support adding. + * to one are reflected by the other. The set does not support adding. * * @return a Set of the mappings */ @@ -415,20 +415,20 @@ public boolean remove(Object object) { if (contains(object)) { - Hashtable.this.remove(((Map.Entry)object).getKey()); + Hashtable.this.remove(((Map.Entry)object).getKey()); return true; } return false; } public boolean contains(Object object) { - Entry entry = getEntry(((Map.Entry)object).getKey()); + Entry entry = getEntry(((Map.Entry)object).getKey()); return object.equals(entry); } - public Iterator iterator() { - return new HashIterator(new MapEntry.Type() { - public Object get(MapEntry entry) { + public Iterator> iterator() { + return new HashIterator>(new MapEntry.Type, K, V>() { + public Map.Entry get(MapEntry entry) { return entry; } }); @@ -452,16 +452,17 @@ if (this == object) return true; if (object instanceof Map) { - Map map = (Map) object; + Map map = (Map) object; if (size() != map.size()) return false; - - Set objectSet = map.entrySet(); - Iterator it = entrySet().iterator(); - while (it.hasNext()) - if (!objectSet.contains(it.next())) - return false; - return true; + + Set> entries = entrySet(); + for (Map.Entry e : map.entrySet()) { + if (!entries.contains(e)) { + return false; + } + } + return true; } return false; } @@ -479,7 +480,7 @@ public synchronized V get(Object key) { int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % elementData.length; - Entry entry = elementData[index]; + Entry entry = elementData[index]; while (entry != null) { if (entry.equalsKey(key, hash)) return entry.value; @@ -488,10 +489,10 @@ return null; } - Entry getEntry(Object key) { + Entry getEntry(Object key) { int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % elementData.length; - Entry entry = elementData[index]; + Entry entry = elementData[index]; while (entry != null) { if (entry.equalsKey(key, hash)) return entry; @@ -510,9 +511,9 @@ */ public synchronized int hashCode() { int result = 0; - Iterator it = entrySet().iterator(); + Iterator> it = entrySet().iterator(); while (it.hasNext()) { - Map.Entry entry = (Map.Entry) it.next(); + Map.Entry entry = it.next(); Object key = entry.getKey(); Object value = entry.getValue(); int hash = (key != this ? key.hashCode() : 0) @@ -545,20 +546,20 @@ * @see #size * @see Enumeration */ - public synchronized Enumeration keys() { + public synchronized Enumeration keys() { if (elementCount == 0) return emptyEnumerator; - return new HashEnumerator(true); + return new HashEnumerator(true); } /** * Answers a Set of the keys contained in this Hashtable. The set is backed - * by this Hashtable so changes to one are relected by the other. The set + * by this Hashtable so changes to one are reflected by the other. The set * does not support adding. * * @return a Set of the keys */ - public Set keySet() { + public Set keySet() { return new Collections.SynchronizedSet( new AbstractSet() { public boolean contains(Object object) { @@ -582,10 +583,10 @@ } public Iterator iterator() { - return new HashIterator( - new MapEntry.Type() { - public K get(MapEntry entry) { - return (K)entry.key; + return new HashIterator( + new MapEntry.Type() { + public K get(MapEntry entry) { + return entry.key; } }); } @@ -660,16 +661,16 @@ length = 1; int newFirst = length; int newLast = -1; - Entry[] newData = new Entry[length]; + Entry[] newData = (Entry[])new Entry[length]; for (int i = lastSlot + 1; --i >= firstSlot;) { - Entry entry = elementData[i]; + Entry entry = elementData[i]; while (entry != null) { int index = (entry.getKeyHash() & 0x7FFFFFFF) % length; if (index < newFirst) newFirst = index; if (index > newLast) newLast = index; - Entry next = entry.next; + Entry next = entry.next; entry.next = newData[index]; newData[index] = entry; entry = next; @@ -695,8 +696,8 @@ public synchronized V remove(Object key) { int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % elementData.length; - Entry last = null; - Entry entry = elementData[index]; + Entry last = null; + Entry entry = elementData[index]; while (entry != null && !entry.equalsKey(key, hash)) { last = entry; entry = entry.next; @@ -736,10 +737,10 @@ if (isEmpty()) return "{}"; - StringBuffer buffer = new StringBuffer(size() * 28); + StringBuilder buffer = new StringBuilder(size() * 28); buffer.append('{'); for (int i = lastSlot; i >= firstSlot; i--) { - Entry entry = elementData[i]; + Entry entry = elementData[i]; while (entry != null) { if (entry.key != this) { buffer.append(entry.key); @@ -771,7 +772,7 @@ * @return a Collection of the values */ public Collection values() { - return new Collections.SynchronizedCollection(new AbstractCollection() { + return new Collections.SynchronizedCollection(new AbstractCollection() { public boolean contains(Object object) { return Hashtable.this.contains(object); } @@ -784,9 +785,9 @@ Hashtable.this.clear(); } - public Iterator iterator() { - return new HashIterator(new MapEntry.Type() { - public Object get(MapEntry entry) { + public Iterator iterator() { + return new HashIterator(new MapEntry.Type() { + public V get(MapEntry entry) { return entry.value; } }); @@ -800,7 +801,7 @@ stream.writeInt(elementData.length); stream.writeInt(elementCount); for (int i = elementData.length; --i >= 0;) { - Entry entry = elementData[i]; + Entry entry = elementData[i]; while (entry != null) { stream.writeObject(entry.key); stream.writeObject(entry.value); @@ -813,7 +814,7 @@ ClassNotFoundException { stream.defaultReadObject(); int length = stream.readInt(); - elementData = new Entry[length]; + elementData = (Entry[])new Entry[length]; elementCount = stream.readInt(); for (int i = elementCount; --i >= 0;) { Object key = stream.readObject(); @@ -823,7 +824,7 @@ firstSlot = index; if (index > lastSlot) lastSlot = index; - Entry entry = newEntry(key, stream.readObject(), hash); + Entry entry = newEntry((K)key, (V)stream.readObject(), hash); entry.next = elementData[index]; elementData[index] = entry; } Index: /luni/src/main/java/java/util/MapEntry.java =================================================================== --- /luni/src/main/java/java/util/MapEntry.java (revision 410712) +++ /luni/src/main/java/java/util/MapEntry.java (working copy) @@ -49,7 +49,7 @@ if (this == object) return true; if (object instanceof Map.Entry) { - Map.Entry entry = (Map.Entry) object; + Map.Entry entry = (Map.Entry) object; return (key == null ? entry.getKey() == null : key.equals(entry .getKey())) && (value == null ? entry.getValue() == null : value Index: /luni/src/main/java/java/util/Dictionary.java =================================================================== --- /luni/src/main/java/java/util/Dictionary.java (revision 410712) +++ /luni/src/main/java/java/util/Dictionary.java (working copy) @@ -21,6 +21,7 @@ * associate keys with values, such as Hashtable. * * @see Hashtable + * @since 1.0 */ public abstract class Dictionary { /** @@ -40,7 +41,7 @@ * @see #size * @see Enumeration */ - abstract public Enumeration elements(); + public abstract Enumeration elements(); /** * Answers the value associated with key. @@ -52,7 +53,7 @@ * * @see #put */ - abstract public V get(Object key); + public abstract V get(Object key); /** * Answers if this Dictionary has no key/value pairs, a size of zero. @@ -61,7 +62,7 @@ * * @see #size */ - abstract public boolean isEmpty(); + public abstract boolean isEmpty(); /** * Answers an Enumeration on the keys of this Dictionary. @@ -72,7 +73,7 @@ * @see #size * @see Enumeration */ - abstract public Enumeration keys(); + public abstract Enumeration keys(); /** * Associate key with value in this @@ -92,7 +93,7 @@ * @see #get * @see #keys */ - abstract public V put(K key, V value); + public abstract V put(K key, V value); /** * Remove the key/value pair with the specified key from this @@ -106,7 +107,7 @@ * @see #get * @see #put */ - abstract public V remove(Object key); + public abstract V remove(Object key); /** * Answers the number of key/value pairs in this Dictionary. @@ -116,5 +117,5 @@ * @see #elements * @see #keys */ - abstract public int size(); + public abstract int size(); } Index: /luni/src/main/java/java/util/Properties.java =================================================================== --- /luni/src/main/java/java/util/Properties.java (revision 410712) +++ /luni/src/main/java/java/util/Properties.java (working copy) @@ -64,7 +64,7 @@ defaults = properties; } - private void dumpString(StringBuffer buffer, String string, boolean key) { + private void dumpString(StringBuilder buffer, String string, boolean key) { int i = 0; if (!key && i < string.length() && string.charAt(i) == ' ') { buffer.append("\\ "); //$NON-NLS-1$ @@ -153,7 +153,7 @@ if (out == null) throw new NullPointerException(); StringBuffer buffer = new StringBuffer(80); - Enumeration keys = propertyNames(); + Enumeration keys = propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); buffer.append(key); @@ -185,7 +185,7 @@ if (writer == null) throw new NullPointerException(); StringBuffer buffer = new StringBuffer(80); - Enumeration keys = propertyNames(); + Enumeration keys = propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); buffer.append(key); @@ -365,12 +365,12 @@ * * @return an Enumeration containing the names of all properties */ - public Enumeration propertyNames() { + public Enumeration propertyNames() { if (defaults == null) return keys(); - Hashtable set = new Hashtable(defaults.size() + size()); - Enumeration keys = defaults.propertyNames(); + Hashtable set = new Hashtable(defaults.size() + size()); + Enumeration keys = defaults.propertyNames(); while (keys.hasMoreElements()) { set.put(keys.nextElement(), set); } @@ -435,18 +435,23 @@ */ public synchronized void store(OutputStream out, String comment) throws IOException { - if (lineSeparator == null) + if (lineSeparator == null) { lineSeparator = (String) AccessController .doPrivileged(new PriviAction("line.separator")); //$NON-NLS-1$ + } - StringBuffer buffer = new StringBuffer(200); + StringBuilder buffer = new StringBuilder(200); OutputStreamWriter writer = new OutputStreamWriter(out, "ISO8859_1"); //$NON-NLS-1$ - if (comment != null) - writer.write("#" + comment + lineSeparator); //$NON-NLS-1$ - writer.write("#" + new Date() + lineSeparator); //$NON-NLS-1$ - Iterator entryItr = entrySet().iterator(); - while (entryItr.hasNext()) { - MapEntry entry = (MapEntry) entryItr.next(); + if (comment != null) { + writer.write("#"); //$NON-NLS-1$ + writer.write(comment); + writer.write(lineSeparator); + } + writer.write("#"); //$NON-NLS-1$ + writer.write(new Date().toString()); + writer.write(lineSeparator); + + for (Map.Entry entry : entrySet()) { String key = (String) entry.getKey(); dumpString(buffer, key, true); buffer.append('=');