test/java/util/NavigableMap/LockStep.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -234,12 +234,12 @@
             }
         }
         Comparator cmp = comparator(s);
         if (s.isEmpty()) {
             THROWS(NoSuchElementException.class,
-                   new Fun(){void f(){ s.first(); }},
-                   new Fun(){void f(){ s.last();  }});
+                   () -> s.first(),
+                   () -> s.last());
             equal(null, s.lower(1));
             equal(null, s.floor(1));
             equal(null, s.ceiling(1));
             equal(null, s.higher(1));
         } else {

@@ -263,12 +263,11 @@
             s.iterator(),
             s.descendingSet().descendingSet().iterator(),
         };
         for (final Iterator it : its)
             if (maybe(4))
-                THROWS(IllegalStateException.class,
-                       new Fun(){void f(){ it.remove(); }});
+                THROWS(IllegalStateException.class, () -> it.remove());
         Object prev = null;
         for (Object e : s) {
             check(s.contains(e));
             for (Iterator it : its) equalNext(it, e);
             equal(e, s.ceiling(e));

@@ -282,11 +281,11 @@
             prev = e;
         }
         for (final Iterator it : its) {
             if (maybe(2))
                 check(! it.hasNext());
-            Fun fun = new Fun(){void f(){ it.next(); }};
+            Fun fun = () -> it.next();
             THROWS(NoSuchElementException.class, fun, fun, fun);
         }
     }
 
     static void equalIterators(final Iterator<?> it1,

@@ -378,12 +377,12 @@
             equal2(m, serialClone(m));
         equal2(m.keySet(), m.descendingKeySet());
         Comparator cmp = comparator(m);
         if (m.isEmpty()) {
             THROWS(NoSuchElementException.class,
-                   new Fun(){void f(){ m.firstKey(); }},
-                   new Fun(){void f(){ m.lastKey();  }});
+                   () -> m.firstKey(),
+                   () -> m.lastKey());
             equal(null, m.firstEntry());
             equal(null, m.lastEntry());
             equal(null, m.pollFirstEntry());
             equal(null, m.pollLastEntry());
             equal(null, m.lowerKey(1));

@@ -428,12 +427,11 @@
             m.descendingMap().descendingMap().entrySet().iterator(),
         };
         Iterator[] its = concat(kits, vits, eits);
         for (final Iterator it : its)
             if (maybe(4))
-                THROWS(IllegalStateException.class,
-                       new Fun(){void f(){ it.remove(); }});
+                THROWS(IllegalStateException.class, () -> it.remove());
         Map.Entry prev = null;
         for (Map.Entry e : (Set<Map.Entry>) m.entrySet()) {
             Object k = e.getKey();
             Object v = e.getValue();
             check(m.containsKey(k));

@@ -457,11 +455,11 @@
             prev = e;
         }
         for (final Iterator it : its) {
             if (maybe(2))
                 check(! it.hasNext());
-            Fun fun = new Fun(){void f(){ it.next(); }};
+            Fun fun = () -> it.next();
             THROWS(NoSuchElementException.class, fun, fun, fun);
         }
     }
 
     static void equalNavigableMapsLeaf(final NavigableMap m1,

@@ -631,11 +629,11 @@
         if (maybe(2))
             check(! s.remove(e));
     }
 
     static Fun remover(final Iterator it) {
-        return new Fun(){void f(){ it.remove(); }};
+        return () -> it.remove();
     }
 
     static MapFrobber randomRemover(NavigableMap m) {
         final Integer k = usedKey(m);
         final MapFrobber[] randomRemovers = {

@@ -661,21 +659,21 @@
                 while (it.hasNext())
                     if (it.next().equals(k)) {
                         it.remove();
                         if (maybe(2))
                             THROWS(IllegalStateException.class,
-                                   new Fun(){void f(){ it.remove(); }});
+                                   () -> it.remove());
                     }
                 checkUnusedKey(m, k);}},
             new MapFrobber() {void frob(NavigableMap m) {
                 final Iterator it = m.navigableKeySet().descendingIterator();
                 while (it.hasNext())
                     if (it.next().equals(k)) {
                         it.remove();
                         if (maybe(2))
                             THROWS(IllegalStateException.class,
-                                   new Fun(){void f(){ it.remove(); }});
+                                   () -> it.remove());
                     }
                 checkUnusedKey(m, k);}},
             new MapFrobber() {void frob(NavigableMap m) {
                 final Iterator<Map.Entry> it = m.entrySet().iterator();
                 while (it.hasNext())

@@ -716,31 +714,31 @@
                 while (it.hasNext())
                     if (it.next().equals(e)) {
                         it.remove();
                         if (maybe(2))
                             THROWS(IllegalStateException.class,
-                                   new Fun(){void f(){ it.remove(); }});
+                                   () -> it.remove());
                     }
                 checkUnusedElt(s, e);}},
             new SetFrobber() {void frob(NavigableSet s) {
                 final Iterator it = s.descendingSet().iterator();
                 while (it.hasNext())
                     if (it.next().equals(e)) {
                         it.remove();
                         if (maybe(2))
                             THROWS(IllegalStateException.class,
-                                   new Fun(){void f(){ it.remove(); }});
+                                   () -> it.remove());
                     }
                 checkUnusedElt(s, e);}},
             new SetFrobber() {void frob(NavigableSet s) {
                 final Iterator it = s.descendingIterator();
                 while (it.hasNext())
                     if (it.next().equals(e)) {
                         it.remove();
                         if (maybe(2))
                             THROWS(IllegalStateException.class,
-                                   new Fun(){void f(){ it.remove(); }});
+                                   () -> it.remove());
                     }
                 checkUnusedElt(s, e);}}
         };
 
         return randomRemovers[rnd.nextInt(randomRemovers.length)];

@@ -767,16 +765,16 @@
             equalNavigableMaps(m1, m2);
         }
         for (final NavigableMap m : maps) {
             final Object e = usedKey(m);
             THROWS(IllegalArgumentException.class,
-                   new Fun(){void f(){m.subMap(e,true,e,false)
-                                       .subMap(e,true,e,true);}},
-                   new Fun(){void f(){m.subMap(e,false,e,true)
-                                       .subMap(e,true,e,true);}},
-                   new Fun(){void f(){m.tailMap(e,false).tailMap(e,true);}},
-                   new Fun(){void f(){m.headMap(e,false).headMap(e,true);}});
+                   () -> {m.subMap(e,true,e,false)
+                           .subMap(e,true,e,true);},
+                   () -> {m.subMap(e,false,e,true)
+                           .subMap(e,true,e,true);},
+                   () -> m.tailMap(e,false).tailMap(e,true),
+                   () -> m.headMap(e,false).headMap(e,true));
         }
         //System.out.printf("%s%n", m1);
         for (int i = size; i > 0; i--) {
             MapFrobber remover = randomRemover(m1);
             for (final NavigableMap m : maps) {

@@ -809,16 +807,16 @@
             equalNavigableSets(s1, s2);
         }
         for (final NavigableSet s : sets) {
             final Object e = usedElt(s);
             THROWS(IllegalArgumentException.class,
-                   new Fun(){void f(){s.subSet(e,true,e,false)
-                                       .subSet(e,true,e,true);}},
-                   new Fun(){void f(){s.subSet(e,false,e,true)
-                                       .subSet(e,true,e,true);}},
-                   new Fun(){void f(){s.tailSet(e,false).tailSet(e,true);}},
-                   new Fun(){void f(){s.headSet(e,false).headSet(e,true);}});
+                   () -> {s.subSet(e,true,e,false)
+                           .subSet(e,true,e,true);},
+                   () -> {s.subSet(e,false,e,true)
+                           .subSet(e,true,e,true);},
+                   () -> s.tailSet(e,false).tailSet(e,true),
+                   () -> s.headSet(e,false).headSet(e,true));
         }
         //System.out.printf("%s%n", s1);
         for (int i = size; i > 0; i--) {
             SetFrobber remover = randomRemover(s1);
             for (final NavigableSet s : sets) {

@@ -845,11 +843,11 @@
         try { realMain(args); } catch (Throwable t) { unexpected(t); }
 
         System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
         if (failed > 0) throw new Exception("Some tests failed");
     }
-    static abstract class Fun {abstract void f() throws Throwable;}
+    @FunctionalInterface interface Fun {void f() throws Throwable;}
     static void THROWS(Class<? extends Throwable> k, Fun... fs) {
           for (Fun f : fs)
               try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
               catch (Throwable t) {
                   if (k.isAssignableFrom(t.getClass())) pass();