--- jsr166/src/test/loops/MapCheck.java 2009/10/29 23:09:07 1.6 +++ jsr166/src/test/loops/MapCheck.java 2011/12/05 04:08:46 1.14 @@ -1,7 +1,7 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ /** * @test @@ -9,7 +9,7 @@ * * When run with "s" second arg, this requires file "testwords", which * is best used with real words. We can't check in this file, but you - * can create one from a real dictonary (1 line per word) and then run + * can create one from a real dictionary (1 line per word) and then run * linux "shuf" to randomize entries. */ import java.util.*; @@ -40,7 +40,7 @@ public class MapCheck { if (args.length > 0) { try { mapClass = Class.forName(args[0]); - } catch(ClassNotFoundException e) { + } catch (ClassNotFoundException e) { throw new RuntimeException("Class " + args[0] + " not found."); } } @@ -79,7 +79,7 @@ public class MapCheck { Object[] absent = new Object[size]; initializeKeys(key, absent, size); - precheck(size, key, absent); + precheck(size, key, absent); for (int rep = 0; rep < numTests; ++rep) { mainTest(newMap(), key, absent); @@ -99,8 +99,8 @@ public class MapCheck { static Map newMap() { try { - return (Map)mapClass.newInstance(); - } catch(Exception e) { + return (Map) mapClass.newInstance(); + } catch (Exception e) { throw new RuntimeException("Can't instantiate " + mapClass + ": " + e); } } @@ -134,7 +134,7 @@ public class MapCheck { try { m.put(null, x); v = m.get(null); - } catch(NullPointerException npe) { + } catch (NullPointerException npe) { System.out.println("Map does not allow null keys"); return; } @@ -153,7 +153,7 @@ public class MapCheck { ++sum; } timer.finish(); - reallyAssert (sum == expect); + reallyAssert(sum == expect); checkSum += sum; } @@ -164,10 +164,10 @@ public class MapCheck { Map intMap = (Map)s; timer.start(nm, n); for (int i = 0; i < n; i++) { - if ((Integer)(intMap.get(i)) != i) ++sum; + if (intMap.get(i) != i) ++sum; } timer.finish(); - reallyAssert (sum == expect); + reallyAssert(sum == expect); } static void remTest(String nm, int n, Map s, Object[] key, int expect) { @@ -177,7 +177,7 @@ public class MapCheck { if (s.remove(key[i]) != null) ++sum; } timer.finish(); - reallyAssert (sum == expect); + reallyAssert(sum == expect); checkSum += sum; } @@ -186,7 +186,7 @@ public class MapCheck { timer.start(nm, n); s.clear(); timer.finish(); - reallyAssert (s.isEmpty()); + reallyAssert(s.isEmpty()); } static void putTest(String nm, int n, Map s, Object[] key, int expect) { @@ -198,7 +198,7 @@ public class MapCheck { if (v == null) ++sum; } timer.finish(); - reallyAssert (sum == expect); + reallyAssert(sum == expect); checkSum += sum; } @@ -209,7 +209,7 @@ public class MapCheck { if (s.containsKey(key[i])) ++sum; } timer.finish(); - reallyAssert (sum == expect); + reallyAssert(sum == expect); checkSum += sum; } @@ -219,7 +219,7 @@ public class MapCheck { for (int i = 0; i < n; i++) { if (s.containsKey(key[i])) ++sum; } - reallyAssert (sum == expect); + reallyAssert(sum == expect); checkSum += sum; } @@ -230,7 +230,7 @@ public class MapCheck { if (s.remove(key[i]) != null) ++sum; } timer.finish(); - reallyAssert (sum == expect); + reallyAssert(sum == expect); checkSum += sum; } @@ -240,7 +240,7 @@ public class MapCheck { timer.start("Traverse key or value ", size); if (s.containsValue(MISSING)) ++sum; timer.finish(); - reallyAssert (sum == 0); + reallyAssert(sum == 0); checkSum += sum; } @@ -256,7 +256,7 @@ public class MapCheck { last = x; } timer.finish(); - reallyAssert (sum == size); + reallyAssert(sum == size); checkSum += sum; return last; } @@ -272,7 +272,7 @@ public class MapCheck { last = x; } timer.finish(); - reallyAssert (sum == size); + reallyAssert(sum == size); checkSum += sum; return last; } @@ -289,13 +289,13 @@ public class MapCheck { ++sum; } timer.finish(); - reallyAssert (sum == size); + reallyAssert(sum == size); checkSum += sum; } static void itRemTest(Map s, int size) { int sz = s.size(); - reallyAssert (sz == size); + reallyAssert(sz == size); timer.start("Remove Present ", size); int sum = 0; for (Iterator it = s.keySet().iterator(); it.hasNext(); ) { @@ -304,13 +304,13 @@ public class MapCheck { ++sum; } timer.finish(); - reallyAssert (sum == sz); + reallyAssert(sum == sz); checkSum += sum; } static void itHalfRemTest(Map s, int size) { int sz = s.size(); - reallyAssert (sz == size); + reallyAssert(sz == size); timer.start("Remove Present ", size); int sum = 0; for (Iterator it = s.keySet().iterator(); it.hasNext(); ) { @@ -321,7 +321,7 @@ public class MapCheck { ++sum; } timer.finish(); - reallyAssert (sum == sz / 2); + reallyAssert(sum == sz / 2); checkSum += sum; } @@ -329,7 +329,7 @@ public class MapCheck { timer.start(nm, n); dst.putAll(src); timer.finish(); - reallyAssert (src.size() == dst.size()); + reallyAssert(src.size() == dst.size()); } static void serTest(Map s, int size) throws Exception { @@ -350,7 +350,7 @@ public class MapCheck { FileInputStream is = new FileInputStream("MapCheck.dat"); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(is)); - Map m = (Map)in.readObject(); + Map m = (Map) in.readObject(); long endTime = System.currentTimeMillis(); long time = endTime - startTime; @@ -358,7 +358,7 @@ public class MapCheck { System.out.print(time + "ms"); if (s instanceof IdentityHashMap) return; - reallyAssert (s.equals(m)); + reallyAssert(s.equals(m)); } static void mainTest(Map s, Object[] key, Object[] absent) { @@ -426,34 +426,34 @@ public class MapCheck { timer.start("Traverse entry ", size * 12); // 12 until finish int sh1 = s.hashCode() - s2.hashCode(); - reallyAssert (sh1 == 0); + reallyAssert(sh1 == 0); boolean eq1 = s2.equals(s); boolean eq2 = s.equals(s2); - reallyAssert (eq1 && eq2); + reallyAssert(eq1 && eq2); Set es2 = s2.entrySet(); for (Iterator it = s.entrySet().iterator(); it.hasNext(); ) { Object entry = it.next(); if (es2.contains(entry)) ++sum; } - reallyAssert (sum == size); + reallyAssert(sum == size); s2.put(lastkey, MISSING); int sh2 = s.hashCode() - s2.hashCode(); - reallyAssert (sh2 != 0); + reallyAssert(sh2 != 0); eq1 = s2.equals(s); eq2 = s.equals(s2); - reallyAssert (!eq1 && !eq2); + reallyAssert(!eq1 && !eq2); sum = 0; for (Iterator it = s.entrySet().iterator(); it.hasNext(); ) { Map.Entry e = (Map.Entry)it.next(); e.setValue(absent[sum++]); } - reallyAssert (sum == size); + reallyAssert(sum == size); for (Iterator it = s2.entrySet().iterator(); it.hasNext(); ) { Map.Entry e = (Map.Entry)it.next(); e.setValue(s.get(e.getKey())); @@ -473,12 +473,12 @@ public class MapCheck { reallyAssert(rmiss == 0); clrTest(size, s2); - reallyAssert (s2.isEmpty() && s.isEmpty()); + reallyAssert(s2.isEmpty() && s.isEmpty()); } static void itTest4(Map s, int size, int pos) { IdentityHashMap seen = new IdentityHashMap(size); - reallyAssert (s.size() == size); + reallyAssert(s.size() == size); int sum = 0; timer.start("Iter XEntry ", size); Iterator it = s.entrySet().iterator(); @@ -492,9 +492,9 @@ public class MapCheck { if (x != MISSING) ++sum; } - reallyAssert (s.containsKey(k)); + reallyAssert(s.containsKey(k)); it.remove(); - reallyAssert (!s.containsKey(k)); + reallyAssert(!s.containsKey(k)); while (it.hasNext()) { Map.Entry x = (Map.Entry)(it.next()); Object k2 = x.getKey(); @@ -503,12 +503,12 @@ public class MapCheck { ++sum; } - reallyAssert (s.size() == size-1); + reallyAssert(s.size() == size-1); s.put(k, v); - reallyAssert (seen.size() == size); + reallyAssert(seen.size() == size); timer.finish(); - reallyAssert (sum == size); - reallyAssert (s.size() == size); + reallyAssert(sum == size); + reallyAssert(s.size() == size); } @@ -610,7 +610,7 @@ public class MapCheck { abs[ai++] = s; break; } - sb.append((char)c); + sb.append((char) c); } } in.close(); @@ -629,15 +629,15 @@ public class MapCheck { char[] c = new char[len * 4 + 1]; for (int j = 1; j < len; ++j) { int r = srng.next(); - c[k++] = (char)(' ' + (r & 0x7f)); + c[k++] = (char) (' ' + (r & 0x7f)); r >>>= 8; - c[k++] = (char)(' ' + (r & 0x7f)); + c[k++] = (char) (' ' + (r & 0x7f)); r >>>= 8; - c[k++] = (char)(' ' + (r & 0x7f)); + c[k++] = (char) (' ' + (r & 0x7f)); r >>>= 8; - c[k++] = (char)(' ' + (r & 0x7f)); + c[k++] = (char) (' ' + (r & 0x7f)); } - c[k++] = (char)((i & 31) | 1); // never == to any testword + c[k++] = (char) ((i & 31) | 1); // never == to any testword ws[i] = new String(c); } } @@ -651,8 +651,8 @@ public class MapCheck { static void printStats() { for (Iterator it = accum.entrySet().iterator(); it.hasNext(); ) { - Map.Entry e = (Map.Entry)(it.next()); - Stats stats = ((Stats)(e.getValue())); + Map.Entry e = (Map.Entry) it.next(); + Stats stats = (Stats) e.getValue(); System.out.print(e.getKey() + ": "); long s; long n = stats.number; @@ -663,7 +663,7 @@ public class MapCheck { else s = stats.sum; - double t = ((double)s) / n; + double t = ((double) s) / n; long nano = Math.round(t); System.out.printf("%6d", + nano); System.out.println(); @@ -682,7 +682,7 @@ public class MapCheck { if (st == null) accum.put(name, new Stats(elapsed, numOps)); else - ((Stats)st).addTime(elapsed, numOps); + ((Stats) st).addTime(elapsed, numOps); } }