samples/growingparameters/src-impl/impl/Impl.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:53:38 +0200
changeset 78 af48bccb02cb
parent 77 22c1953e372c
permissions -rw-r--r--
Finished re-reading of "classes vs. interfaces"
     1 package impl;
     2 
     3 import java.util.Collections;
     4 import java.util.List;
     5 import java.util.Map;
     6 
     7 public class Impl {
     8     public static void main(String[] args) {
     9         System.err.println("showUsageOfAbstractClassAPI:");
    10         showUsageOfAbstractClassAPI();
    11         System.err.println("showUsageOfRequestResponseAPI:");
    12         showUsageOfRequestResponseAPI();
    13     }
    14     
    15     private static void assertEquals(String msg, int expected, int real) {
    16         System.err.println("    " + msg + " expected: " + expected + " was: " + real);
    17         assert expected == real;
    18     }
    19     
    20     private static void showUsageOfAbstractClassAPI() {
    21         class ProviderWrittenAgainstVersion1 extends api.classes.Compute {
    22             @Override
    23             public List<String> getData() {
    24                 return Collections.singletonList("Hello");
    25             }
    26         }
    27         int index1 = api.classes.Support.searchByDescription("Hello", new ProviderWrittenAgainstVersion1());
    28         assertEquals("Hello was found", 0, index1);
    29         int index2 = api.classes.Support.searchByDescription("Unknown", new ProviderWrittenAgainstVersion1());
    30         assertEquals("Unknown was not found", -1, index2);
    31         
    32         class ProviderWrittenAgainstVersion2 extends api.classes.Compute {
    33             @Override
    34             public List<String> getData() {
    35                 return Collections.singletonList("Hello");
    36             }
    37 
    38             @Override
    39             public Map<String, String> getDataAndDescription() {
    40                 return Collections.singletonMap("Hello", "Says hello");
    41             }
    42         }
    43 
    44         int index3 = api.classes.Support.searchByDescription("Says hello", new ProviderWrittenAgainstVersion2());
    45         assertEquals("Found by description", 0, index3);
    46     }
    47     
    48     
    49     
    50     private static void showUsageOfRequestResponseAPI() {
    51         class ProviderWrittenAgainstVersion1 implements api.request.response.Compute {
    52             public void computeData(Request request, Response response) {
    53                 response.add("Hello");
    54             }
    55         }
    56         int index1 = api.request.response.Support.searchByDescription("Hello", new ProviderWrittenAgainstVersion1());
    57         assertEquals("Hello found", 0, index1);
    58         int index2 = api.request.response.Support.searchByDescription("Unknown", new ProviderWrittenAgainstVersion1());
    59         assertEquals("Unknown not found", -1, index2);
    60         
    61         class ProviderWrittenAgainstVersion2 implements api.request.response.Compute {
    62             public void computeData(Request request, Response response) {
    63                 response.add("Hello", "Says hello");
    64             }
    65         }
    66 
    67         int index3 = api.request.response.Support.searchByDescription("Says hello", new ProviderWrittenAgainstVersion2());
    68         assertEquals("Description found", 0, index3);
    69         assert index3 == 0;
    70     }
    71 }