# HG changeset patch # User Jaroslav Tulach # Date 1213430017 -7200 # Node ID 22c1953e372c59721c5f4820f0df73a1b7025f38 # Parent ee4e8d38093ea90c1efc28ca09a5183c7d0cb7a0 Compute with added method converted to separate project diff -r ee4e8d38093e -r 22c1953e372c samples/growingparameters/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/growingparameters/build.xml Sat Jun 14 09:53:37 2008 +0200 @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r ee4e8d38093e -r 22c1953e372c samples/growingparameters/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/growingparameters/nbproject/project.xml Sat Jun 14 09:53:37 2008 +0200 @@ -0,0 +1,98 @@ + + + org.netbeans.modules.ant.freeform + + + growingparameters + + + + growingparameters + + + + + . + UTF-8 + + + + java + src-api1.0 + UTF-8 + + + + java + impl + UTF-8 + + + + + build + + + clean + + + run + + + clean + build + + + + folder + build/api1.0/classes + build + + + folder + build/api2.0/classes + build + + + + + + src-api1.0 + + + + impl + + + build.xml + + + + + + + + + + + + + + + src-api1.0 + build/api1.0/classes + 1.5 + + + src-api2.0 + build/api2.0/classes + 1.5 + + + src-impl + src-api2.0 + 1.5 + + + + diff -r ee4e8d38093e -r 22c1953e372c samples/growingparameters/src-api1.0/api/classes/Compute.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/growingparameters/src-api1.0/api/classes/Compute.java Sat Jun 14 09:53:37 2008 +0200 @@ -0,0 +1,7 @@ +package api.classes; + +import java.util.List; + +public abstract class Compute { + public abstract List getData(); +} diff -r ee4e8d38093e -r 22c1953e372c samples/growingparameters/src-api1.0/api/classes/Support.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/growingparameters/src-api1.0/api/classes/Support.java Sat Jun 14 09:53:37 2008 +0200 @@ -0,0 +1,29 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package api.classes; + +import java.util.Iterator; +import java.util.List; + +/** + * + * @author Jaroslav Tulach + */ +public class Support { + private Support() { + } + + public static int searchByName(String name, Compute provider) { + Iterator it = provider.getData().iterator(); + for (int i = 0; it.hasNext(); i++) { + if (name.equals(it.next())) { + return i; + } + } + return -1; + } + +} diff -r ee4e8d38093e -r 22c1953e372c samples/growingparameters/src-api2.0/api/classes/Compute.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/growingparameters/src-api2.0/api/classes/Compute.java Sat Jun 14 09:53:37 2008 +0200 @@ -0,0 +1,27 @@ +package api.classes; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +// BEGIN: grow.compute +public abstract class Compute { + /** + * @return list of strings to work with + * @since 1.0 */ + public abstract List getData(); + /** Computes the strings to work with together with their associated descriptions. + * Shall be overriden in subclasses. By default delegates to {@link #getData} + * and uses the provided strings as both, the string and its description. + * + * @return name to description pairs to work with + * @since 2.0 */ + public Map getDataAndDescription() { + LinkedHashMap ret = new LinkedHashMap(); + for (String s : getData()) { + ret.put(s, s); + } + return ret; + } +} +// END: grow.compute diff -r ee4e8d38093e -r 22c1953e372c samples/growingparameters/src-api2.0/api/classes/Support.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/growingparameters/src-api2.0/api/classes/Support.java Sat Jun 14 09:53:37 2008 +0200 @@ -0,0 +1,31 @@ +package api.classes; + +import java.util.Iterator; +import java.util.Map.Entry; + +public class Support { + private Support() { + } + + public static int searchByName(String name, Compute provider) { + Iterator it = provider.getData().iterator(); + for (int i = 0; it.hasNext(); i++) { + if (name.equals(it.next())) { + return i; + } + } + return -1; + } + + /** @since 2.0 */ + public static int searchByDescription(String name, Compute provider) { + Iterator> it = provider.getDataAndDescription().entrySet().iterator(); + for (int i = 0; it.hasNext(); i++) { + if (name.equals(it.next().getValue())) { + return i; + } + } + return -1; + } + +} diff -r ee4e8d38093e -r 22c1953e372c samples/growingparameters/src-impl/impl/Impl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/growingparameters/src-impl/impl/Impl.java Sat Jun 14 09:53:37 2008 +0200 @@ -0,0 +1,38 @@ +package impl; + +import api.classes.Compute; +import api.classes.Support; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class Impl { + public static void main(String[] args) { + class ProviderWrittenAgainstVersion1 extends Compute { + @Override + public List getData() { + return Collections.singletonList("Hello"); + } + } + int index1 = Support.searchByDescription("Hello", new ProviderWrittenAgainstVersion1()); + assert index1 == 0; + int index2 = Support.searchByDescription("Unknown", new ProviderWrittenAgainstVersion1()); + assert index2 == -1; + + + class ProviderWrittenAgainstVersion2 extends Compute { + @Override + public List getData() { + return Collections.singletonList("Hello"); + } + + @Override + public Map getDataAndDescription() { + return Collections.singletonMap("Hello", "Says hello"); + } + } + + int index3 = Support.searchByDescription("Says hello", new ProviderWrittenAgainstVersion2()); + assert index3 == 0; + } +}