# HG changeset patch # User Jaroslav Tulach # Date 1213429850 -7200 # Node ID b577ee7fcf67177a0e264894a86d7c5e56a81f80 # Parent d7c5ff8acd7258242c2cb484c818877cf68457f7 example with conditional usage of an API diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/conditionaluseofapi/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/conditionaluseofapi/build.xml Sat Jun 14 09:50:50 2008 +0200 @@ -0,0 +1,27 @@ + + + Builds, tests, and runs the project conditionaluseofapi. + + + + + + + + + + + + + + + + + + + + + + + + diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/conditionaluseofapi/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/conditionaluseofapi/nbproject/build-impl.xml Sat Jun 14 09:50:50 2008 +0200 @@ -0,0 +1,627 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/conditionaluseofapi/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/conditionaluseofapi/nbproject/genfiles.properties Sat Jun 14 09:50:50 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=32385e3b +build.xml.script.CRC32=91329421 +build.xml.stylesheet.CRC32=be360661 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=32385e3b +nbproject/build-impl.xml.script.CRC32=7a10d71d +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/conditionaluseofapi/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/conditionaluseofapi/nbproject/project.properties Sat Jun 14 09:50:50 2008 +0200 @@ -0,0 +1,59 @@ +application.title=conditionaluseofapi +application.vendor=jarda +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/conditionaluseofapi.jar +dist.javadoc.dir=${dist.dir}/javadoc +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.4 +javac.target=1.4 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=conditionaluseofapi.Main +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/conditionaluseofapi/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/conditionaluseofapi/nbproject/project.xml Sat Jun 14 09:50:50 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + conditionaluseofapi + 1.6.5 + + + + + + + + + diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/conditionaluseofapi/src/conditionaluseofapi/AddString.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/conditionaluseofapi/src/conditionaluseofapi/AddString.java Sat Jun 14 09:50:50 2008 +0200 @@ -0,0 +1,14 @@ + +package conditionaluseofapi; + +/** Facade interface to shield us from the actual implementation for + * Java 1.4 and Java 5. + * + * @author Jaroslav Tulach + */ +// BEGIN: theory.binary.overloads.facade +interface AddString { + public void addString(String msg); + public String getMessage(); +} +// END: theory.binary.overloads.facade diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/conditionaluseofapi/src/conditionaluseofapi/Main.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/conditionaluseofapi/src/conditionaluseofapi/Main.java Sat Jun 14 09:50:50 2008 +0200 @@ -0,0 +1,41 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Jaroslav Tulach. Portions Copyright 2007 Jaroslav Tulach. + * All Rights Reserved. + */ +package conditionaluseofapi; + +/** + * + * @author Jaroslav Tulach + */ +public class Main { + + public static void main(String[] args) throws Exception { + // BEGIN: theory.binary.overloads.init + AddString add; + + try { + Class onlyOn15 = Class.forName("java.lang.StringBuilder"); + add = (AddString)Class.forName("conditionaluseofapi.StringBuilderAdd15").newInstance(); + } catch (ClassNotFoundException ex) { + add = new StringBufferAdd(); + } + // END: theory.binary.overloads.init + + add.addString("Hello"); + add.addString(" "); + add.addString("World!"); + + System.out.println(add.getMessage()); + System.out.println("printed with: " + add); + } + +} diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/conditionaluseofapi/src/conditionaluseofapi/StringBufferAdd.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/conditionaluseofapi/src/conditionaluseofapi/StringBufferAdd.java Sat Jun 14 09:50:50 2008 +0200 @@ -0,0 +1,22 @@ +package conditionaluseofapi; + +/** Implementation for string concatention using Java 1.4 APIs. + * + * @author Jaroslav Tulach + */ +final class StringBufferAdd implements AddString { + + private StringBuffer sb = new StringBuffer(); + + public void addString(String msg) { + sb.append(msg); + } + + public String getMessage() { + return sb.toString(); + } + + public String toString() { + return "Old Java 1.4 implementation"; + } +} diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/conditionaluseofapi/src/conditionaluseofapi/StringBuilderAdd15.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/conditionaluseofapi/src/conditionaluseofapi/StringBuilderAdd15.java Sat Jun 14 09:50:50 2008 +0200 @@ -0,0 +1,26 @@ +package conditionaluseofapi; + +/** Implementation for string concatention using Java 5 only. + * + * StringBuilder is supposed to be faster than StringBuffer as it + * is not synchronized and as such it is does not waste time with + * synchronization when its methods are called. + * + * @author Jaroslav Tulach + */ +final class StringBuilderAdd15 implements AddString { + + private StringBuilder sb = new StringBuilder(); + + public void addString(String msg) { + sb.append(msg); + } + + public String getMessage() { + return sb.toString(); + } + + public String toString() { + return "New Shiny and Fast Java 5 Implementation"; + } +} diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/friendpackage/nbproject/build-impl.xml --- a/samples/friendpackage/nbproject/build-impl.xml Sat Jun 14 09:50:29 2008 +0200 +++ b/samples/friendpackage/nbproject/build-impl.xml Sat Jun 14 09:50:50 2008 +0200 @@ -108,6 +108,16 @@ + + + + + + + + + + @@ -142,7 +152,6 @@ - @@ -150,7 +159,7 @@ - + @@ -187,11 +196,12 @@ + - + @@ -306,8 +316,10 @@ - + + + @@ -455,7 +467,7 @@ --> - + @@ -480,8 +492,10 @@ - + + + @@ -518,7 +532,7 @@ - + Some tests failed; see details above. diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/friendpackage/nbproject/genfiles.properties --- a/samples/friendpackage/nbproject/genfiles.properties Sat Jun 14 09:50:29 2008 +0200 +++ b/samples/friendpackage/nbproject/genfiles.properties Sat Jun 14 09:50:50 2008 +0200 @@ -4,5 +4,5 @@ # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=b1c774b2 -nbproject/build-impl.xml.script.CRC32=93374311 -nbproject/build-impl.xml.stylesheet.CRC32=3c2f24dc +nbproject/build-impl.xml.script.CRC32=2fcc3cdb +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/friendpackage/src/apipkg/AccessorImpl.java --- a/samples/friendpackage/src/apipkg/AccessorImpl.java Sat Jun 14 09:50:29 2008 +0200 +++ b/samples/friendpackage/src/apipkg/AccessorImpl.java Sat Jun 14 09:50:50 2008 +0200 @@ -7,8 +7,8 @@ * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1999-2006 Sun - * Microsystems, Inc. All Rights Reserved. + * Code is Jaroslav Tulach. Portions Copyright 2007 Jaroslav Tulach. + * All Rights Reserved. */ package apipkg; diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/friendpackage/src/apipkg/Item.java --- a/samples/friendpackage/src/apipkg/Item.java Sat Jun 14 09:50:29 2008 +0200 +++ b/samples/friendpackage/src/apipkg/Item.java Sat Jun 14 09:50:50 2008 +0200 @@ -7,8 +7,8 @@ * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1999-2006 Sun - * Microsystems, Inc. All Rights Reserved. + * Code is Jaroslav Tulach. Portions Copyright 2007 Jaroslav Tulach. + * All Rights Reserved. */ package apipkg; diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/friendpackage/src/implpkg/Accessor.java --- a/samples/friendpackage/src/implpkg/Accessor.java Sat Jun 14 09:50:29 2008 +0200 +++ b/samples/friendpackage/src/implpkg/Accessor.java Sat Jun 14 09:50:50 2008 +0200 @@ -7,8 +7,8 @@ * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1999-2006 Sun - * Microsystems, Inc. All Rights Reserved. + * Code is Jaroslav Tulach. Portions Copyright 2007 Jaroslav Tulach. + * All Rights Reserved. */ package implpkg; diff -r d7c5ff8acd72 -r b577ee7fcf67 samples/friendpackage/test/implpkg/AccessorTest.java --- a/samples/friendpackage/test/implpkg/AccessorTest.java Sat Jun 14 09:50:29 2008 +0200 +++ b/samples/friendpackage/test/implpkg/AccessorTest.java Sat Jun 14 09:50:50 2008 +0200 @@ -7,8 +7,8 @@ * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1999-2006 Sun - * Microsystems, Inc. All Rights Reserved. + * Code is Jaroslav Tulach. Portions Copyright 2007 Jaroslav Tulach. + * All Rights Reserved. */ package implpkg;