--- old/src/share/classes/java/util/LinkedHashMap.java 2013-12-10 15:26:40.214590058 -0800
+++ new/src/share/classes/java/util/LinkedHashMap.java 2013-12-10 15:26:39.990590047 -0800
@@ -28,7 +28,6 @@
import java.util.function.Consumer;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
-import java.io.Serializable;
import java.io.IOException;
/**
@@ -63,14 +62,17 @@
* provided to create a linked hash map whose order of iteration is the order
* in which its entries were last accessed, from least-recently accessed to
* most-recently (access-order). This kind of map is well-suited to
- * building LRU caches. Invoking the put or get method
- * results in an access to the corresponding entry (assuming it exists after
- * the invocation completes). The putAll method generates one entry
- * access for each mapping in the specified map, in the order that key-value
- * mappings are provided by the specified map's entry set iterator. No
- * other methods generate entry accesses. In particular, operations on
- * collection-views do not affect the order of iteration of the backing
- * map.
+ * building LRU caches. Invoking the {@code put}, {@code putIfAbsent},
+ * {@code get}, {@code computeIfAbsent} or {@code getOrDefault} methods results
+ * in an access to the corresponding entry (assuming it exists after the
+ * invocation completes). Invoking the {@code replace}, {@code merge},
+ * {@code compute} or {@code computeIfPresent} methods results in one or more
+ * accesses of the corresponding entry. The {@code putAll} method generates one
+ * entry access for each mapping in the specified map, in the order that
+ * key-value mappings are provided by the specified map's entry set iterator.
+ * No other methods generate entry accesses. In particular, operations
+ * on collection-views do not affect the order of iteration of the
+ * backing map.
*
*
The {@link #removeEldestEntry(Map.Entry)} method may be overridden to
* impose a policy for removing stale mappings automatically when new mappings
@@ -443,8 +445,19 @@
}
/**
- * Removes all of the mappings from this map.
- * The map will be empty after this call returns.
+ * {@inheritDoc}
+ */
+ public V getOrDefault(Object key, V defaultValue) {
+ Node e;
+ if ((e = getNode(hash(key), key)) == null)
+ return defaultValue;
+ if (accessOrder)
+ afterNodeAccess(e);
+ return e.value;
+ }
+
+ /**
+ * {@inheritDoc}
*/
public void clear() {
super.clear();
--- old/test/java/util/LinkedHashMap/Basic.java 2013-12-10 15:26:41.186590105 -0800
+++ new/test/java/util/LinkedHashMap/Basic.java 2013-12-10 15:26:40.950590094 -0800
@@ -23,28 +23,29 @@
/**
* @test
- * @bug 4245809
+ * @bug 4245809 8029795
* @summary Basic test for LinkedHashMap. (Based on MapBash)
*/
import java.util.*;
+import java.util.function.*;
import java.io.*;
public class Basic {
- static Random rnd = new Random(666);
- static Object nil = new Integer(0);
+ final static Random rnd = new Random(666);
+ final static Integer nil = new Integer(0);
public static void main(String[] args) throws Exception {
int numItr = 500;
int mapSize = 500;
- // Linked List test
+ // Linked List testk
for (int i=0; i m = new LinkedHashMap();
+ Integer head = nil;
for (int j=0; j m2 = new LinkedHashMap(); m2.putAll(m);
m2.values().removeAll(m.keySet());
if (m2.size()!= 1 || !m2.containsValue(nil))
throw new Exception("Collection views test failed.");
@@ -66,7 +67,7 @@
while (head != nil) {
if (!m.containsKey(head))
throw new Exception("Linked list doesn't contain a link.");
- Object newHead = m.get(head);
+ Integer newHead = m.get(head);
if (newHead == null)
throw new Exception("Could not retrieve a link.");
m.remove(head);
@@ -79,7 +80,7 @@
throw new Exception("Linked list size not as expected.");
}
- Map m = new LinkedHashMap();
+ Map m = new LinkedHashMap();
for (int i=0; i m2 = new LinkedHashMap(); m2.putAll(m);
if (!m.equals(m2))
throw new Exception("Clone not equal to original. (1)");
if (!m2.equals(m))
throw new Exception("Clone not equal to original. (2)");
- Set s = m.entrySet(), s2 = m2.entrySet();
+ Set> s = m.entrySet(), s2 = m2.entrySet();
if (!s.equals(s2))
throw new Exception("Clone not equal to original. (3)");
if (!s2.equals(s))
@@ -137,7 +138,7 @@
// Test ordering properties with insert order
m = new LinkedHashMap();
- List l = new ArrayList(mapSize);
+ List l = new ArrayList(mapSize);
for (int i=0; i l2 = new ArrayList(l);
Collections.shuffle(l2);
for (int i=0; i f = (Integer y, Integer z) -> {
+ if (!Objects.equals(y,z))
+ throw new RuntimeException("unequal " + y + "," + z);
+ return new Integer(z);
+ };
+
+ for (int i=0; i