to the end of daily_life
authorJaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 10:04:51 +0200
changeset 2091c999569643b
parent 208 897361847d12
child 210 acf2c31e22d4
to the end of daily_life
samples/composition/src-api1.0/api/Arithmetica.java
samples/composition/src-api2.0-compat/api/Arithmetica.java
samples/composition/src-api2.0-enum/api/Arithmetica.java
samples/composition/src-api2.0-property/api/Arithmetica.java
samples/composition/src-api2.0-runtime/api/Arithmetica.java
samples/composition/src-api2.0/api/Arithmetica.java
samples/composition/src-test/api/ArithmeticaCompatibilityTest.java
samples/composition/src-test/api/ArithmeticaTest.java
samples/composition/src-test/api/FactorialTest.java
samples/consistency/src-api1.0/api/Lookups.java
samples/consistency/src-api2.0/api/Lookup.java
samples/consistency/src-api2.0/api/Lookups.java
samples/deadlock/src/org/apidesign/deadlock/logs/Parallel.java
samples/deadlock/test/org/apidesign/deadlock/logs/ParallelControlFlowTest.java
samples/deadlock/test/org/apidesign/deadlock/logs/ParallelSortedTest.java
samples/deadlock/test/org/apidesign/deadlock/logs/ParallelTest.java
samples/delegatingwriter/src/org/apidesign/delegatingwriter/AltBufferedWriter.java
samples/delegatingwriter/test/org/apidesign/delegatingwriter/CountingWriter.java
samples/delegatingwriter/test/org/apidesign/delegatingwriter/CryptoWriter.java
samples/delegatingwriterfinal/src-api2.0/api/SimpleBuffer.java
samples/delegatingwriterfinal/src-api2.0/api/Writer.java
samples/delegatingwriterfinal/src-test2.0/api/usage/twodotzero/CountingWriter.java
samples/growingparameters/src-api1.0/api/request/response/Compute.java
samples/growingparameters/src-api2.0/api/request/response/Compute.java
samples/instanceof/src/api/InstanceProvider.java
samples/instanceofclass/src-api1.0/api/InstanceProvider.java
samples/instanceofclass/src-api2.0/api/InstanceProvider.java
samples/misuse/src/org/apidesign/misuse/Connection.java
samples/misuse/src/org/apidesign/misuse/projectconfig/ProjectConfigurationCorrect.java
samples/misuse/src/org/apidesign/misuse/projectconfig/ProjectConfigurationOriginal.java
samples/reentrant/src/org/apidesign/reentrant/CriticalSectionReentrant.java
samples/reentrant/src/org/apidesign/reentrant/CriticalSectionReentrantImmutable.java
     1.1 --- a/samples/composition/src-api1.0/api/Arithmetica.java	Sat Jun 14 10:04:50 2008 +0200
     1.2 +++ b/samples/composition/src-api1.0/api/Arithmetica.java	Sat Jun 14 10:04:51 2008 +0200
     1.3 @@ -24,10 +24,6 @@
     1.4      
     1.5      public int sumRange(int from, int to) {
     1.6          int len = to - from;
     1.7 -        if (len < 0) {
     1.8 -            len = -len;
     1.9 -            from = to;
    1.10 -        }
    1.11          int[] array = new int[len + 1];
    1.12          for (int i = 0; i <= len; i++) {
    1.13              array[i] = from + i;
     2.1 --- a/samples/composition/src-api2.0-compat/api/Arithmetica.java	Sat Jun 14 10:04:50 2008 +0200
     2.2 +++ b/samples/composition/src-api2.0-compat/api/Arithmetica.java	Sat Jun 14 10:04:51 2008 +0200
     2.3 @@ -43,10 +43,6 @@
     2.4  
     2.5      private int sumRange1(int from, int to) {
     2.6          int len = to - from;
     2.7 -        if (len < 0) {
     2.8 -            len = -len;
     2.9 -            from = to;
    2.10 -        }
    2.11          int[] array = new int[len + 1];
    2.12          for (int i = 0; i <= len; i++) {
    2.13              array[i] = from + i;
    2.14 @@ -55,7 +51,7 @@
    2.15      }
    2.16      
    2.17      private int sumRange2(int from, int to) {
    2.18 -        return (from + to) * (Math.abs(to - from) + 1) / 2;
    2.19 +        return (from + to) * (to - from + 1) / 2;
    2.20      }
    2.21  }
    2.22  // END: design.composition.arith2.0.compat
     3.1 --- a/samples/composition/src-api2.0-enum/api/Arithmetica.java	Sat Jun 14 10:04:50 2008 +0200
     3.2 +++ b/samples/composition/src-api2.0-enum/api/Arithmetica.java	Sat Jun 14 10:04:51 2008 +0200
     3.3 @@ -49,10 +49,6 @@
     3.4  
     3.5      private int sumRange1(int from, int to) {
     3.6          int len = to - from;
     3.7 -        if (len < 0) {
     3.8 -            len = -len;
     3.9 -            from = to;
    3.10 -        }
    3.11          int[] array = new int[len + 1];
    3.12          for (int i = 0; i <= len; i++) {
    3.13              array[i] = from + i;
    3.14 @@ -61,6 +57,6 @@
    3.15      }
    3.16      
    3.17      private int sumRange2(int from, int to) {
    3.18 -        return (from + to) * (Math.abs(to - from) + 1) / 2;
    3.19 +        return (from + to) * (to - from + 1) / 2;
    3.20      }
    3.21  }
     4.1 --- a/samples/composition/src-api2.0-property/api/Arithmetica.java	Sat Jun 14 10:04:50 2008 +0200
     4.2 +++ b/samples/composition/src-api2.0-property/api/Arithmetica.java	Sat Jun 14 10:04:51 2008 +0200
     4.3 @@ -36,10 +36,6 @@
     4.4  
     4.5      private int sumRange1(int from, int to) {
     4.6          int len = to - from;
     4.7 -        if (len < 0) {
     4.8 -            len = -len;
     4.9 -            from = to;
    4.10 -        }
    4.11          int[] array = new int[len + 1];
    4.12          for (int i = 0; i <= len; i++) {
    4.13              array[i] = from + i;
    4.14 @@ -48,7 +44,7 @@
    4.15      }
    4.16      
    4.17      private int sumRange2(int from, int to) {
    4.18 -        return (from + to) * (Math.abs(to - from) + 1) / 2;
    4.19 +        return (from + to) * (to - from + 1) / 2;
    4.20      }
    4.21  }
    4.22  // END: design.composition.arith2.0.property
     5.1 --- a/samples/composition/src-api2.0-runtime/api/Arithmetica.java	Sat Jun 14 10:04:50 2008 +0200
     5.2 +++ b/samples/composition/src-api2.0-runtime/api/Arithmetica.java	Sat Jun 14 10:04:51 2008 +0200
     5.3 @@ -35,10 +35,6 @@
     5.4  
     5.5      private int sumRange1(int from, int to) {
     5.6          int len = to - from;
     5.7 -        if (len < 0) {
     5.8 -            len = -len;
     5.9 -            from = to;
    5.10 -        }
    5.11          int[] array = new int[len + 1];
    5.12          for (int i = 0; i <= len; i++) {
    5.13              array[i] = from + i;
    5.14 @@ -47,7 +43,7 @@
    5.15      }
    5.16      
    5.17      private int sumRange2(int from, int to) {
    5.18 -        return (from + to) * (Math.abs(to - from) + 1) / 2;
    5.19 +        return (from + to) * (to - from + 1) / 2;
    5.20      }
    5.21  
    5.22      private static boolean calledByV2AwareLoader() {
     6.1 --- a/samples/composition/src-api2.0/api/Arithmetica.java	Sat Jun 14 10:04:50 2008 +0200
     6.2 +++ b/samples/composition/src-api2.0/api/Arithmetica.java	Sat Jun 14 10:04:51 2008 +0200
     6.3 @@ -24,7 +24,7 @@
     6.4      
     6.5  // BEGIN: design.composition.arith2.0
     6.6      public int sumRange(int from, int to) {
     6.7 -        return (from + to) * (Math.abs(to - from) + 1) / 2;
     6.8 +        return (from + to) * (to - from + 1) / 2;
     6.9      }
    6.10  // END: design.composition.arith2.0
    6.11  }
     7.1 --- a/samples/composition/src-test/api/ArithmeticaCompatibilityTest.java	Sat Jun 14 10:04:50 2008 +0200
     7.2 +++ b/samples/composition/src-test/api/ArithmeticaCompatibilityTest.java	Sat Jun 14 10:04:51 2008 +0200
     7.3 @@ -66,15 +66,15 @@
     7.4              compare(now, old, seed);
     7.5          
     7.6              assertEquals(
     7.7 -                "Verify amount calls to of sumRange is the same", 
     7.8 +                "Verify amount of sumRange is the same", 
     7.9                  now.countSumRange, old.countSumRange
    7.10              );
    7.11              assertEquals(
    7.12 -                "Verify amount calls to of sumAll is the same", 
    7.13 +                "Verify amount of sumAll is the same", 
    7.14                  now.countSumAll, old.countSumAll
    7.15              );
    7.16              assertEquals(
    7.17 -                "Verify amount calls to of sumTwo is the same", 
    7.18 +                "Verify amount of sumTwo is the same", 
    7.19                  now.countSumTwo, old.countSumTwo
    7.20              );
    7.21          } catch (AssertionFailedError ex) {
    7.22 @@ -99,15 +99,15 @@
    7.23          compare(now, old, 1208120436947L);
    7.24  
    7.25          assertEquals(
    7.26 -            "Verify amount of calls to sumRange is the same", 
    7.27 +            "Verify amount of sumRange is the same", 
    7.28              now.countSumRange, old.countSumRange
    7.29          );
    7.30          assertEquals(
    7.31 -            "Verify amount of calls to sumAll is the same", 
    7.32 +            "Verify amount of sumAll is the same", 
    7.33              now.countSumAll, old.countSumAll
    7.34          );
    7.35          assertEquals(
    7.36 -            "Verify amount of calls to sumTwo is the same", 
    7.37 +            "Verify amount of sumTwo is the same", 
    7.38              now.countSumTwo, old.countSumTwo
    7.39          );
    7.40      }
    7.41 @@ -119,15 +119,15 @@
    7.42          compare(now, old, 1208120628821L);
    7.43  
    7.44          assertEquals(
    7.45 -            "Verify amount of calls to sumRange is the same", 
    7.46 +            "Verify amount of sumRange is the same", 
    7.47              now.countSumRange, old.countSumRange
    7.48          );
    7.49          assertEquals(
    7.50 -            "Verify amount of calls to sumAll is the same", 
    7.51 +            "Verify amount of sumAll is the same", 
    7.52              now.countSumAll, old.countSumAll
    7.53          );
    7.54          assertEquals(
    7.55 -            "Verify amount of calls to sumTwo is the same", 
    7.56 +            "Verify amount of sumTwo is the same", 
    7.57              now.countSumTwo, old.countSumTwo
    7.58          );
    7.59      }
     8.1 --- a/samples/composition/src-test/api/ArithmeticaTest.java	Sat Jun 14 10:04:50 2008 +0200
     8.2 +++ b/samples/composition/src-test/api/ArithmeticaTest.java	Sat Jun 14 10:04:51 2008 +0200
     8.3 @@ -35,10 +35,8 @@
     8.4  
     8.5      public void testSumRange() {
     8.6          Arithmetica instance = new Arithmetica();
     8.7 -        assertEquals("1+2+3=6", 6, instance.sumRange(1, 3));
     8.8 -        assertEquals("sum(1,10)=55", 55, instance.sumRange(1, 10));
     8.9 -        assertEquals("sum(1,1)=1", 1, instance.sumRange(1, 1));
    8.10 -        assertEquals("sum(10,1)=55", 55, instance.sumRange(10, 1));
    8.11 +        assertEquals("+", 6, instance.sumRange(1, 3));
    8.12 +        assertEquals("10", 55, instance.sumRange(1, 10));
    8.13      }
    8.14      //END: design.composition.arith.test
    8.15  
     9.1 --- a/samples/composition/src-test/api/FactorialTest.java	Sat Jun 14 10:04:50 2008 +0200
     9.2 +++ b/samples/composition/src-test/api/FactorialTest.java	Sat Jun 14 10:04:51 2008 +0200
     9.3 @@ -38,4 +38,22 @@
     9.4      public void testFactorial5() {
     9.5          assertEquals(120, Factorial.factorial(5));
     9.6      }
     9.7 +
     9.8 +    /** Class showing inventive, non-expected use of 
     9.9 +     * Arithmetica methods to do multiplication instead of
    9.10 +     * addition.
    9.11 +     */
    9.12 +    //BEGIN: design.composition.arith.factorial
    9.13 +    public static final class Factorial extends Arithmetica {
    9.14 +        public static int factorial(int n) {
    9.15 +            return new Factorial().sumRange(1, n);
    9.16 +        }
    9.17 +        @Override
    9.18 +        public int sumTwo(int one, int second) {
    9.19 +            return one * second;
    9.20 +        }
    9.21 +    }
    9.22 +    //END: design.composition.arith.factorial
    9.23 +
    9.24 +    
    9.25  }
    10.1 --- a/samples/consistency/src-api1.0/api/Lookups.java	Sat Jun 14 10:04:50 2008 +0200
    10.2 +++ b/samples/consistency/src-api1.0/api/Lookups.java	Sat Jun 14 10:04:51 2008 +0200
    10.3 @@ -1,9 +1,6 @@
    10.4  package api;
    10.5  
    10.6 -import java.util.ArrayList;
    10.7  import java.util.Collection;
    10.8 -import java.util.HashSet;
    10.9 -import java.util.List;
   10.10  import java.util.Set;
   10.11  
   10.12  /** Factory to create various types of lookup instances.
   10.13 @@ -15,39 +12,7 @@
   10.14      private Lookups() {
   10.15      }
   10.16      
   10.17 -    public static Lookup fixed(final Object... instances) {
   10.18 -        return new Lookup() {
   10.19 -            @Override
   10.20 -            public <T> T lookup(Class<T> clazz) {
   10.21 -                for (Object obj : instances) {
   10.22 -                    if (clazz.isInstance(obj)) {
   10.23 -                        return clazz.cast(obj);
   10.24 -                    }
   10.25 -                }
   10.26 -                return null;
   10.27 -            }
   10.28 -
   10.29 -            @Override
   10.30 -            public <T> Collection<? extends T> lookupAll(Class<T> clazz) {
   10.31 -                List<T> result = new ArrayList<T>();
   10.32 -                for (Object obj : instances) {
   10.33 -                    if (clazz.isInstance(obj)) {
   10.34 -                        result.add(clazz.cast(obj));
   10.35 -                    }
   10.36 -                }
   10.37 -                return result;
   10.38 -            }
   10.39 -
   10.40 -            @Override
   10.41 -            public <T> Set<Class<? extends T>> lookupAllClasses(Class<T> clazz) {
   10.42 -                Set<Class<? extends T>> result = new HashSet<Class<? extends T>>();
   10.43 -                for (Object obj : instances) {
   10.44 -                    if (clazz.isInstance(obj)) {
   10.45 -                        result.add(obj.getClass().asSubclass(clazz));
   10.46 -                    }
   10.47 -                }
   10.48 -                return result;
   10.49 -            }
   10.50 -        };
   10.51 +    public static Lookup fixed(Object... instances) {
   10.52 +        return null;
   10.53      }
   10.54  }
    11.1 --- a/samples/consistency/src-api2.0/api/Lookup.java	Sat Jun 14 10:04:50 2008 +0200
    11.2 +++ b/samples/consistency/src-api2.0/api/Lookup.java	Sat Jun 14 10:04:51 2008 +0200
    11.3 @@ -1,11 +1,6 @@
    11.4  package api;
    11.5  
    11.6 -import java.util.ArrayList;
    11.7  import java.util.Collection;
    11.8 -import java.util.Collections;
    11.9 -import java.util.HashSet;
   11.10 -import java.util.Iterator;
   11.11 -import java.util.List;
   11.12  import java.util.Set;
   11.13  
   11.14  /** Simplified version of NetBeans 
   11.15 @@ -18,49 +13,26 @@
   11.16   * @version 2.0
   11.17   */
   11.18  // BEGIN: design.consistency.2.0
   11.19 -public abstract class Lookup {
   11.20 -    /** only for classes in the same package */
   11.21 +public final class Lookup {
   11.22      Lookup() {
   11.23      }
   11.24      
   11.25      // BEGIN: design.consistency.lookup.2.0
   11.26      public <T> T lookup(Class<T> clazz) {
   11.27 -        Iterator<T> it = doLookup(clazz);
   11.28 -        return it.hasNext() ? it.next() : null;
   11.29 +        return null;
   11.30      }
   11.31      // END: design.consistency.lookup.2.0
   11.32  
   11.33      // BEGIN: design.consistency.lookupAll.2.0
   11.34      public <T> Collection<? extends T> lookupAll(Class<T> clazz) {
   11.35 -        Iterator<T> it = doLookup(clazz);
   11.36 -        if (!it.hasNext()) {
   11.37 -            return Collections.emptyList();
   11.38 -        } else {
   11.39 -            List<T> result = new ArrayList<T>();
   11.40 -            while (it.hasNext()) {
   11.41 -                result.add(it.next());
   11.42 -            }
   11.43 -            return result;
   11.44 -        }
   11.45 +        return null;
   11.46      }
   11.47      // END: design.consistency.lookupAll.2.0
   11.48  
   11.49      // BEGIN: design.consistency.lookupAllClasses.2.0
   11.50      public <T> Set<Class<? extends T>> lookupAllClasses(Class<T> clazz) {
   11.51 -        Iterator<T> it = doLookup(clazz);
   11.52 -        if (!it.hasNext()) {
   11.53 -            return Collections.emptySet();
   11.54 -        } else {
   11.55 -            Set<Class<? extends T>> result = 
   11.56 -                new HashSet<Class<? extends T>>();
   11.57 -            while (it.hasNext()) {
   11.58 -                result.add(it.next().getClass().asSubclass(clazz));
   11.59 -            }
   11.60 -            return result;
   11.61 -        }
   11.62 +        return null;
   11.63      }
   11.64      // END: design.consistency.lookupAllClasses.2.0
   11.65 -// FINISH: design.consistency.2.0
   11.66 -    
   11.67 -    abstract <T> Iterator<T> doLookup(Class<T> clazz);
   11.68  }
   11.69 +// END: design.consistency.2.0
   11.70 \ No newline at end of file
    12.1 --- a/samples/consistency/src-api2.0/api/Lookups.java	Sat Jun 14 10:04:50 2008 +0200
    12.2 +++ b/samples/consistency/src-api2.0/api/Lookups.java	Sat Jun 14 10:04:51 2008 +0200
    12.3 @@ -1,8 +1,6 @@
    12.4  package api;
    12.5  
    12.6 -import java.util.ArrayList;
    12.7  import java.util.Collection;
    12.8 -import java.util.Iterator;
    12.9  import java.util.Set;
   12.10  
   12.11  /** Factory to create various types of lookup instances.
   12.12 @@ -14,30 +12,12 @@
   12.13      private Lookups() {
   12.14      }
   12.15      
   12.16 -    public static Lookup fixed(final Object... instances) {
   12.17 -        return new Lookup() {
   12.18 -            @Override
   12.19 -            <T> Iterator<T> doLookup(Class<T> clazz) {
   12.20 -                ArrayList<T> result = new ArrayList<T>();
   12.21 -                for (Object obj : instances) {
   12.22 -                    if (clazz.isInstance(obj)) {
   12.23 -                        result.add(clazz.cast(obj));
   12.24 -                    }
   12.25 -                }
   12.26 -                return result.iterator();
   12.27 -            }
   12.28 -        };
   12.29 +    public static Lookup fixed(Object... instances) {
   12.30 +        return null;
   12.31      }
   12.32      
   12.33 -    public static Lookup dynamic(final Dynamic provider) {
   12.34 -        return new Lookup() {
   12.35 -            @Override
   12.36 -            <T> Iterator<T> doLookup(Class<T> clazz) {
   12.37 -                ArrayList<T> result = new ArrayList<T>();
   12.38 -                provider.computeInstances(clazz, result);
   12.39 -                return result.iterator();
   12.40 -            }
   12.41 -        };
   12.42 +    public static Lookup dynamic(Dynamic provider) {
   12.43 +        return null;
   12.44      }
   12.45      
   12.46      public interface Dynamic {
    13.1 --- a/samples/deadlock/src/org/apidesign/deadlock/logs/Parallel.java	Sat Jun 14 10:04:50 2008 +0200
    13.2 +++ b/samples/deadlock/src/org/apidesign/deadlock/logs/Parallel.java	Sat Jun 14 10:04:51 2008 +0200
    13.3 @@ -5,7 +5,7 @@
    13.4  import java.util.logging.Logger;
    13.5  
    13.6  // BEGIN: test.parallel
    13.7 -class Parallel implements Runnable {
    13.8 +class Parael implements Runnable {
    13.9      public void run() {
   13.10          Random r = new Random();
   13.11          for (int i = 0; i < 10; i++) {
   13.12 @@ -16,8 +16,8 @@
   13.13          }
   13.14      }
   13.15      public static void main(String[] args) throws InterruptedException {
   13.16 -        Thread t1 = new Thread(new Parallel(), "1st");
   13.17 -        Thread t2 = new Thread(new Parallel(), "2nd");
   13.18 +        Thread t1 = new Thread(new Parael(), "1st");
   13.19 +        Thread t2 = new Thread(new Parael(), "2nd");
   13.20          t1.start(); t2.start();
   13.21          t1.join(); t2.join();
   13.22      }
    14.1 --- a/samples/deadlock/test/org/apidesign/deadlock/logs/ParallelControlFlowTest.java	Sat Jun 14 10:04:50 2008 +0200
    14.2 +++ b/samples/deadlock/test/org/apidesign/deadlock/logs/ParallelControlFlowTest.java	Sat Jun 14 10:04:51 2008 +0200
    14.3 @@ -47,7 +47,7 @@
    14.4              "THREAD: 2nd MSG: cnt: 9",
    14.5              500
    14.6          );
    14.7 -        Parallel.main(null);
    14.8 +        Parael.main(null);
    14.9          fail("Ok, just print the logged output");
   14.10      }
   14.11  // END: test.parallel.test.controlflow
   14.12 @@ -61,7 +61,7 @@
   14.13              "THREAD: 1st MSG: cnt: 6",
   14.14              5000
   14.15          );
   14.16 -        Parallel.main(null);
   14.17 +        Parael.main(null);
   14.18          fail("Ok, just print the logged output");
   14.19      }
   14.20      // END: test.parallel.test.fivetwo
    15.1 --- a/samples/deadlock/test/org/apidesign/deadlock/logs/ParallelSortedTest.java	Sat Jun 14 10:04:50 2008 +0200
    15.2 +++ b/samples/deadlock/test/org/apidesign/deadlock/logs/ParallelSortedTest.java	Sat Jun 14 10:04:51 2008 +0200
    15.3 @@ -25,7 +25,7 @@
    15.4  
    15.5      public void testMain() throws Exception {
    15.6          Logger.global.addHandler(new BlockingHandler());
    15.7 -        Parallel.main(null);
    15.8 +        Parael.main(null);
    15.9          fail("Ok, just print the logged output");
   15.10      }
   15.11  
    16.1 --- a/samples/deadlock/test/org/apidesign/deadlock/logs/ParallelTest.java	Sat Jun 14 10:04:50 2008 +0200
    16.2 +++ b/samples/deadlock/test/org/apidesign/deadlock/logs/ParallelTest.java	Sat Jun 14 10:04:51 2008 +0200
    16.3 @@ -21,7 +21,7 @@
    16.4      }
    16.5  
    16.6      public void testMain() throws Exception {
    16.7 -        Parallel.main(null);
    16.8 +        Parael.main(null);
    16.9          fail("Ok, just print logged messages");
   16.10      }
   16.11  }
    17.1 --- a/samples/delegatingwriter/src/org/apidesign/delegatingwriter/AltBufferedWriter.java	Sat Jun 14 10:04:50 2008 +0200
    17.2 +++ b/samples/delegatingwriter/src/org/apidesign/delegatingwriter/AltBufferedWriter.java	Sat Jun 14 10:04:51 2008 +0200
    17.3 @@ -68,7 +68,7 @@
    17.4          // BEGIN: writer.delegateout
    17.5          // efficient, yet dangerous delegation skipping methods unknown to 
    17.6          // subclasses that used version 1.4
    17.7 -        if (shouldBufferAsTheSequenceIsNotTooBig(csq)) {
    17.8 +        if (csq != null && csq.length() < 1024) {
    17.9              write(csq.toString());
   17.10          } else {
   17.11              flush();
   17.12 @@ -103,7 +103,7 @@
   17.13              throw new IOException(ex);
   17.14          }
   17.15          
   17.16 -        if (isOverriden || shouldBufferAsTheSequenceIsNotTooBig(csq)) {
   17.17 +        if (isOverriden || (csq != null && csq.length() < 1024)) {
   17.18              write(csq.toString());
   17.19          } else {
   17.20              flush();
   17.21 @@ -112,28 +112,6 @@
   17.22          return this;
   17.23          // END: writer.conditionally
   17.24      }
   17.25 -
   17.26 -    /** At the end the purpose of BufferedWriter is to buffer writes, this
   17.27 -     * method is here to decide when it is OK to prefer buffering and when 
   17.28 -     * it is better to delegate directly into the underlaying stream.
   17.29 -     * 
   17.30 -     * @param csq the seqence to evaluate
   17.31 -     * @return true if buffering from super class should be used
   17.32 -     */
   17.33 -    private static boolean shouldBufferAsTheSequenceIsNotTooBig(CharSequence csq) {
   17.34 -        if (csq == null) {
   17.35 -            return false;
   17.36 -        }
   17.37 -        // as buffers are usually bigger than 1024, it makes sense to 
   17.38 -        // pay the penalty of converting the sequence to string, but buffering
   17.39 -        // the write
   17.40 -        if (csq.length() < 1024) {
   17.41 -            return true;
   17.42 -        } else {
   17.43 -            // otherwise, just directly write down the char sequence
   17.44 -            return false;
   17.45 -        }
   17.46 -    }
   17.47      
   17.48      public enum Behaviour {
   17.49          THROW_EXCEPTION, 
    18.1 --- a/samples/delegatingwriter/test/org/apidesign/delegatingwriter/CountingWriter.java	Sat Jun 14 10:04:50 2008 +0200
    18.2 +++ b/samples/delegatingwriter/test/org/apidesign/delegatingwriter/CountingWriter.java	Sat Jun 14 10:04:51 2008 +0200
    18.3 @@ -6,6 +6,8 @@
    18.4  
    18.5  // BEGIN: writer.CountingWriter
    18.6  /** Writer that counts the number of written in characters.
    18.7 + *
    18.8 + * @author Jaroslav Tulach
    18.9   */
   18.10  public class CountingWriter extends Writer {
   18.11      private int counter;
    19.1 --- a/samples/delegatingwriter/test/org/apidesign/delegatingwriter/CryptoWriter.java	Sat Jun 14 10:04:50 2008 +0200
    19.2 +++ b/samples/delegatingwriter/test/org/apidesign/delegatingwriter/CryptoWriter.java	Sat Jun 14 10:04:51 2008 +0200
    19.3 @@ -34,26 +34,26 @@
    19.4      public void write(char[] buf, int off, int len) throws IOException {
    19.5          char[] arr = new char[len];
    19.6          for (int i = 0; i < len; i++) {
    19.7 -            arr[i] = encryptChar(buf[off + i]);
    19.8 +            arr[i] = convertChar(buf[off + i]);
    19.9          }
   19.10          super.write(arr, 0, len);
   19.11      }
   19.12  
   19.13      @Override
   19.14      public void write(int c) throws IOException {
   19.15 -        super.write(encryptChar(c));
   19.16 +        super.write(convertChar(c));
   19.17      }
   19.18  
   19.19      @Override
   19.20      public void write(String str, int off, int len) throws IOException {
   19.21          StringBuffer sb = new StringBuffer();
   19.22          for (int i = 0; i < len; i++) {
   19.23 -            sb.append(encryptChar(str.charAt(off + i)));
   19.24 +            sb.append(convertChar(str.charAt(off + i)));
   19.25          }
   19.26          super.write(sb.toString(), 0, len);
   19.27      }
   19.28  
   19.29 -    private char encryptChar(int c) {
   19.30 +    private char convertChar(int c) {
   19.31          if (c == 'Z') {
   19.32              return 'A';
   19.33          }
    20.1 --- a/samples/delegatingwriterfinal/src-api2.0/api/SimpleBuffer.java	Sat Jun 14 10:04:50 2008 +0200
    20.2 +++ b/samples/delegatingwriterfinal/src-api2.0/api/SimpleBuffer.java	Sat Jun 14 10:04:51 2008 +0200
    20.3 @@ -28,7 +28,7 @@
    20.4      }
    20.5  
    20.6      public void write(CharSequence seq) throws IOException {
    20.7 -        if (shouldBufferAsTheSequenceIsNotTooBig(seq)) {
    20.8 +        if (seq.length() < 1024) {
    20.9              sb.append(seq);
   20.10          } else {
   20.11              flush();
   20.12 @@ -36,26 +36,4 @@
   20.13          }
   20.14      }
   20.15  
   20.16 -    /** At the end the purpose of BufferedWriter is to buffer writes, this
   20.17 -     * method is here to decide when it is OK to prefer buffering and when 
   20.18 -     * it is better to delegate directly into the underlaying stream.
   20.19 -     * 
   20.20 -     * @param csq the seqence to evaluate
   20.21 -     * @return true if buffering from super class should be used
   20.22 -     */
   20.23 -    private static boolean shouldBufferAsTheSequenceIsNotTooBig(CharSequence csq) {
   20.24 -        if (csq == null) {
   20.25 -            return false;
   20.26 -        }
   20.27 -        // as buffers are usually bigger than 1024, it makes sense to 
   20.28 -        // pay the penalty of converting the sequence to string, but buffering
   20.29 -        // the write
   20.30 -        if (csq.length() < 1024) {
   20.31 -            return true;
   20.32 -        } else {
   20.33 -            // otherwise, just directly write down the char sequence
   20.34 -            return false;
   20.35 -        }
   20.36 -    }
   20.37 -    
   20.38  }
    21.1 --- a/samples/delegatingwriterfinal/src-api2.0/api/Writer.java	Sat Jun 14 10:04:50 2008 +0200
    21.2 +++ b/samples/delegatingwriterfinal/src-api2.0/api/Writer.java	Sat Jun 14 10:04:51 2008 +0200
    21.3 @@ -97,8 +97,8 @@
    21.4          return new Writer(impl, null);
    21.5      }
    21.6  
    21.7 -    public static Writer create(ImplSeq seq) {
    21.8 -        return new Writer(null, seq);
    21.9 +    public static Writer create(ImplSeq impl) {
   21.10 +        return new Writer(null, impl);
   21.11      }
   21.12      
   21.13      public static Writer create(final java.io.Writer w) {
    22.1 --- a/samples/delegatingwriterfinal/src-test2.0/api/usage/twodotzero/CountingWriter.java	Sat Jun 14 10:04:50 2008 +0200
    22.2 +++ b/samples/delegatingwriterfinal/src-test2.0/api/usage/twodotzero/CountingWriter.java	Sat Jun 14 10:04:51 2008 +0200
    22.3 @@ -6,6 +6,8 @@
    22.4  import java.util.concurrent.atomic.AtomicInteger;
    22.5  
    22.6  /** Writer that counts the number of written in characters.
    22.7 + *
    22.8 + * @author Jaroslav Tulach
    22.9   */
   22.10  public class CountingWriter implements Writer.ImplSeq {
   22.11      private final AtomicInteger counter;
    23.1 --- a/samples/growingparameters/src-api1.0/api/request/response/Compute.java	Sat Jun 14 10:04:50 2008 +0200
    23.2 +++ b/samples/growingparameters/src-api1.0/api/request/response/Compute.java	Sat Jun 14 10:04:51 2008 +0200
    23.3 @@ -21,11 +21,11 @@
    23.4          }
    23.5          
    23.6          public void add(String s) {
    23.7 -            result.add(s);
    23.8 +            this.result.add(s);
    23.9          }
   23.10          
   23.11          public void addAll(List<String> all) {
   23.12 -            result.addAll(all);
   23.13 +            this.result.addAll(all);
   23.14          }
   23.15      }
   23.16  }
    24.1 --- a/samples/growingparameters/src-api2.0/api/request/response/Compute.java	Sat Jun 14 10:04:50 2008 +0200
    24.2 +++ b/samples/growingparameters/src-api2.0/api/request/response/Compute.java	Sat Jun 14 10:04:51 2008 +0200
    24.3 @@ -22,7 +22,7 @@
    24.4          }
    24.5          
    24.6          public void add(String s) {
    24.7 -            result.put(s, s);
    24.8 +            this.result.put(s, s);
    24.9          }
   24.10          
   24.11          public void addAll(List<String> all) {
   24.12 @@ -33,7 +33,7 @@
   24.13  
   24.14          /** @since 2.0 */
   24.15          public void add(String s, String description) {
   24.16 -            result.put(s, description);
   24.17 +            this.result.put(s, description);
   24.18          }
   24.19      }
   24.20  }
    25.1 --- a/samples/instanceof/src/api/InstanceProvider.java	Sat Jun 14 10:04:50 2008 +0200
    25.2 +++ b/samples/instanceof/src/api/InstanceProvider.java	Sat Jun 14 10:04:51 2008 +0200
    25.3 @@ -3,7 +3,7 @@
    25.4  
    25.5  // BEGIN: instanceof.InstanceProvider
    25.6  public interface InstanceProvider {
    25.7 -    public Class<?> instanceClass() throws Exception;
    25.8 -    public Object instanceCreate() throws Exception;
    25.9 +    public Class<?> instanceClass();
   25.10 +    public Object instanceCreate();
   25.11  }
   25.12  // END: instanceof.InstanceProvider
    26.1 --- a/samples/instanceofclass/src-api1.0/api/InstanceProvider.java	Sat Jun 14 10:04:50 2008 +0200
    26.2 +++ b/samples/instanceofclass/src-api1.0/api/InstanceProvider.java	Sat Jun 14 10:04:51 2008 +0200
    26.3 @@ -2,21 +2,18 @@
    26.4  package api;
    26.5  
    26.6  // BEGIN: instanceof.class.InstanceProvider1
    26.7 +public final class InstanceProvider {
    26.8 +    private final Object instance;
    26.9  
   26.10 -import java.util.concurrent.Callable;
   26.11 -
   26.12 -public final class InstanceProvider {
   26.13 -    private final Callable<Object> instance;
   26.14 -
   26.15 -    public InstanceProvider(Callable<Object> instance) {
   26.16 +    public InstanceProvider(Object instance) {
   26.17          this.instance = instance;
   26.18      }
   26.19      
   26.20 -    public Class<?> instanceClass() throws Exception {
   26.21 -        return instance.call().getClass();
   26.22 +    public Class<?> instanceClass() {
   26.23 +        return instance.getClass();
   26.24      }
   26.25 -    public Object instanceCreate() throws Exception {
   26.26 -        return instance.call();
   26.27 +    public Object instanceCreate() {
   26.28 +        return instance;
   26.29      }
   26.30  }
   26.31  // END: instanceof.class.InstanceProvider1
    27.1 --- a/samples/instanceofclass/src-api2.0/api/InstanceProvider.java	Sat Jun 14 10:04:50 2008 +0200
    27.2 +++ b/samples/instanceofclass/src-api2.0/api/InstanceProvider.java	Sat Jun 14 10:04:51 2008 +0200
    27.3 @@ -2,50 +2,24 @@
    27.4  package api;
    27.5  
    27.6  // BEGIN: instanceof.class.InstanceProvider2
    27.7 +public final class InstanceProvider {
    27.8 +    private final Object instance;
    27.9  
   27.10 -import java.util.Arrays;
   27.11 -import java.util.HashSet;
   27.12 -import java.util.Set;
   27.13 -import java.util.concurrent.Callable;
   27.14 -
   27.15 -public final class InstanceProvider {
   27.16 -    private final Callable<Object> instance;
   27.17 -    private final Set<String> types;
   27.18 -
   27.19 -    public InstanceProvider(Callable<Object> instance) {
   27.20 +    public InstanceProvider(Object instance) {
   27.21          this.instance = instance;
   27.22 -        this.types = null;
   27.23 -    }
   27.24 -    /** Specifies not only a factory for creating objects, but
   27.25 -     * also additional information about them.
   27.26 -     * @param instance the factory to create the object
   27.27 -     * @param type the class that the create object will be instance of
   27.28 -     * @since 2.0 
   27.29 -     */
   27.30 -    public InstanceProvider(Callable<Object> instance, String... types) {
   27.31 -        this.instance = instance;
   27.32 -        this.types = new HashSet<String>();
   27.33 -        this.types.addAll(Arrays.asList(types));
   27.34      }
   27.35      
   27.36 -    public Class<?> instanceClass() throws Exception {
   27.37 -        return instance.call().getClass();
   27.38 +    public Class<?> instanceClass() {
   27.39 +        return instance.getClass();
   27.40      }
   27.41 -    public Object instanceCreate() throws Exception {
   27.42 -        return instance.call();
   27.43 +    public Object instanceCreate() {
   27.44 +        return instance;
   27.45      }
   27.46      
   27.47 -    /** Allows to find out if the InstanceProvider creates object of given
   27.48 -     * type. This check can be done without loading the actual object or
   27.49 -     * its implementation class into memory.
   27.50 -     * 
   27.51 -     * @param c class to test 
   27.52 -     * @return if the instances produced by this provider is instance of c
   27.53 -     * @since 2.0 
   27.54 -     */
   27.55 -    public boolean isInstanceOf(Class<?> c) throws Exception {
   27.56 -        if (types != null) {
   27.57 -            return types.contains(c.getName());
   27.58 +    /** @since 2.0 */
   27.59 +    public boolean isInstanceOf(Class<?> c) {
   27.60 +        if (Helper.knownHowToDoItBetter()) {
   27.61 +            return Helper.computeTheResultOfIsInstanceOfInSomeBetterWay(c);
   27.62          } else {
   27.63              // fallback
   27.64              return c.isAssignableFrom(instanceClass());
   27.65 @@ -55,3 +29,12 @@
   27.66      
   27.67  }
   27.68  // END: instanceof.class.InstanceProvider2
   27.69 +
   27.70 +class Helper {
   27.71 +    static boolean computeTheResultOfIsInstanceOfInSomeBetterWay(Class<?> c) {
   27.72 +        return false;
   27.73 +    }
   27.74 +    static boolean knownHowToDoItBetter() {
   27.75 +        return false;
   27.76 +    }
   27.77 +}
   27.78 \ No newline at end of file
    28.1 --- a/samples/misuse/src/org/apidesign/misuse/Connection.java	Sat Jun 14 10:04:50 2008 +0200
    28.2 +++ b/samples/misuse/src/org/apidesign/misuse/Connection.java	Sat Jun 14 10:04:51 2008 +0200
    28.3 @@ -2,10 +2,10 @@
    28.4  
    28.5  // BEGIN: misuse.Connection
    28.6  public interface Connection {
    28.7 -    public Savepoint setSavepoint();
    28.8 +    Savepoint setSavepoint();
    28.9      
   28.10      public interface Savepoint {
   28.11 -        public void rollback();
   28.12 +        void rollback();
   28.13          // and other useful operations
   28.14      }
   28.15  }
    29.1 --- a/samples/misuse/src/org/apidesign/misuse/projectconfig/ProjectConfigurationCorrect.java	Sat Jun 14 10:04:50 2008 +0200
    29.2 +++ b/samples/misuse/src/org/apidesign/misuse/projectconfig/ProjectConfigurationCorrect.java	Sat Jun 14 10:04:51 2008 +0200
    29.3 @@ -4,9 +4,9 @@
    29.4      // BEGIN: misuse.prjconfig.correct
    29.5      interface ProjectConfigurationProvider
    29.6          <Configuration extends ProjectConfiguration> {
    29.7 -        public Configuration[] getConfigurations();
    29.8 -        public Configuration getActive();
    29.9 -        public void setActive(Configuration c);
   29.10 +        Configuration[] getConfigurations();
   29.11 +        Configuration getActive();
   29.12 +        void setActive(Configuration c);
   29.13      }
   29.14      interface ProjectConfiguration {
   29.15          public String getDisplayName();
   29.16 @@ -24,13 +24,12 @@
   29.17      }
   29.18      */
   29.19  
   29.20 -    static 
   29.21 -    // BEGIN: misuse.prjconfig.correct.access
   29.22 -    { 
   29.23 +    static { 
   29.24 +        // BEGIN: misuse.prjconfig.correct.access
   29.25          ProjectConfigurationProvider<?> provider = null; // obtain elsewhere;
   29.26          resetToZero(provider);
   29.27 +        // END: misuse.prjconfig.correct.access
   29.28      }
   29.29 -    // END: misuse.prjconfig.correct.access
   29.30  
   29.31      // BEGIN: misuse.prjconfig.correct.openmethod
   29.32      private static <C extends ProjectConfiguration> void resetToZero(
    30.1 --- a/samples/misuse/src/org/apidesign/misuse/projectconfig/ProjectConfigurationOriginal.java	Sat Jun 14 10:04:50 2008 +0200
    30.2 +++ b/samples/misuse/src/org/apidesign/misuse/projectconfig/ProjectConfigurationOriginal.java	Sat Jun 14 10:04:51 2008 +0200
    30.3 @@ -3,9 +3,9 @@
    30.4  public class ProjectConfigurationOriginal {
    30.5      // BEGIN: misuse.prjconfig.orig
    30.6      interface ProjectConfigurationProvider {
    30.7 -        public ProjectConfiguration[] getConfigurations();
    30.8 -        public ProjectConfiguration getActive();
    30.9 -        public void setActive(ProjectConfiguration c);
   30.10 +        ProjectConfiguration[] getConfigurations();
   30.11 +        ProjectConfiguration getActive();
   30.12 +        void setActive(ProjectConfiguration c);
   30.13      }
   30.14      interface ProjectConfiguration {
   30.15          public String getDisplayName();
    31.1 --- a/samples/reentrant/src/org/apidesign/reentrant/CriticalSectionReentrant.java	Sat Jun 14 10:04:50 2008 +0200
    31.2 +++ b/samples/reentrant/src/org/apidesign/reentrant/CriticalSectionReentrant.java	Sat Jun 14 10:04:51 2008 +0200
    31.3 @@ -5,13 +5,13 @@
    31.4  
    31.5  public class CriticalSectionReentrant<T extends Comparable<T>> implements CriticalSection<T> {
    31.6      private T pilot;
    31.7 +    private AtomicInteger cnt = new AtomicInteger();
    31.8      
    31.9      public void assignPilot(T pilot) {
   31.10          this.pilot = pilot;
   31.11      }
   31.12  
   31.13      // BEGIN: reentrant.merge.int
   31.14 -    private AtomicInteger cnt = new AtomicInteger();
   31.15      public int sumBigger(Collection<T> args) {
   31.16          T pilotCopy = this.pilot;
   31.17          int own = doCriticalSection(args, pilotCopy);
    32.1 --- a/samples/reentrant/src/org/apidesign/reentrant/CriticalSectionReentrantImmutable.java	Sat Jun 14 10:04:50 2008 +0200
    32.2 +++ b/samples/reentrant/src/org/apidesign/reentrant/CriticalSectionReentrantImmutable.java	Sat Jun 14 10:04:51 2008 +0200
    32.3 @@ -13,10 +13,7 @@
    32.4      // BEGIN: reentrant.merge.immutable
    32.5      public int sumBigger(Collection<T> args) {
    32.6          for (;;) {
    32.7 -            ImmutableData<T> previous;
    32.8 -            synchronized (this) {
    32.9 -                previous = this.data;
   32.10 -            }
   32.11 +            ImmutableData<T> previous = this.data;
   32.12              int[] ret = { 0 };
   32.13              ImmutableData<T> now = doCriticalSection(args, previous, ret);
   32.14