samples/growingparameters/src-impl/impl/Impl.java
changeset 78 af48bccb02cb
parent 77 22c1953e372c
     1.1 --- a/samples/growingparameters/src-impl/impl/Impl.java	Sat Jun 14 09:53:37 2008 +0200
     1.2 +++ b/samples/growingparameters/src-impl/impl/Impl.java	Sat Jun 14 09:53:38 2008 +0200
     1.3 @@ -1,26 +1,35 @@
     1.4  package impl;
     1.5  
     1.6 -import api.classes.Compute;
     1.7 -import api.classes.Support;
     1.8  import java.util.Collections;
     1.9  import java.util.List;
    1.10  import java.util.Map;
    1.11  
    1.12  public class Impl {
    1.13      public static void main(String[] args) {
    1.14 -        class ProviderWrittenAgainstVersion1 extends Compute {
    1.15 +        System.err.println("showUsageOfAbstractClassAPI:");
    1.16 +        showUsageOfAbstractClassAPI();
    1.17 +        System.err.println("showUsageOfRequestResponseAPI:");
    1.18 +        showUsageOfRequestResponseAPI();
    1.19 +    }
    1.20 +    
    1.21 +    private static void assertEquals(String msg, int expected, int real) {
    1.22 +        System.err.println("    " + msg + " expected: " + expected + " was: " + real);
    1.23 +        assert expected == real;
    1.24 +    }
    1.25 +    
    1.26 +    private static void showUsageOfAbstractClassAPI() {
    1.27 +        class ProviderWrittenAgainstVersion1 extends api.classes.Compute {
    1.28              @Override
    1.29              public List<String> getData() {
    1.30                  return Collections.singletonList("Hello");
    1.31              }
    1.32          }
    1.33 -        int index1 = Support.searchByDescription("Hello", new ProviderWrittenAgainstVersion1());
    1.34 -        assert index1 == 0;
    1.35 -        int index2 = Support.searchByDescription("Unknown", new ProviderWrittenAgainstVersion1());
    1.36 -        assert index2 == -1;
    1.37 -
    1.38 +        int index1 = api.classes.Support.searchByDescription("Hello", new ProviderWrittenAgainstVersion1());
    1.39 +        assertEquals("Hello was found", 0, index1);
    1.40 +        int index2 = api.classes.Support.searchByDescription("Unknown", new ProviderWrittenAgainstVersion1());
    1.41 +        assertEquals("Unknown was not found", -1, index2);
    1.42          
    1.43 -        class ProviderWrittenAgainstVersion2 extends Compute {
    1.44 +        class ProviderWrittenAgainstVersion2 extends api.classes.Compute {
    1.45              @Override
    1.46              public List<String> getData() {
    1.47                  return Collections.singletonList("Hello");
    1.48 @@ -32,7 +41,31 @@
    1.49              }
    1.50          }
    1.51  
    1.52 -        int index3 = Support.searchByDescription("Says hello", new ProviderWrittenAgainstVersion2());
    1.53 +        int index3 = api.classes.Support.searchByDescription("Says hello", new ProviderWrittenAgainstVersion2());
    1.54 +        assertEquals("Found by description", 0, index3);
    1.55 +    }
    1.56 +    
    1.57 +    
    1.58 +    
    1.59 +    private static void showUsageOfRequestResponseAPI() {
    1.60 +        class ProviderWrittenAgainstVersion1 implements api.request.response.Compute {
    1.61 +            public void computeData(Request request, Response response) {
    1.62 +                response.add("Hello");
    1.63 +            }
    1.64 +        }
    1.65 +        int index1 = api.request.response.Support.searchByDescription("Hello", new ProviderWrittenAgainstVersion1());
    1.66 +        assertEquals("Hello found", 0, index1);
    1.67 +        int index2 = api.request.response.Support.searchByDescription("Unknown", new ProviderWrittenAgainstVersion1());
    1.68 +        assertEquals("Unknown not found", -1, index2);
    1.69 +        
    1.70 +        class ProviderWrittenAgainstVersion2 implements api.request.response.Compute {
    1.71 +            public void computeData(Request request, Response response) {
    1.72 +                response.add("Hello", "Says hello");
    1.73 +            }
    1.74 +        }
    1.75 +
    1.76 +        int index3 = api.request.response.Support.searchByDescription("Says hello", new ProviderWrittenAgainstVersion2());
    1.77 +        assertEquals("Description found", 0, index3);
    1.78          assert index3 == 0;
    1.79      }
    1.80  }