ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/NavigableSetCheck.java
(Generate patch)

Comparing jsr166/src/test/loops/NavigableSetCheck.java (file contents):
Revision 1.7 by jsr166, Wed Sep 1 07:47:27 2010 UTC vs.
Revision 1.14 by jsr166, Sun Oct 23 03:03:24 2016 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6   /**
7   * @test
8   * @synopsis Times and checks basic set operations
9   */
10 import java.util.*;
10   import java.io.*;
11 + import java.util.*;
12  
13   public class NavigableSetCheck {
14  
# Line 25 | Line 25 | public class NavigableSetCheck {
25      }
26  
27      public static void main(String[] args) throws Exception {
28 <        Class setClass = null;
28 >        Class<?> setClass = null;
29          int numTests = 50;
30          int size = 50000;
31  
# Line 37 | Line 37 | public class NavigableSetCheck {
37              }
38          }
39  
40
40          if (args.length > 1)
41              numTests = Integer.parseInt(args[1]);
42  
# Line 46 | Line 45 | public class NavigableSetCheck {
45  
46          System.out.println("Testing " + setClass.getName() + " trials: " + numTests + " size: " + size);
47  
49
48          absentSize = 8;
49          while (absentSize < size) absentSize <<= 1;
50          absentMask = absentSize - 1;
# Line 59 | Line 57 | public class NavigableSetCheck {
57          for (int i = 0; i < size; ++i)
58              key[i] = new Integer(i * 2 + 1);
59  
62
60          for (int rep = 0; rep < numTests; ++rep) {
61              runTest(newSet(setClass), key);
62          }
63  
64          TestTimer.printStats();
68
65      }
66  
67 <    static NavigableSet newSet(Class cl) {
67 >    static NavigableSet newSet(Class<?> cl) {
68          try {
69 <            NavigableSet m = (NavigableSet) cl.newInstance();
74 <            return m;
69 >            return (NavigableSet) cl.getConstructor().newInstance();
70          } catch (Exception e) {
71              throw new RuntimeException("Can't instantiate " + cl + ": " + e);
72          }
73      }
74  
80
75      static void runTest(NavigableSet s, Integer[] key) {
76          shuffle(key);
77          int size = key.length;
# Line 171 | Line 165 | public class NavigableSetCheck {
165          reallyAssert(sum == expect);
166      }
167  
174
168      static void higherTest(NavigableSet s) {
169          int sum = 0;
170          int iters = s.size();
# Line 226 | Line 219 | public class NavigableSetCheck {
219          reallyAssert(sum == iters-1);
220      }
221  
229
222      static void ktest(NavigableSet s, int size, Integer[] key) {
223          timer.start("Contains               ", size);
224          int sum = 0;
# Line 237 | Line 229 | public class NavigableSetCheck {
229          reallyAssert(sum == size);
230      }
231  
240
232      static void ittest1(NavigableSet s, int size) {
233          int sum = 0;
234          timer.start("Iter Key               ", size);
# Line 268 | Line 259 | public class NavigableSetCheck {
259          rittest1(s, size);
260      }
261  
271
262      static void rtest(NavigableSet s, int size) {
263          timer.start("Remove (iterator)      ", size);
264          for (Iterator it = s.iterator(); it.hasNext(); ) {
# Line 278 | Line 268 | public class NavigableSetCheck {
268          timer.finish();
269      }
270  
281
282
271      static void dtest(NavigableSet s, int size, Integer[] key) {
272          timer.start("Add (addAll)           ", size * 2);
273 <        NavigableSet s2 = null;
273 >        final NavigableSet s2;
274          try {
275 <            s2 = (NavigableSet) (s.getClass().newInstance());
275 >            s2 = (NavigableSet) s.getClass().getConstructor().newInstance();
276              s2.addAll(s);
277          }
278          catch (Exception e) { e.printStackTrace(); return; }
# Line 329 | Line 317 | public class NavigableSetCheck {
317          reallyAssert(s2.isEmpty() && s.isEmpty());
318      }
319  
332
333
320      static void test(NavigableSet s, Integer[] key) {
321          int size = key.length;
322  
# Line 391 | Line 377 | public class NavigableSetCheck {
377              startTime = System.currentTimeMillis();
378          }
379  
394
380          String classify() {
381              if (name.startsWith("Contains"))
382                  return "Contains               ";
# Line 447 | Line 432 | public class NavigableSetCheck {
432  
433      static void shuffle(Integer[] keys) {
434          int size = keys.length;
435 <        for (int i=size; i>1; i--) {
435 >        for (int i = size; i > 1; i--) {
436              int r = rng.nextInt(i);
437              Integer t = keys[i-1];
438              keys[i-1] = keys[r];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines