# HG changeset patch # User Jaroslav Tulach # Date 1213429965 -7200 # Node ID 4257f4cf226bee6df7e49776f9865481f35a7a05 # Parent 130e099942d8edaccc2510e62e6d74f840200069 Adding samples from API fest to the repository, including pieces of their code in the document, not just links diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/boolcircuit/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/boolcircuit/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project boolcircuit. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/boolcircuit/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/boolcircuit/nbproject/build-impl.xml Sat Jun 14 09:52:45 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 130e099942d8 -r 4257f4cf226b samples/apifest1/boolcircuit/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/boolcircuit/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=2ab820eb +build.xml.script.CRC32=58a52595 +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=2ab820eb +nbproject/build-impl.xml.script.CRC32=72d8319a +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/boolcircuit/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/boolcircuit/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,58 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/boolcircuit/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/boolcircuit/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + boolcircuit + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/boolcircuit/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/boolcircuit/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,25 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + */ +class Circuit { +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/boolcircuit/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/boolcircuit/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,102 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +// BEGIN: apifest.CircuitTest +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + fail("task1"); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + fail("task2"); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + fail("task3"); + } + +} +// END: apifest.CircuitTest diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/alwayscreatenewcircuit/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/alwayscreatenewcircuit/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project alwayscreatenewcircuit. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/alwayscreatenewcircuit/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/alwayscreatenewcircuit/nbproject/build-impl.xml Sat Jun 14 09:52:45 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/alwayscreatenewcircuit/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/alwayscreatenewcircuit/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=ffd6778c +build.xml.script.CRC32=f0487089 +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=ffd6778c +nbproject/build-impl.xml.script.CRC32=d54dcd8c +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/alwayscreatenewcircuit/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/alwayscreatenewcircuit/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,58 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/alwayscreatenewcircuit/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/alwayscreatenewcircuit/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + alwayscreatenewcircuit + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/alwayscreatenewcircuit/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/alwayscreatenewcircuit/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,139 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + */ +public abstract class Circuit { + /** Creates a new instance of Circuits */ + private Circuit() { + } + + public static Circuit negate(boolean input) { + return new Negation(input); + } + + public static Circuit negate(Circuit input) { + return new Negation(input); + } + + public static Circuit and(boolean input1, boolean input2) { + return new And(input1, input2); + } + + public static Circuit and(Circuit input1, boolean input2) { + return new And(input1, new Primitive(input2)); + } + + public static Circuit and(boolean input1, Circuit input2) { + return new And(new Primitive(input1), input2); + } + + public static Circuit and(Circuit input1, Circuit input2) { + return new And(input1, input2); + } + + public static Circuit or(boolean input1, boolean input2) { + return new Or(input1, input2); + } + + public static Circuit or(Circuit input1, boolean input2) { + return new Or(input1, new Primitive(input2)); + } + + public static Circuit or(boolean input1, Circuit input2) { + return new Or(new Primitive(input1), input2); + } + + public static Circuit or(Circuit input1, Circuit input2) { + return new Or(input1, input2); + } + + + public abstract boolean output(); + + private final static class Primitive extends Circuit { + private boolean input; + + Primitive(boolean input) { + this.input = input; + } + + public final boolean output() { + return input; + } + } + + private final static class Negation extends Circuit { + private Circuit input; + + Negation(boolean input) { + this.input = new Primitive(input); + } + + Negation(Circuit input) { + this.input = input; + } + + public final boolean output() { + return !(input.output()); + } + } + + private final static class And extends Circuit { + private Circuit input1; + private Circuit input2; + + + And(boolean input1, boolean input2) { + this.input1 = new Primitive(input1); + this.input2 = new Primitive(input2); + } + + And(Circuit input1, Circuit input2) { + this.input1 = input1; + this.input2 = input2; + } + + public final boolean output() { + return input1.output() && input2.output(); + } + } + + private final static class Or extends Circuit { + private Circuit input1; + private Circuit input2; + + + Or(boolean input1, boolean input2) { + this.input1 = new Primitive(input1); + this.input2 = new Primitive(input2); + } + + Or(Circuit input1, Circuit input2) { + this.input1 = input1; + this.input2 = input2; + } + + public final boolean output() { + return input1.output() || input2.output(); + } + } + } \ No newline at end of file diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/alwayscreatenewcircuit/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/alwayscreatenewcircuit/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,126 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + // BEGIN: apifest.day1.alwayscreatenewcircuit.CircuitTest + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + boolean x1 = true; + boolean x2 = true; + + Circuit outputCircuit = Circuit.and(x1, x2); + assertTrue(outputCircuit.output()); + + x1 = false; + x2 = true; + outputCircuit = Circuit.and(x1, x2); + assertFalse(outputCircuit.output()); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + boolean x1 = false; + boolean x2 = true; + boolean x3 = false; + Circuit outputCircuit = Circuit.or(Circuit.and(x1,x2),x3); + assertFalse(outputCircuit.output()); + + x1 = false; + x2 = false; + x3 = true; + outputCircuit = Circuit.or(Circuit.and(x1,x2),x3); + assertTrue(outputCircuit.output()); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + boolean x1 = true; + Circuit outputCircuit = Circuit.or(x1,Circuit.negate(x1)); + assertTrue(outputCircuit.output()); + + x1 = false; + outputCircuit = Circuit.or(x1,Circuit.negate(x1)); + assertTrue(outputCircuit.output()); + } + // END: apifest.day1.alwayscreatenewcircuit.CircuitTest + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/elementbasedsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/elementbasedsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project elementbasedsolution. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/elementbasedsolution/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/elementbasedsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/elementbasedsolution/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/elementbasedsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=3856b393 +build.xml.script.CRC32=5c47136e +build.xml.stylesheet.CRC32=a12b3d02 +# 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=3856b393 +nbproject/build-impl.xml.script.CRC32=6771a052 +nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/elementbasedsolution/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/elementbasedsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,56 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/elementbasedsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/elementbasedsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + elementbasedsolution + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/elementbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/elementbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,73 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + */ +public final class Circuit { + private Circuit() { + } + + public static Element and(final Element e1, final Element e2) { + return new Element() { + public boolean result() { + return e1.result() && e2.result(); + } + }; + } + public static Element or(final Element e1, final Element e2) { + return new Element() { + public boolean result() { + return e1.result() || e2.result(); + } + }; + } + + public static Element not(final Element e1) { + return new Element() { + public boolean result() { + return !e1.result(); + } + }; + } + + public static Variable var() { + return new Variable(); + } + + public static abstract class Element { + private Element() { + } + + public abstract boolean result(); + } + + public static final class Variable extends Element { + private boolean value; + + public void assignValue(boolean b) { + value = b; + } + + public boolean result() { + return value; + } + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/elementbasedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/elementbasedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,132 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + Circuit.Variable x1 = Circuit.var(); + Circuit.Variable x2 = Circuit.var(); + + Circuit.Element res = Circuit.and(x1, x2); + + x1.assignValue(false); + x2.assignValue(true); + assertFalse(res.result()); + + x1.assignValue(true); + x2.assignValue(true); + assertTrue(res.result()); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + Circuit.Variable x1 = Circuit.var(); + Circuit.Variable x2 = Circuit.var(); + Circuit.Variable x3 = Circuit.var(); + + Circuit.Element res = Circuit.or(Circuit.and(x1, x2), x3); + + x1.assignValue(false); + x2.assignValue(true); + x3.assignValue(false); + assertFalse(res.result()); + + x1.assignValue(false); + x2.assignValue(false); + x3.assignValue(true); + assertTrue(res.result()); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + Circuit.Variable x1 = Circuit.var(); + + Circuit.Element res = Circuit.or(x1, Circuit.not(x1)); + + x1.assignValue(false); + assertTrue(res.result()); + x1.assignValue(true); + assertTrue(res.result()); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project boolcircuit. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/nbproject/build-impl.xml Sat Jun 14 09:52:45 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,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=835ca895 +nbproject/build-impl.xml.script.CRC32=d896881b +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,58 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + inputandoperation + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/AndOperation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/AndOperation.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,31 @@ +/* + * AndOperation.java + * + * Created on July 12, 2006, 2:34 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +final class AndOperation extends Operation { + + private Input input1; + + private Input input2; + + /** Creates a new instance of AndOperation */ + AndOperation(Input in1, Input in2) { + input1 = in1; + input2 = in2; + } + + boolean performBooleanOperation() { + return input1.getBooleanValue() && input2.getBooleanValue(); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/BooleanInput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/BooleanInput.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,28 @@ +/* + * BooleanInput.java + * + * Created on July 12, 2006, 2:31 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +final class BooleanInput extends Input { + + private boolean value; + + /** Creates a new instance of BooleanInput */ + public BooleanInput(boolean val) { + value = val; + } + + public boolean getBooleanValue() { + return value; + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,29 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + */ +class Circuit { + + public static boolean evaluateBooleanOperation(Operation op) { + return op.performBooleanOperation(); + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/Factory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/Factory.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,55 @@ +/* + * Factory.java + * + * Created on July 12, 2006, 2:21 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +public class Factory { + + /** Creates a new instance of Factory */ + private Factory() { + } + + public static Input createSimpleBooleanInput(boolean value) { + return new BooleanInput(value); + } + + /** + * @throws IllegalArgument if the boolean operation was already used as input for another operation.. + */ + public static Input createOperationBasedBooleanInput(Operation op) throws IllegalArgumentException { + assert op != null; + if (op.isUsed()) { + throw new IllegalArgumentException("Cannot use a single operation repeatedly."); + } + op.markOperationAsUsed(); + return new OperationInput(op); + } + + public static Operation createAndOperation(Input one, Input two) { + assert one != null; + assert two != null; + return new AndOperation(one, two); + } + + public static Operation createOrOperation(Input one, Input two) { + assert one != null; + assert two != null; + return new OrOperation(one, two); + } + + public static Operation createNotOperation(Input one) { + assert one != null; + return new NotOperation(one); + } + + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/Input.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/Input.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,22 @@ +/* + * Input.java + * + * Created on July 12, 2006, 2:20 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +public abstract class Input { + + Input() { + + } + + public abstract boolean getBooleanValue(); +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/NotOperation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/NotOperation.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,28 @@ +/* + * NotOperation.java + * + * Created on July 12, 2006, 2:35 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +final class NotOperation extends Operation { + + private Input input; + + /** Creates a new instance of NotOperation */ + NotOperation(Input input) { + this.input = input; + } + + boolean performBooleanOperation() { + return !input.getBooleanValue(); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/Operation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/Operation.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,33 @@ +/* + * Operation.java + * + * Created on July 12, 2006, 2:26 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +public abstract class Operation { + + private boolean used; + + /** Creates a new instance of Operation */ + Operation() { + } + + abstract boolean performBooleanOperation(); + + void markOperationAsUsed() { + used = true; + } + + boolean isUsed() { + return used; + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/OperationInput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/OperationInput.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,26 @@ +/* + * OperationInput.java + * + * Created on July 12, 2006, 2:32 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +final class OperationInput extends Input { + private Operation operation; + /** Creates a new instance of OperationInput */ + public OperationInput(Operation oper) { + operation = oper; + } + + public boolean getBooleanValue() { + return operation.performBooleanOperation(); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/OrOperation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/OrOperation.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,31 @@ +/* + * OrOperation.java + * + * Created on July 12, 2006, 2:34 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +final class OrOperation extends Operation { + + private Input input1; + + private Input input2; + + /** Creates a new instance of orOperation */ + OrOperation(Input in1, Input in2) { + input1 = in1; + input2 = in2; + } + + boolean performBooleanOperation() { + return input1.getBooleanValue() || input2.getBooleanValue(); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/inputandoperation/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/inputandoperation/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,116 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + Input inTrue; + Input inFalse; + public CircuitTest(String testName) { + super(testName); + } + + // BEGIN: apifest.day1.inputandoperation.CircuitTest + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + inTrue = Factory.createSimpleBooleanInput(true); + inFalse = Factory.createSimpleBooleanInput(false); + Operation op1 = Factory.createAndOperation(inFalse, inTrue); + assertFalse(Circuit.evaluateBooleanOperation(op1)); + Operation op2 = Factory.createAndOperation(inTrue, inTrue); + assertTrue(Circuit.evaluateBooleanOperation(op2)); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + inTrue = Factory.createSimpleBooleanInput(true); + inFalse = Factory.createSimpleBooleanInput(false); + Operation op1 = Factory.createAndOperation(inFalse, inTrue); + Operation op2 = Factory.createOrOperation(Factory.createOperationBasedBooleanInput(op1), inFalse); + assertFalse(Circuit.evaluateBooleanOperation(op2)); + + op1 = Factory.createAndOperation(inFalse, inFalse); + op2 = Factory.createOrOperation(Factory.createOperationBasedBooleanInput(op1), inTrue); + assertTrue(Circuit.evaluateBooleanOperation(op2)); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + inTrue = Factory.createSimpleBooleanInput(true); + inFalse = Factory.createSimpleBooleanInput(false); + Operation not = Factory.createNotOperation(inTrue); + Operation or = Factory.createOrOperation(Factory.createOperationBasedBooleanInput(not), inTrue); + assertTrue(Circuit.evaluateBooleanOperation(or)); + not = Factory.createNotOperation(inFalse); + or = Factory.createOrOperation(Factory.createOperationBasedBooleanInput(not), inFalse); + assertTrue(Circuit.evaluateBooleanOperation(or)); + } + // END: apifest.day1.inputandoperation.CircuitTest +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/parsingsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/parsingsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project parsingsolution. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/parsingsolution/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/parsingsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/parsingsolution/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/parsingsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=97db7a12 +build.xml.script.CRC32=b2dbf729 +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=97db7a12 +nbproject/build-impl.xml.script.CRC32=41b27734 +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/parsingsolution/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/parsingsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,58 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/parsingsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/parsingsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + parsingsolution + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/parsingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/parsingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,60 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +// BEGIN: apifest.day1.parsingsolution.Circuit +/** + * Usage: + * First method parse must be called with valid logical expression on input. + * If it returns zero then it is possible to call method evaluate with array + * of input values as parameter. Method evaluate can be invoked many time with + * different input values. + * Method parse can be called anytime to change logical expression. + */ +public class Circuit { + + /** Parses logical expression + * @param string representation of logical expression + * Valid tokens: + * Input values are represented by x and number starting from 1 eg.: x1 + * AND, NOT, OR and brackets '(',')' can be used. + * Example of valid expression: x1 AND x2 + * @return 0 when input expression is validated and parsed. Return nonzero value otherwise. + */ + public int parse(String expression) { + return 0; + } + + /** Evaluate logical expression + * @param array of boolean input values. Size of array must correspond to number + * of variables used in expression + * If size of array is bigger then only first N values are used to evaluate expression. + * Remaining values are ignored. + * If size of array is smaller then IllegalArgumentException is thrown. + * If no expression is set by method parse then IllegalStateException is thrown. + */ + public boolean evaluate(boolean [] x) { + return true; + + } + +} +// END: apifest.day1.parsingsolution.Circuit + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/parsingsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/parsingsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,109 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + Circuit c = new Circuit(); + c.parse("x1 AND x2"); + assertFalse(c.evaluate(new boolean [] {Boolean.FALSE, Boolean.TRUE})); + assertTrue(c.evaluate(new boolean [] {Boolean.TRUE, Boolean.TRUE})); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + Circuit c = new Circuit(); + c.parse("(x1 AND x2) or x3"); + assertFalse(c.evaluate(new boolean [] {Boolean.FALSE, Boolean.TRUE, Boolean.FALSE})); + assertTrue(c.evaluate(new boolean [] {Boolean.FALSE, Boolean.FALSE, Boolean.TRUE})); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + Circuit c = new Circuit(); + c.parse("x1 or NOT x1"); + assertTrue(c.evaluate(new boolean [] {Boolean.FALSE})); + assertTrue(c.evaluate(new boolean [] {Boolean.TRUE})); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/pinbasedsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/pinbasedsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project pinbasedsolution. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/pinbasedsolution/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/pinbasedsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/pinbasedsolution/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/pinbasedsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=c2d9be31 +build.xml.script.CRC32=09dc18c1 +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=c2d9be31 +nbproject/build-impl.xml.script.CRC32=c591e2ef +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/pinbasedsolution/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/pinbasedsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,58 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/pinbasedsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/pinbasedsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + pinbasedsolution + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/pinbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/pinbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,71 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * A representation of a logic circuit. + * It can only be constructed from an element net. + * Usage: + *
+ *  Circuit c = Circuit.construct(
+ *      Element.createOr(
+ *          Element.createAnd(
+ *              Element.createInput(0),
+ *              Element.createInput(1)
+ *          ),
+ *          Element.createInput(2)
+ *      )
+ *  );
+ *            
+ *  boolean val = c.evaluate(false, true, false));
+ * 
+ */ +public class Circuit { + Element root; + int pins; + + private Circuit(Element elem) { + root = elem; + pins = 1 + root.maxInput(); + } + + /** + * Evaluate output of the circuit for given inputs. + * For general + */ + public boolean evaluate(Boolean ... inputs) throws UnstableException { + if (inputs.length != pins) throw new IllegalArgumentException("Wrong number of inputs, " + pins + " expected."); + boolean[] inp = new boolean[pins]; + for (int i=0; i + * The basic elements include: + * + * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + // BEGIN: apifest.day1.pinbasedsolution.CircuitTest + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() throws Exception { + Circuit c = Circuit.construct( + Element.createAnd( + Element.createInput(0), + Element.createInput(1) + ) + ); + + assertFalse ("false AND true is false", c.evaluate(false, true)); + assertTrue ("true AND true is true", c.evaluate(true, true)); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() throws Exception { + Circuit c = Circuit.construct( + Element.createOr( + Element.createAnd( + Element.createInput(0), + Element.createInput(1) + ), + Element.createInput(2) + ) + ); + + assertFalse ("(false AND true) OR false is false", c.evaluate(false, true, false)); + assertTrue ("(false AND false) OR true is true", c.evaluate(false, false, true)); + } + + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() throws Exception { + Circuit c = Circuit.construct( + Element.createOr( + Element.createInput(0), + Element.createNot(Element.createInput(0)) + ) + ); + + assertTrue ("tautology is true", c.evaluate(false)); + assertTrue ("tautology is true", c.evaluate(true)); + } + // END: apifest.day1.pinbasedsolution.CircuitTest +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/stackbasedsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/stackbasedsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project stackbasedsolution. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/stackbasedsolution/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/stackbasedsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/stackbasedsolution/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/stackbasedsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=10562595 +build.xml.script.CRC32=8e100d5a +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=10562595 +nbproject/build-impl.xml.script.CRC32=4a74b13c +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/stackbasedsolution/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/stackbasedsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,58 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/stackbasedsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/stackbasedsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + stackbasedsolution + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,28 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.util.Stack; + +/** + */ +public interface Circuit { + public char evaluate (Stack input) throws IllegalArgumentException; +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/CircuitFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/CircuitFactory.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,50 @@ +/* + * CircuitFactory.java + * + * Created on July 12, 2006, 3:01 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.util.Stack; + +/** + * + */ +public class CircuitFactory { + + /** Creates a new instance of CircuitFactory */ + private CircuitFactory() { + } + + public final static Circuit join (final Circuit c1, final Circuit c2, final Operation op) { + return new Circuit () { + public char evaluate(Stack input) throws IllegalArgumentException { + return op.evaluate(c1.evaluate(input), c2.evaluate(input)); + } + }; + } + + public final static Circuit getBasicCircuit (final Operation op) { + return new Circuit () { + public char evaluate(Stack input) throws IllegalArgumentException { + // special handling of unary oparation + if (op instanceof Operation.Neg) { + return op.evaluate(input.pop(), input.peek()); + } else { + return op.evaluate(input.pop(), input.pop()); + } + } + }; + } + public final static Circuit getTrivialCircuit () { + return new Circuit () { + public char evaluate(Stack input) throws IllegalArgumentException { + return input.peek(); + } + }; + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/Operation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/Operation.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,53 @@ +/* + * Operation.java + * + * Created on July 12, 2006, 3:06 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +public interface Operation { + public char evaluate (char i1, char i2) throws IllegalArgumentException; + public final static Operation OR = new Or (); + public final static Operation AND = new And (); + public final static Operation NEG = new Neg (); + + + static class And implements Operation { + public char evaluate(char i1, char i2) throws IllegalArgumentException { + if (i1 != '0' && i1 != '1') { + throw new IllegalArgumentException ("Invalid input parameter: " + i1); + } + if (i2 != '0' && i2 != '1') { + throw new IllegalArgumentException ("Invalid input parameter: " + i2); + } + return i1 == '1' && i2 == '1' ? '1' : '0'; + } + } + static class Or implements Operation { + public char evaluate(char i1, char i2) throws IllegalArgumentException { + if (i1 != '0' && i1 != '1') { + throw new IllegalArgumentException ("Invalid input parameter: " + i1); + } + if (i2 != '0' && i2 != '1') { + throw new IllegalArgumentException ("Invalid input parameter: " + i2); + } + return i1 == '1' || i2 == '1' ? '1' : '0'; + } + } + static class Neg implements Operation { + public char evaluate(char i1, char i2) throws IllegalArgumentException { + if (i1 != '0' && i1 != '1') { + throw new IllegalArgumentException ("Invalid input parameter: " + i1); + } + return i1 == '1' ? '0' : '1'; + } + } +} + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/stackbasedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/stackbasedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,107 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.util.Arrays; +import java.util.Stack; +import junit.framework.TestCase; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

    + *
  • negation - has one input and one output and changes 0 on input to + * on output 1 and 1 to 0 + *
  • and - has two inputs and one output. The output is 1 only if both + * inputs are 1, otherwise it is 0 + *
  • or - has two inputs and one output. The output is 1 always, except + * in the case when both inputs are 0 + *
+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + // BEGIN: apifest.day1.stackbasedsolution.CircuitTest + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + Stack s = new Stack (); + s.addAll(Arrays.asList('1', '1')); + assertEquals("'1' for '11' input.", '1', CircuitFactory.getBasicCircuit(Operation.AND).evaluate(s)); + s.addAll(Arrays.asList('1', '0')); + assertEquals("'0' for '10' input.", '0', CircuitFactory.getBasicCircuit(Operation.AND).evaluate(s)); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + Stack s = new Stack (); + s.addAll(Arrays.asList('0', '1', '0')); + assertEquals("'0' for '010' input.", '0', CircuitFactory.join(CircuitFactory.getTrivialCircuit(), CircuitFactory.getBasicCircuit(Operation.OR), Operation.AND).evaluate(s)); + s.addAll(Arrays.asList('0', '0', '1')); + assertEquals("'1' for '001' input.", '1', CircuitFactory.join(CircuitFactory.getTrivialCircuit(), CircuitFactory.getBasicCircuit(Operation.OR), Operation.AND).evaluate(s)); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + Circuit alwaysTrue = CircuitFactory.join(CircuitFactory.getTrivialCircuit(), CircuitFactory.getBasicCircuit(Operation.NEG), Operation.OR); + Stack s = new Stack (); + s.addAll(Arrays.asList('0', '0')); + assertEquals ("'1' for '00'", '1', alwaysTrue.evaluate(s)); + s.addAll(Arrays.asList('1', '1')); + assertEquals ("'1' for '11'", '1', alwaysTrue.evaluate(s)); + } + // END: apifest.day1.stackbasedsolution.CircuitTest +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/subclassingsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/subclassingsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project boolcircuit. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/subclassingsolution/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/subclassingsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/subclassingsolution/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/subclassingsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=2ab820eb +build.xml.script.CRC32=58a52595 +build.xml.stylesheet.CRC32=a12b3d02 +# 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=0f6dc18a +nbproject/build-impl.xml.script.CRC32=079f4b62 +nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/subclassingsolution/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/subclassingsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,54 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +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} +src.dir=src +test.src.dir=test +libs.junit.classpath=../../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/subclassingsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/subclassingsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + subclassingsolution + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/subclassingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/subclassingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,70 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + + +/** Usefull class for building your own circuits. + * + */ +public abstract class Circuit extends Object { + + /** For your conveninece */ + public static Circuit AND = new Circuit() { + + @Override + public boolean evaluate(boolean[] in) { + if ( in.length != 2) { + throw new IllegalArgumentException( "Should have two parameters"); + } + return in[0] && in[1]; + } + + }; + + public static Circuit OR = new Circuit() { + + @Override + public boolean evaluate(boolean[] in) { + if ( in.length != 2) { + throw new IllegalArgumentException( "Should have two parameters"); + } + return in[0] || in[1]; + } + + }; + + public static Circuit NOT = new Circuit() { + + @Override + public boolean evaluate(boolean[] in) { + if ( in.length != 1) { + throw new IllegalArgumentException( "Should have one parameter"); + } + return !in[0]; + } + + }; + + + /** Feel free to implement and don't hesitate to throw IllegalArgumentEception + */ + public abstract boolean evaluate(boolean... in); + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/subclassingsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/subclassingsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,136 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +import static org.netbeans.apifest.boolcircuit.Circuit.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

    + *
  • negation - has one input and one output and changes 0 on input to + * on output 1 and 1 to 0 + *
  • and - has two inputs and one output. The output is 1 only if both + * inputs are 1, otherwise it is 0 + *
  • or - has two inputs and one output. The output is 1 always, except + * in the case when both inputs are 0 + *
+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + + + + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + + assertFalse( AND.evaluate( false, true )); + assertTrue( AND.evaluate( true, true )); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + + Circuit c = new Circuit() { + + @Override + public boolean evaluate(boolean[] in) { + if ( in.length != 3) { + throw new IllegalArgumentException( "Should have one parameter"); + } + return OR.evaluate( AND.evaluate( in[0], in[1] ), in[2] ); + } + + }; + + assertFalse( c.evaluate( false, true, false ) ); + assertTrue( c.evaluate( false, false, true ) ); + + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + + Circuit c = new Circuit() { + + @Override + public boolean evaluate(boolean[] in) { + if ( in.length != 1) { + throw new IllegalArgumentException( "Should have three parameters"); + } + return OR.evaluate( in[0], NOT.evaluate( in[0] ) ); + } + + }; + + assertTrue( c.evaluate( true ) ); + assertTrue( c.evaluate( false ) ); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/welltestedsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/welltestedsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project welltestedsolution. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/welltestedsolution/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/welltestedsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/welltestedsolution/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/welltestedsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=3022b908 +build.xml.script.CRC32=fdb77cae +build.xml.stylesheet.CRC32=a12b3d02 +# 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=3022b908 +nbproject/build-impl.xml.script.CRC32=b9627854 +nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/welltestedsolution/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/welltestedsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,56 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/welltestedsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/welltestedsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + welltestedsolution + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/welltestedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/welltestedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,162 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + */ +public abstract class Circuit { + + public static Circuit createNotCircuit(Circuit in) { + return new NotCircuit(in); + } + + public static Circuit createOrCircuit(Circuit in1, Circuit in2) { + return new OrCircuit(in1, in2); + } + + public static Circuit createAndCircuit(Circuit in1, Circuit in2) { + return new AndCircuit(in1, in2); + } + + private Circuit() { + + } + + public abstract boolean evaluate(Boolean ... inputs); + + abstract int inputs(); + + private static class NotCircuit extends Circuit { + + private Circuit in; + + NotCircuit (Circuit in) { + this.in = in; + } + + int inputs() { + return in == null? 1: in.inputs(); + } + + public boolean evaluate (Boolean ... inputs) { + if (inputs == null || inputs.length != inputs()) { + throw new IllegalArgumentException(); + } + Boolean o = inputs[0]; + if (in != null) { + return !in.evaluate(inputs); + } + else if (o != null) { + return !o.booleanValue(); + } + throw new IllegalArgumentException(); + } + } + + private static class AndCircuit extends Circuit { + private Circuit in1, in2; + + AndCircuit (Circuit in1, Circuit in2) { + this.in1 = in1; + this.in2 = in2; + } + + int inputs() { + return (in1 == null? 1: in1.inputs()) + (in2 == null? 1: in2.inputs()) ; + } + + public boolean evaluate (Boolean ... inputs) { + if (inputs == null || inputs.length != inputs()) { + throw new IllegalArgumentException(); + } + boolean x1, x2; + Boolean o1 = inputs[0]; + if (in1 != null) { + Boolean[] ins1 = new Boolean[in1.inputs()]; + System.arraycopy(inputs, 0, ins1, 0, in1.inputs()); + x1 = in1.evaluate(ins1); + } + else if (o1 != null) { + x1 = o1.booleanValue(); + } + else { + throw new IllegalArgumentException(); + } + Boolean o2 = inputs[in1 != null? in1.inputs(): 1]; + if (in2 != null) { + Boolean[] ins2 = new Boolean[in2.inputs()]; + System.arraycopy(inputs, in1 != null? in1.inputs(): 1, ins2, 0, in2.inputs()); + x2 = in2.evaluate(ins2); + } + else if (o2 != null) { + x2 = o2.booleanValue(); + } + else { + throw new IllegalArgumentException(); + } + return x1 && x2; + } + } + + private static class OrCircuit extends Circuit { + private Circuit in1, in2; + + OrCircuit (Circuit in1, Circuit in2) { + this.in1 = in1; + this.in2 = in2; + } + + int inputs() { + return (in1 == null? 1: in1.inputs()) + (in2 == null? 1: in2.inputs()) ; + } + + public boolean evaluate (Boolean ... inputs) { + if (inputs == null || inputs.length != inputs()) { + throw new IllegalArgumentException(); + } + boolean x1, x2; + Boolean o1 = inputs[0]; + if (in1 != null) { + Boolean[] ins1 = new Boolean[in1.inputs()]; + System.arraycopy(inputs, 0, ins1, 0, in1.inputs()); + x1 = in1.evaluate(ins1); + } + else if (o1 != null) { + x1 = o1.booleanValue(); + } + else { + throw new IllegalArgumentException(); + } + Boolean o2 = inputs[in1 != null? in1.inputs(): 1]; + if (in2 != null) { + Boolean[] ins2 = new Boolean[in2.inputs()]; + System.arraycopy(inputs, in1 != null? in1.inputs(): 1, ins2, 0, in2.inputs()); + x2 = in2.evaluate(ins2); + } + else if (o2 != null) { + x2 = o2.booleanValue(); + } + else { + throw new IllegalArgumentException(); + } + return x1 || x2; + } + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day1/welltestedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day1/welltestedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,165 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

    + *
  • negation - has one input and one output and changes 0 on input to + * on output 1 and 1 to 0 + *
  • and - has two inputs and one output. The output is 1 only if both + * inputs are 1, otherwise it is 0 + *
  • or - has two inputs and one output. The output is 1 always, except + * in the case when both inputs are 0 + *
+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + assertFalse("x1 and x2 for (false, true)", Circuit.createAndCircuit(null, null).evaluate(false, true)); + assertTrue("x1 and x2 for (true, true)", Circuit.createAndCircuit(null, null).evaluate(true, true)); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + Circuit c = Circuit.createOrCircuit(Circuit.createAndCircuit(null, null), null); + assertFalse("(x1 and x2) or x3", c.evaluate(false, true, false)); + assertTrue("(x1 and x2) or x3", c.evaluate(false, false, true)); + + assertTrue("(x1 and x2) or x3", c.evaluate(true, true, true)); + assertFalse("(x1 and x2) or x3", c.evaluate(true, false, false)); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + Circuit c = Circuit.createOrCircuit(null, Circuit.createNotCircuit(null)); + assertTrue("(x1 or not(x1)) for false", c.evaluate(false, false)); + assertTrue("(x1 or not(x1)) for false", c.evaluate(true, true)); + } + + public void testOr() { + Circuit c = Circuit.createOrCircuit(null, null); + try { + c.evaluate(); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true, true, true); + } catch (IllegalArgumentException iae) { // expected + } + assertFalse("(x1 or x2)", c.evaluate(false, false)); + assertTrue("(x1 or x2)", c.evaluate(true, false)); + assertTrue("(x1 or x2)", c.evaluate(false, true)); + assertTrue("(x1 or x2)", c.evaluate(true, true)); + + } + + public void testAnd() { + Circuit c = Circuit.createAndCircuit(null, null); + try { + c.evaluate(); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true, true, true); + } catch (IllegalArgumentException iae) { // expected + } + assertFalse("(x1 or x2)", c.evaluate(false, false)); + assertFalse("(x1 or x2)", c.evaluate(true, false)); + assertFalse("(x1 or x2)", c.evaluate(false, true)); + assertTrue("(x1 or x2)", c.evaluate(true, true)); + + } + + public void testNot() { + Circuit c = Circuit.createNotCircuit(null); + try { + c.evaluate(); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true, true); + } catch (IllegalArgumentException iae) { // expected + } + assertFalse("(x1 or x2)", c.evaluate(true)); + assertTrue("(x1 or x2)", c.evaluate(false)); + + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/alwayscreatenewcircuit/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project alwayscreatenewcircuit. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/alwayscreatenewcircuit/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/alwayscreatenewcircuit/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=ffd6778c +build.xml.script.CRC32=f0487089 +build.xml.stylesheet.CRC32=a12b3d02 +# 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=ffd6778c +nbproject/build-impl.xml.script.CRC32=20ec1204 +nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/alwayscreatenewcircuit/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,56 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/alwayscreatenewcircuit/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + alwayscreatenewcircuit + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/alwayscreatenewcircuit/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,234 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashSet; + +/** + */ +public abstract class Circuit { + /** Creates a new instance of Circuits */ + protected Circuit() { + } + + public static Circuit negate(Input input) { + return new Negation(new Primitive(input)); + } + + @Deprecated + public static Circuit negate(boolean input) { + return new Negation(input); + } + + public static Circuit negate(Circuit input) { + return new Negation(input); + } + + public static Circuit and(Input input1, Input input2) { + return new And(new Primitive(input1), new Primitive(input2)); + } + + @Deprecated + public static Circuit and(boolean input1, boolean input2) { + return new And(input1, input2); + } + + public static Circuit and(Circuit input1, Input input2) { + return new And(input1, new Primitive(input2)); + } + + @Deprecated + public static Circuit and(Circuit input1, boolean input2) { + return new And(input1, new Primitive(input2)); + } + + public static Circuit and(Input input1, Circuit input2) { + return new And(new Primitive(input1), input2); + } + + @Deprecated + public static Circuit and(boolean input1, Circuit input2) { + return new And(new Primitive(input1), input2); + } + + public static Circuit and(Circuit input1, Circuit input2) { + return new And(input1, input2); + } + + public static Circuit or(Input input1, Input input2) { + return new Or(new Primitive(input1), new Primitive(input2)); + } + + @Deprecated + public static Circuit or(boolean input1, boolean input2) { + return new Or(input1, input2); + } + + public static Circuit or(Circuit input1, Input input2) { + return new Or(input1, new Primitive(input2)); + } + + @Deprecated + public static Circuit or(Circuit input1, boolean input2) { + return new Or(input1, new Primitive(input2)); + } + + public static Circuit or(Input input1, Circuit input2) { + return new Or(new Primitive(input1), input2); + } + + @Deprecated + public static Circuit or(boolean input1, Circuit input2) { + return new Or(new Primitive(input1), input2); + } + + public static Circuit or(Circuit input1, Circuit input2) { + return new Or(input1, input2); + } + + + public final boolean output() { + double v = value(); + if (v > 1 || v < 0) { + throw new IllegalArgumentException(); + } + return (v > 0) ? true : false; + } + + private static final double check(double v) { + if (v > 1 || v < 0) { + throw new IllegalArgumentException(); + } + return v; + } + + + public abstract double value(); + + private final static class Primitive extends Circuit { + private Input input; + + Primitive(boolean input) { + this.input = new Input(input); + } + + Primitive(Input input) { + this.input = input; + } + + + + public double value() { + return input.getValue(); + } + } + + private final static class Negation extends Circuit { + private Circuit input; + + @Deprecated + Negation(boolean input) { + this.input = new Primitive(input); + } + + Negation(Circuit input) { + this.input = input; + } + + + public double value() { + double x = input.value(); + return check(1-x); + } + } + + private static class And extends Circuit { + Circuit input1; + Circuit input2; + + And(boolean input1, boolean input2) { + this.input1 = new Primitive(input1); + this.input2 = new Primitive(input2); + } + + And(Circuit input1, Circuit input2) { + this.input1 = input1; + this.input2 = input2; + } + + public double value() { + double x = input1.value(); + double y = input2.value(); + return check(x * y); + } + } + + private final static class Or extends And { + Or(boolean input1, boolean input2) { + super(input1, input2); + } + + Or(Circuit input1, Circuit input2) { + super(input1, input2); + } + + public double value() { + double x = input1.value(); + double y = input2.value(); + + return check(1 - (1 - x) * (1 - y)); + } + } + + public static class Input { + private double value; + + public static Input valueOf(boolean initValue) { + return new Input(initValue); + } + + public static Input valueOf(double initValue) { + return new Input(initValue); + } + + /** Creates a new instance of Input */ + private Input(boolean input) { + setValue(input); + } + + private Input(double input) { + setValue(input); + } + + public double getValue() { + return value; + } + + public void setValue(double input) { + value = input; + } + + public void setValue(boolean input) { + value = (input) ? 1 : 0; + } + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/alwayscreatenewcircuit/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,125 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

    + *
  • negation - has one input and one output and changes 0 on input to + * on output 1 and 1 to 0 + *
  • and - has two inputs and one output. The output is 1 only if both + * inputs are 1, otherwise it is 0 + *
  • or - has two inputs and one output. The output is 1 always, except + * in the case when both inputs are 0 + *
+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + boolean x1 = true; + boolean x2 = true; + + Circuit outputCircuit = Circuit.and(x1, x2); + assertTrue(outputCircuit.output()); + + x1 = false; + x2 = true; + outputCircuit = Circuit.and(x1, x2); + assertFalse(outputCircuit.output()); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + boolean x1 = false; + boolean x2 = true; + boolean x3 = false; + Circuit outputCircuit = Circuit.or(Circuit.and(x1,x2),x3); + assertFalse(outputCircuit.output()); + + x1 = false; + x2 = false; + x3 = true; + outputCircuit = Circuit.or(Circuit.and(x1,x2),x3); + assertTrue(outputCircuit.output()); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + boolean x1 = true; + Circuit outputCircuit = Circuit.or(x1,Circuit.negate(x1)); + assertTrue(outputCircuit.output()); + + x1 = false; + outputCircuit = Circuit.or(x1,Circuit.negate(x1)); + assertTrue(outputCircuit.output()); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/alwayscreatenewcircuit/test/org/netbeans/apifest/boolcircuit/RealTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/test/org/netbeans/apifest/boolcircuit/RealTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,171 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** This file contains the APIFest quest for day 2. Simply, turn the + * boolean circuit into circuit that can compute with double values from 0 to 1. + *

+ * This means that where ever a boolean was used to represent input or + * output values, one can now use any double number from >= 0 and <= 1. + * Still, to support backward compatibility, the operations with booleans + * has to be kept available and have to work. In fact False shall be + * treated as 0 and True as 1. + *

+ * The basic elements has to be modified to work on doubles in the following + * way: + *

    + *
  • negation - neg(x) = 1 - x, this is correct extension as neg(false)=neg(0)=1-0=1=true + *
  • and - and(x,y) = x * y, again this is fine as and(true,true)=1*1=true and also + * and(false,true)=0*1=0=false + *
  • or - or(x,y) = 1 - (1 - x) * (1 - y) and this is also ok as + * or(false,false) = 1 - (1 - 0) * (1 - 0) = 1 - 1 = 0 = false + * or(true,false) = 1 - (1 - 1) * (1 - 0) = 1 - 0 * 1 = 1 = true + *
+ *

+ * However as the circuits with doubles are more rich than plain boolean circuits, + * there is additional requirement to allow any user of your API to write its + * own "element" type. This is all going to be exercise in the tests bellow + * which you are supposed to implement. + */ +public class RealTest extends TestCase { + static { + // your code shall run without any permissions + } + + public RealTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** First of all create a circuit which will evaluate + * expression (X1 and X2) or not(x1). Hold the circuit + * in some variable. + * + * Feed this circuit with x1=true, x2=false, assert result is false + * + * Feed the same circuit with x1=false, x2=true, assert result is true + * + * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0 + * + * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625 + * + * Feed the same circuit with x1=0.0, x2=2.0, make sure it throws an exception + */ + public void testX1andX2orNotX1() { + Circuit.Input x1 = Circuit.Input.valueOf(true); + Circuit.Input x2 = Circuit.Input.valueOf(false); + Circuit c = Circuit.or(Circuit.and(x1,x2), Circuit.negate(x1)); + assertFalse(c.output()); + + x1.setValue(false); + x2.setValue(true); + assertTrue(c.output()); + + x1.setValue(0.0); + x2.setValue(1.0); + assertTrue(c.output()); + + x1.setValue(0.5); + x2.setValue(0.5); + assertEquals(0.625, c.value()); + + try { + x1.setValue(1.0); + x2.setValue(2.0); + c.value(); + fail(); + } catch(IllegalArgumentException iae) { + + } + } + + /** Ensure that one variable cannot be filled with two different values. + * Create a circuit for x1 and x1. Make sure that for any usage of your + * API that would not lead to x1 * x1 result, an exception is thrown. + * For example if there was a way to feed the circuit with two different + * values 0.3 and 0.5 an exception is thrown indicating that this is + * improper use of the circuit. + */ + public void testImproperUseOfTheCircuit() { + assertTrue(true); + } + + /** Write your own element type called "gte" that will have two inputs and one output. + * The output value will be 1 if x1 >= x2 and 0 otherwise. + * + * Create + * circuit for following expression: (x1 and not(x1)) gte x1 + * + * Feed the circuit with 0.5 and verify the result is 0 + * + * Feed the same circuit with 1 and verify the result is 0 + * + * Feed the same circuit with 0 and verify the result is 1 + */ + public void testGreaterThanEqualElement() { + class Comp extends Circuit { + Circuit i1; + Circuit i2; + Comp(Circuit i1, Circuit i2) { + this.i1 = i1; + this.i2 = i2; + } + + public double value() { + double x1 = i1.value(); + double x2 = i2.value(); + return (x1 >= x2) ? 1 : 0; + } + } + + + + Circuit.Input x1 = Circuit.Input.valueOf(0.5); + + Circuit c1 = Circuit.and(x1, Circuit.negate(x1)); + Circuit c2 = Circuit.negate(Circuit.negate(x1)); + + Circuit comp = new Comp(c1, c2); + assertEquals(0.0, comp.value()); + + x1.setValue(1); + assertEquals(0.0, comp.value()); + + x1.setValue(0); + assertEquals(1.0, comp.value()); + + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/elementbasedsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/elementbasedsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project elementbasedsolution. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/elementbasedsolution/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/elementbasedsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/elementbasedsolution/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/elementbasedsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=3856b393 +build.xml.script.CRC32=5c47136e +build.xml.stylesheet.CRC32=a12b3d02 +# 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=3856b393 +nbproject/build-impl.xml.script.CRC32=6771a052 +nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/elementbasedsolution/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/elementbasedsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,56 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/elementbasedsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/elementbasedsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + elementbasedsolution + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/elementbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/elementbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,115 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + */ +public final class Circuit { + private Circuit() { + } + + public static Element and(final Element e1, final Element e2) { + return new Element() { + public boolean result() { + return e1.result() && e2.result(); + } + public double doubleResult() { + return e1.doubleResult() * e2.doubleResult(); + } + }; + } + public static Element or(final Element e1, final Element e2) { + return new Element() { + public boolean result() { + return e1.result() || e2.result(); + } + public double doubleResult() { + return 1.0 - (1.0 - e1.doubleResult()) * (1.0 - e2.doubleResult()); + } + }; + } + + public static Element not(final Element e1) { + return new Element() { + public boolean result() { + return !e1.result(); + } + public double doubleResult() { + return 1 - e1.doubleResult(); + } + }; + } + + public static Element operation(final Operation op, final Element... elements) { + return new Element() { + public boolean result() { + return doubleResult() >= 1.0; + } + public double doubleResult() { + double[] arr = new double[elements.length]; + for (int i = 0; i < arr.length; i++) { + arr[i] = elements[i].doubleResult(); + } + return op.computeResult(arr); + } + }; + + } + + public static Variable var() { + return new Variable(); + } + + public static abstract class Element { + private Element() { + } + + public abstract boolean result(); + public abstract double doubleResult(); + } + + public static final class Variable extends Element { + private Boolean booleanValue; + private Double doubleValue; + + public void assignValue(boolean b) { + booleanValue = b; + } + public void assignValue(double d) { + if (d < 0 || d > 1) { + throw new IllegalArgumentException(); + } + doubleValue = d; + } + + public boolean result() { + return booleanValue != null ? booleanValue : doubleValue >= 1.0; + } + + public double doubleResult() { + return doubleValue != null ? doubleValue : (booleanValue ? 1.0 : 0.0); + } + + } + + public static interface Operation { + public double computeResult(double... values); + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/elementbasedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/elementbasedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,132 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

    + *
  • negation - has one input and one output and changes 0 on input to + * on output 1 and 1 to 0 + *
  • and - has two inputs and one output. The output is 1 only if both + * inputs are 1, otherwise it is 0 + *
  • or - has two inputs and one output. The output is 1 always, except + * in the case when both inputs are 0 + *
+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + Circuit.Variable x1 = Circuit.var(); + Circuit.Variable x2 = Circuit.var(); + + Circuit.Element res = Circuit.and(x1, x2); + + x1.assignValue(false); + x2.assignValue(true); + assertFalse(res.result()); + + x1.assignValue(true); + x2.assignValue(true); + assertTrue(res.result()); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + Circuit.Variable x1 = Circuit.var(); + Circuit.Variable x2 = Circuit.var(); + Circuit.Variable x3 = Circuit.var(); + + Circuit.Element res = Circuit.or(Circuit.and(x1, x2), x3); + + x1.assignValue(false); + x2.assignValue(true); + x3.assignValue(false); + assertFalse(res.result()); + + x1.assignValue(false); + x2.assignValue(false); + x3.assignValue(true); + assertTrue(res.result()); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + Circuit.Variable x1 = Circuit.var(); + + Circuit.Element res = Circuit.or(x1, Circuit.not(x1)); + + x1.assignValue(false); + assertTrue(res.result()); + x1.assignValue(true); + assertTrue(res.result()); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/elementbasedsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/elementbasedsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,164 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** This file contains the APIFest quest for day 2. Simply, turn the + * boolean circuit into circuit that can compute with double values from 0 to 1. + *

+ * This means that where ever a boolean was used to represent input or + * output values, one can now use any double number from >= 0 and <= 1. + * Still, to support backward compatibility, the operations with booleans + * has to be kept available and have to work. In fact False shall be + * treated as 0 and True as 1. + *

+ * The basic elements has to be modified to work on doubles in the following + * way: + *

    + *
  • negation - neg(x) = 1 - x, this is correct extension as neg(false)=neg(0)=1-0=1=true + *
  • and - and(x,y) = x * y, again this is fine as and(true,true)=1*1=true and also + * and(false,true)=0*1=0=false + *
  • or - or(x,y) = 1 - (1 - x) * (1 - y) and this is also ok as + * or(false,false) = 1 - (1 - 0) * (1 - 0) = 1 - 1 = 0 = false + * or(true,false) = 1 - (1 - 1) * (1 - 0) = 1 - 0 * 1 = 1 = true + *
+ *

+ * However as the circuits with doubles are more rich than plain boolean circuits, + * there is additional requirement to allow any user of your API to write its + * own "element" type. This is all going to be exercise in the tests bellow + * which you are supposed to implement. + */ +public class RealTest extends TestCase { + static { + // your code shall run without any permissions + } + + public RealTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** First of all create a circuit which will evaluate + * expression (X1 and X2) or not(x1). Hold the circuit + * in some variable. + * + * Feed this circuit with x1=true, x2=false, assert result is false + * + * Feed the same circuit with x1=false, x2=true, assert result is true + * + * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0 + * + * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625 + * + * Feed the same circuit with x1=0.0, x2=2.0, make sure it throws an exception + */ + public void testX1andX2orNotX1() { + Circuit.Variable x1 = Circuit.var(); + Circuit.Variable x2 = Circuit.var(); + + Circuit.Element el = Circuit.or( + Circuit.and(x1, x2), + Circuit.not(x1) + ); + + x1.assignValue(true); x2.assignValue(false); + assertFalse(el.result()); + + x1.assignValue(false); x2.assignValue(true); + assertTrue(el.result()); + + x1.assignValue(0.0); x2.assignValue(1.0); + assertEquals(1.0, el.doubleResult()); + + x1.assignValue(0.5); x2.assignValue(0.5); + assertEquals(0.625, el.doubleResult()); + + try { + x1.assignValue(0.0); x2.assignValue(2.0); + fail("Should throw an exception"); + } catch (IllegalArgumentException ex) { + // ok + } + } + + /** Ensure that one variable cannot be filled with two different values. + * Create a circuit for x1 and x1. Make sure that for any usage of your + * API that would not lead to x1 * x1 result, an exception is thrown. + * For example if there was a way to feed the circuit with two different + * values 0.3 and 0.5 an exception is thrown indicating that this is + * improper use of the circuit. + */ + public void testImproperUseOfTheCircuit() { + // no way to get 0.3 * 0.5 from the circuit + Circuit.Variable x1 = Circuit.var(); + Circuit.Element el = Circuit.and(x1, x1); + + x1.assignValue(0.3); + assertEquals(0.3 * 0.3, el.doubleResult()); + + x1.assignValue(0.5); + assertEquals(0.5 * 0.5, el.doubleResult()); + } + + /** Write your own element type called "gte" that will have two inputs and one output. + * The output value will be 1 if x1 >= x2 and 0 otherwise. + * + * Create + * circuit for following expression: (x1 and not(x1)) gte x1 + * + * Feed the circuit with 0.5 and verify the result is 0 + * + * Feed the same circuit with 1 and verify the result is 0 + * + * Feed the same circuit with 0 and verify the result is 1 + */ + public void testGreaterThanElement() { + class GreaterThanEqual implements Circuit.Operation { + public double computeResult(double... values) { + return values[0] >= values[1] ? 1.0 : 0.0; + } + } + Circuit.Variable x1 = Circuit.var(); + Circuit.Element gte = Circuit.operation( + new GreaterThanEqual(), + Circuit.and(x1, Circuit.not(x1)), + x1 + ); + + x1.assignValue(0.5); assertEquals(0.0, gte.doubleResult()); + x1.assignValue(1.0); assertEquals(0.0, gte.doubleResult()); + x1.assignValue(0.0); assertEquals(1.0, gte.doubleResult()); + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project boolcircuit. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,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=835ca895 +nbproject/build-impl.xml.script.CRC32=7f83eb6b +nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,56 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + inputandoperation + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/AndOperation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/AndOperation.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,35 @@ +/* + * AndOperation.java + * + * Created on July 12, 2006, 2:34 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +final class AndOperation extends Operation { + + private Input input1; + + private Input input2; + + /** Creates a new instance of AndOperation */ + AndOperation(Input in1, Input in2) { + input1 = in1; + input2 = in2; + } + + public boolean performBooleanOperation() { + return input1.getBooleanValue() && input2.getBooleanValue(); + } + + public double performRealOperation() { + return input1.getRealValue() * input2.getRealValue(); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/BooleanInput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/BooleanInput.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,32 @@ +/* + * BooleanInput.java + * + * Created on July 12, 2006, 2:31 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +final class BooleanInput extends Input { + + private boolean value; + + /** Creates a new instance of BooleanInput */ + public BooleanInput(boolean val) { + value = val; + } + + public boolean getBooleanValue() { + return value; + } + + public double getRealValue() { + return value ? 1f : 0f; + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,33 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + */ +class Circuit { + + public static boolean evaluateBooleanOperation(Operation op) { + return op.performBooleanOperation(); + } + + public static double evaluateRealOperation(Operation op) { + return op.performRealOperation(); + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/Factory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/Factory.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,70 @@ +/* + * Factory.java + * + * Created on July 12, 2006, 2:21 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +public class Factory { + + /** Creates a new instance of Factory */ + private Factory() { + } + + /** + * @deprecated use for constants only.. use VariableInput instead.. + */ + public static Input createSimpleBooleanInput(boolean value) { + return new BooleanInput(value); + } + + public static VariableInput createVariableInput() { + return new VariableInput(); + } + /** + * @throws IllegalArgument if the boolean operation was already used as input for another operation.. + * @deprecated + */ + public static Input createOperationBasedBooleanInput(Operation op) throws IllegalArgumentException { + assert op != null; + if (op.isUsed()) { + throw new IllegalArgumentException("Cannot use a single operation repeatedly."); + } + op.markOperationAsUsed(); + return new OperationInput(op); + } + + /** + * WTF, just make another reasonable sounding factory method now that we have reals.. + */ + + public static Input createOperationBasedInput(Operation op) throws IllegalArgumentException { + return createOperationBasedBooleanInput(op); + } + + public static Operation createAndOperation(Input one, Input two) { + assert one != null; + assert two != null; + return new AndOperation(one, two); + } + + public static Operation createOrOperation(Input one, Input two) { + assert one != null; + assert two != null; + return new OrOperation(one, two); + } + + public static Operation createNotOperation(Input one) { + assert one != null; + return new NotOperation(one); + } + + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/Input.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/Input.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,25 @@ +/* + * Input.java + * + * Created on July 12, 2006, 2:20 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +public abstract class Input { + + Input() { + + } + + public abstract boolean getBooleanValue(); + + public abstract double getRealValue(); + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/NotOperation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/NotOperation.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,33 @@ +/* + * NotOperation.java + * + * Created on July 12, 2006, 2:35 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +final class NotOperation extends Operation { + + private Input input; + + /** Creates a new instance of NotOperation */ + NotOperation(Input input) { + this.input = input; + } + + public boolean performBooleanOperation() { + return !input.getBooleanValue(); + } + + public double performRealOperation() { + return 1f - input.getRealValue(); + } + + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/Operation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/Operation.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,35 @@ +/* + * Operation.java + * + * Created on July 12, 2006, 2:26 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +public abstract class Operation { + + private boolean used; + + /** Creates a new instance of Operation */ + protected Operation() { + } + + public abstract boolean performBooleanOperation(); + + final void markOperationAsUsed() { + used = true; + } + + final boolean isUsed() { + return used; + } + + public abstract double performRealOperation(); + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/OperationInput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/OperationInput.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,30 @@ +/* + * OperationInput.java + * + * Created on July 12, 2006, 2:32 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +final class OperationInput extends Input { + private Operation operation; + /** Creates a new instance of OperationInput */ + public OperationInput(Operation oper) { + operation = oper; + } + + public boolean getBooleanValue() { + return operation.performBooleanOperation(); + } + + public double getRealValue() { + return operation.performRealOperation(); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/OrOperation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/OrOperation.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,35 @@ +/* + * OrOperation.java + * + * Created on July 12, 2006, 2:34 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +final class OrOperation extends Operation { + + private Input input1; + + private Input input2; + + /** Creates a new instance of orOperation */ + OrOperation(Input in1, Input in2) { + input1 = in1; + input2 = in2; + } + + public boolean performBooleanOperation() { + return input1.getBooleanValue() || input2.getBooleanValue(); + } + + public double performRealOperation() { + return 1 - ( 1 - input1.getRealValue()) * (1 - input2.getRealValue()); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/VariableInput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/src/org/netbeans/apifest/boolcircuit/VariableInput.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,44 @@ +/* + * VariableInput.java + * + * Created on July 13, 2006, 3:02 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + * @author mkleint + */ +public final class VariableInput extends Input { + + private double value; + + /** Creates a new instance of VariableInput */ + VariableInput() { + value = 0f; + } + + public void setBooleanValue(boolean bool) { + value = bool ? 1d : 0d; + } + + public boolean getBooleanValue() { + return value == 1d; + } + + public double getRealValue() { + return value; + } + + public void setRealValue(double real) throws IllegalArgumentException { + if (real < 0d || real > 1d) { + throw new IllegalArgumentException(); + }; + value = real; + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,116 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

    + *
  • negation - has one input and one output and changes 0 on input to + * on output 1 and 1 to 0 + *
  • and - has two inputs and one output. The output is 1 only if both + * inputs are 1, otherwise it is 0 + *
  • or - has two inputs and one output. The output is 1 always, except + * in the case when both inputs are 0 + *
+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + Input inTrue; + Input inFalse; + public CircuitTest(String testName) { + super(testName); + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + inTrue = Factory.createSimpleBooleanInput(true); + inFalse = Factory.createSimpleBooleanInput(false); + Operation op1 = Factory.createAndOperation(inFalse, inTrue); + assertFalse(Circuit.evaluateBooleanOperation(op1)); + Operation op2 = Factory.createAndOperation(inTrue, inTrue); + assertTrue(Circuit.evaluateBooleanOperation(op2)); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + inTrue = Factory.createSimpleBooleanInput(true); + inFalse = Factory.createSimpleBooleanInput(false); + Operation op1 = Factory.createAndOperation(inFalse, inTrue); + Operation op2 = Factory.createOrOperation(Factory.createOperationBasedBooleanInput(op1), inFalse); + assertFalse(Circuit.evaluateBooleanOperation(op2)); + + op1 = Factory.createAndOperation(inFalse, inFalse); + op2 = Factory.createOrOperation(Factory.createOperationBasedBooleanInput(op1), inTrue); + assertTrue(Circuit.evaluateBooleanOperation(op2)); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + inTrue = Factory.createSimpleBooleanInput(true); + inFalse = Factory.createSimpleBooleanInput(false); + Operation not = Factory.createNotOperation(inTrue); + Operation or = Factory.createOrOperation(Factory.createOperationBasedBooleanInput(not), inTrue); + assertTrue(Circuit.evaluateBooleanOperation(or)); + not = Factory.createNotOperation(inFalse); + or = Factory.createOrOperation(Factory.createOperationBasedBooleanInput(not), inFalse); + assertTrue(Circuit.evaluateBooleanOperation(or)); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/inputandoperation/test/org/netbeans/apifest/boolcircuit/RealTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/inputandoperation/test/org/netbeans/apifest/boolcircuit/RealTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,191 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** This file contains the APIFest quest for day 2. Simply, turn the + * boolean circuit into circuit that can compute with double values from 0 to 1. + *

+ * This means that where ever a boolean was used to represent input or + * output values, one can now use any double number from >= 0 and <= 1. + * Still, to support backward compatibility, the operations with booleans + * has to be kept available and have to work. In fact False shall be + * treated as 0 and True as 1. + *

+ * The basic elements has to be modified to work on doubles in the following + * way: + *

    + *
  • negation - neg(x) = 1 - x, this is correct extension as neg(false)=neg(0)=1-0=1=true + *
  • and - and(x,y) = x * y, again this is fine as and(true,true)=1*1=true and also + * and(false,true)=0*1=0=false + *
  • or - or(x,y) = 1 - (1 - x) * (1 - y) and this is also ok as + * or(false,false) = 1 - (1 - 0) * (1 - 0) = 1 - 1 = 0 = false + * or(true,false) = 1 - (1 - 1) * (1 - 0) = 1 - 0 * 1 = 1 = true + *
+ *

+ * However as the circuits with doubles are more rich than plain boolean circuits, + * there is additional requirement to allow any user of your API to write its + * own "element" type. This is all going to be exercise in the tests bellow + * which you are supposed to implement. + */ +public class RealTest extends TestCase { + static { + // your code shall run without any permissions + } + + public RealTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** First of all create a circuit which will evaluate + * expression (X1 and X2) or not(x1). Hold the circuit + * in some variable. + * + * Feed this circuit with x1=true, x2=false, assert result is false + * + * Feed the same circuit with x1=false, x2=true, assert result is true + * + * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0 + * + * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625 + * + * Feed the same circuit with x1=0.0, x2=2.0, make sure it throws an exception + */ + public void testX1andX2orNotX1() { + VariableInput x1 = Factory.createVariableInput(); + VariableInput x2 = Factory.createVariableInput(); + Operation and = Factory.createAndOperation(x1, x2); + Operation not = Factory.createNotOperation(x1); + Operation or = Factory.createOrOperation(Factory.createOperationBasedInput(and), Factory.createOperationBasedInput(not)); + + x1.setBooleanValue(false); + x2.setBooleanValue(true); + assertTrue(Circuit.evaluateBooleanOperation(or)); + + x1.setRealValue(0.0); + x2.setRealValue(1.0); + assertEquals(1.0, Circuit.evaluateRealOperation(or)); + + x1.setRealValue(0.5); + x2.setRealValue(0.5); + assertEquals(0.625, Circuit.evaluateRealOperation(or)); + + try { + x1.setRealValue(0.0); + x2.setRealValue(2.0); + Circuit.evaluateRealOperation(or); + fail(); + } catch (IllegalArgumentException exc) { + //good.. + } + + } + + /** Ensure that one variable cannot be filled with two different values. + * Create a circuit for x1 and x1. Make sure that for any usage of your + * API that would not lead to x1 * x1 result, an exception is thrown. + * For example if there was a way to feed the circuit with two different + * values 0.3 and 0.5 an exception is thrown indicating that this is + * improper use of the circuit. + */ + public void testImproperUseOfTheCircuit() { + + // this is enforced by the setter on the VariableInput.. how to test?? + + + +// fail("task2"); + // PS: This request is based on observation that some API from day1 + // solved the multiple usage of one variable, by repeating its + // value multiple times. This tasks says that if this is case of + // your API you must make sure, when that usage of different values + // for one variable is prohibited. If there is no way in your API to + // express this task, just say so, and you do not need to write a test. + // However if anyone else finds a way to simulate such situation in your + // API later, it will get points for breaking your API. + } + + /** Write your own element type called "gte" that will have two inputs and one output. + * The output value will be 1 if x1 >= x2 and 0 otherwise. + * + * Create + * circuit for following expression: (x1 and not(x1)) gte x1 + * + * Feed the circuit with 0.5 and verify the result is 0 + * + * Feed the same circuit with 1 and verify the result is 0 + * + * Feed the same circuit with 0 and verify the result is 1 + */ + public void testGreaterThanEqualElement() { + VariableInput x1 = Factory.createVariableInput(); + Operation not = Factory.createNotOperation(x1); + Operation and = Factory.createAndOperation(x1, Factory.createOperationBasedInput(not)); + Operation gte = new GTEOperation(Factory.createOperationBasedInput(and), x1); + + x1.setRealValue(0.5); + assertEquals(0.0, Circuit.evaluateRealOperation(gte)); + + x1.setRealValue(1.0); + assertEquals(0.0, Circuit.evaluateRealOperation(gte)); + + x1.setRealValue(0.0); + assertEquals(1.0, Circuit.evaluateRealOperation(gte)); + + } + + private final class GTEOperation extends Operation { + + private Input input2; + + private Input input1; + + public GTEOperation(Input in1, Input in2) { + super(); + input1 = in1; + input2 = in2; + } + + public boolean performBooleanOperation() { + return input1.getRealValue() >= input2.getRealValue(); + } + + public double performRealOperation() { + return (input1.getRealValue() >= input2.getRealValue()) ? 1.0 : 0.0; + } + + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/pinbasedsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/pinbasedsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project pinbasedsolution. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/pinbasedsolution/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/pinbasedsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/pinbasedsolution/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/pinbasedsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=c2d9be31 +build.xml.script.CRC32=09dc18c1 +build.xml.stylesheet.CRC32=a12b3d02 +# 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=c2d9be31 +nbproject/build-impl.xml.script.CRC32=716bfc49 +nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/pinbasedsolution/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/pinbasedsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,56 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/pinbasedsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/pinbasedsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + pinbasedsolution + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/pinbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/pinbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,86 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * A representation of a logic circuit. + * It can only be constructed from an element net. + * Usage: + *

+ *  Circuit c = Circuit.construct(
+ *      Element.createOr(
+ *          Element.createAnd(
+ *              Element.createInput(0),
+ *              Element.createInput(1)
+ *          ),
+ *          Element.createInput(2)
+ *      )
+ *  );
+ *            
+ *  boolean val = c.evaluate(false, true, false));
+ * 
+ */ +public class Circuit { + Element root; + int pins; + + private Circuit(Element elem) { + root = elem; + pins = 1 + root.maxInput(); + } + + /** + * Evaluate output of the circuit for given inputs. + * For general + */ + public boolean evaluate(Boolean ... inputs) throws UnstableException { + if (inputs.length != pins) throw new IllegalArgumentException("Wrong number of inputs, " + pins + " expected."); + double[] inp = new double[pins]; + for (int i=0; i 0.5; + } + + public double evaluate(double ... inputs) throws UnstableException { + if (inputs.length != pins) throw new IllegalArgumentException("Wrong number of inputs, " + pins + " expected."); + + double[] inp = new double[pins]; // defensive copy with a check + for (int i=0; i 1.0) { + throw new IllegalArgumentException("Out of range, pin " + i + ", value=" + inputs[i]); + } + inp[i] = inputs[i]; + } + + return root.evaluate(inp); + } + + /** + * Creates a circuit from a preconstructed element net. + * + * @param a top-level element representing the logic net. + * @return a circuit prepared for evaluating result for given inputs. + * + */ + public static Circuit construct(Element elem) { + return new Circuit(elem); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/pinbasedsolution/src/org/netbeans/apifest/boolcircuit/Element.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/pinbasedsolution/src/org/netbeans/apifest/boolcircuit/Element.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,119 @@ +/* + * Element.java + * + * Created on 12. červenec 2006, 14:14 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * Representation of an element in the circuit. + * The internal behaviour of the element is opaque to the API user, it can only + * be used as a building block for logical equations, using primitive operation + * factories and a factory for input pin representation. + * Elements are chained to create the logical net. The inputs to the net are + * represented by the elements created by {@link #createInput(boolean[])} + * factory method. + */ +public abstract class Element { + + /** Creates a new instance of Element */ + private Element() { + } + + /** + */ + abstract double evaluate(double[] inputs); + + abstract int maxInput(); + + /** + * Creates an Element representing 2-input AND function. + * + */ + public static Element createAnd(final Element source1, final Element source2) { + return new Element() { + double evaluate(double[] inputs) { + return source1.evaluate(inputs) * source2.evaluate(inputs); + } + + int maxInput() { + return Math.max(source1.maxInput(), source2.maxInput()); + } + }; + } + + /** + * Creates an Element representing 2-input OR function. + * + */ + public static Element createOr(final Element source1, final Element source2) { + return new Element() { + double evaluate(double[] inputs) { + double x = source1.evaluate(inputs); + double y = source2.evaluate(inputs); + return 1 - (1 - x)*(1-y); + } + + int maxInput() { + return Math.max(source1.maxInput(), source2.maxInput()); + } + }; + } + + /** + * Creates an Element representing negation. + * + */ + public static Element createNot(final Element source1) { + return new Element() { + double evaluate(double[] inputs) { + return 1 - source1.evaluate(inputs); + } + + int maxInput() { + return source1.maxInput(); + } + }; + } + + /** + * Creates an Element representing input to the logical net. + * + */ + public static Element createInput(final int pin) { + return new Element() { + double evaluate(double[] inputs) { + return inputs[pin]; + } + + int maxInput() { + return pin; + } + }; + } + + /** + * Creates an Element with user-defined transfer function. + * + */ + public static Element createGate(final Element source1, final Element source2, final Function function) { + return new Element() { + double evaluate(double[] inputs) { + double x = source1.evaluate(inputs); + double y = source2.evaluate(inputs); + double result = function.evaluate(x, y); + if (result < 0.0 || result > 1.0) throw new InternalError("Illegal gate function"); + return result; + } + + int maxInput() { + return Math.max(source1.maxInput(), source2.maxInput()); + } + }; + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/pinbasedsolution/src/org/netbeans/apifest/boolcircuit/Function.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/pinbasedsolution/src/org/netbeans/apifest/boolcircuit/Function.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,19 @@ +/* + * Function.java + * + * Created on 13. červenec 2006, 14:40 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * An abstract transfer function of a gate. + * @author nenik + */ +public abstract class Function { + + public abstract double evaluate(double input1, double input2); +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/pinbasedsolution/src/org/netbeans/apifest/boolcircuit/UnstableException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/pinbasedsolution/src/org/netbeans/apifest/boolcircuit/UnstableException.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,24 @@ +/* + * UnstableException.java + * + * Created on 12. červenec 2006, 14:15 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * Exception representing that the circuit is unstable for given + * input configuration. It can happen in case there is backward loop + * in the logic. + * + */ +public class UnstableException extends Exception { + + /** Creates a new instance of UnstableException */ + public UnstableException() { + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/pinbasedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/pinbasedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,128 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

    + *
  • negation - has one input and one output and changes 0 on input to + * on output 1 and 1 to 0 + *
  • and - has two inputs and one output. The output is 1 only if both + * inputs are 1, otherwise it is 0 + *
  • or - has two inputs and one output. The output is 1 always, except + * in the case when both inputs are 0 + *
+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() throws Exception { + Circuit c = Circuit.construct( + Element.createAnd( + Element.createInput(0), + Element.createInput(1) + ) + ); + + assertFalse ("false AND true is false", c.evaluate(false, true)); + assertTrue ("true AND true is true", c.evaluate(true, true)); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() throws Exception { + Circuit c = Circuit.construct( + Element.createOr( + Element.createAnd( + Element.createInput(0), + Element.createInput(1) + ), + Element.createInput(2) + ) + ); + + assertFalse ("(false AND true) OR false is false", c.evaluate(false, true, false)); + assertTrue ("(false AND false) OR true is true", c.evaluate(false, false, true)); + } + + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() throws Exception { + Circuit c = Circuit.construct( + Element.createOr( + Element.createInput(0), + Element.createNot(Element.createInput(0)) + ) + ); + + assertTrue ("tautology is true", c.evaluate(false)); + assertTrue ("tautology is true", c.evaluate(true)); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/pinbasedsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/pinbasedsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,177 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** This file contains the APIFest quest for day 2. Simply, turn the + * boolean circuit into circuit that can compute with double values from 0 to 1. + *

+ * This means that where ever a boolean was used to represent input or + * output values, one can now use any double number from >= 0 and <= 1. + * Still, to support backward compatibility, the operations with booleans + * has to be kept available and have to work. In fact False shall be + * treated as 0 and True as 1. + *

+ * The basic elements has to be modified to work on doubles in the following + * way: + *

    + *
  • negation - neg(x) = 1 - x, this is correct extension as neg(false)=neg(0)=1-0=1=true + *
  • and - and(x,y) = x * y, again this is fine as and(true,true)=1*1=true and also + * and(false,true)=0*1=0=false + *
  • or - or(x,y) = 1 - (1 - x) * (1 - y) and this is also ok as + * or(false,false) = 1 - (1 - 0) * (1 - 0) = 1 - 1 = 0 = false + * or(true,false) = 1 - (1 - 1) * (1 - 0) = 1 - 0 * 1 = 1 = true + *
+ *

+ * However as the circuits with doubles are more rich than plain boolean circuits, + * there is additional requirement to allow any user of your API to write its + * own "element" type. This is all going to be exercise in the tests bellow + * which you are supposed to implement. + */ +public class RealTest extends TestCase { + static { + // your code shall run without any permissions + } + + public RealTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** First of all create a circuit which will evaluate + * expression (X1 and X2) or not(x1). Hold the circuit + * in some variable. + * + * Feed this circuit with x1=true, x2=false, assert result is false + * + * Feed the same circuit with x1=false, x2=true, assert result is true + * + * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0 + * + * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625 + * + * Feed the same circuit with x1=0.0, x2=2.0, make sure it throws an exception + */ + public void testX1andX2orNotX1() throws Exception { + boolean fired = false; + + Circuit c = Circuit.construct( + Element.createOr( + Element.createAnd( + Element.createInput(0), + Element.createInput(1) + ), + Element.createNot(Element.createInput(0)) + ) + ); + + assertFalse ("false", c.evaluate(true, false)); + assertTrue ("true", c.evaluate(false, true)); + assertEquals ("1.0", 1.0, c.evaluate(0.0, 1.0)); + assertEquals ("0.625", 0.625, c.evaluate(0.5, 0.5)); + try { + c.evaluate(0.0, 2.0); + } catch (Exception exc) { + fired = true; + } + assertTrue ("Fired an exception for wrong input", fired); + } + + /** Ensure that one variable cannot be filled with two different values. + * Create a circuit for x1 and x1. Make sure that for any usage of your + * API that would not lead to x1 * x1 result, an exception is thrown. + * For example if there was a way to feed the circuit with two different + * values 0.3 and 0.5 an exception is thrown indicating that this is + * improper use of the circuit. + */ + public void testImproperUseOfTheCircuit() throws Exception { + final double[] inputs = new double[] {1.0}; + + // Cheating a little bit with one more gate, but the same effect + // could be obtained with (hard to achieve) thread race condition. + Circuit evil = Circuit.construct( + Element.createAnd( + Element.createGate( + Element.createInput(0), + Element.createInput(0), + new Function() { + public double evaluate(double input1, double input2) { + inputs[0] = 0.0; + return input1*input2; + } + + } + ), + Element.createInput(0) + ) + ); + assertEquals ("1 and 1 'and' 1 = 1", 1.0, evil.evaluate(inputs)); + + } + + /** Write your own element type called "gte" that will have two inputs and one output. + * The output value will be 1 if x1 >= x2 and 0 otherwise. + * + * Create + * circuit for following expression: (x1 and not(x1)) gte x1 + * + * Feed the circuit with 0.5 and verify the result is 0 + * + * Feed the same circuit with 1 and verify the result is 0 + * + * Feed the same circuit with 0 and verify the result is 1 + */ + public void testGreaterThanEqualElement() throws Exception { + Circuit c = Circuit.construct( + Element.createGate( + Element.createAnd( + Element.createInput(0), + Element.createNot(Element.createInput(0)) + ), + Element.createInput(0), + new Function() { + public double evaluate(double input1, double input2) { + return input1 >= input2 ? 1.0 : 0.0; + } + + } + ) + ); + + assertEquals ("0.0", 0.0, c.evaluate(0.5)); + assertEquals ("0.0", 0.0, c.evaluate(1.0)); + assertEquals ("1.0", 1.0, c.evaluate(0.0)); + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/stackbasedsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/stackbasedsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project stackbasedsolution. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/stackbasedsolution/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/stackbasedsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/stackbasedsolution/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/stackbasedsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=10562595 +build.xml.script.CRC32=8e100d5a +build.xml.stylesheet.CRC32=a12b3d02 +# 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=10562595 +nbproject/build-impl.xml.script.CRC32=50f3448d +nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/stackbasedsolution/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/stackbasedsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,56 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/stackbasedsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/stackbasedsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + stackbasedsolution + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,28 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.util.Stack; + +/** + */ +public interface Circuit { + public char evaluate (Stack input) throws IllegalArgumentException; +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit2.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,28 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.util.Stack; + +/** + */ +public interface Circuit2 extends Circuit { + public double evaluate (double ... input) throws IllegalArgumentException; +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/CircuitFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/CircuitFactory.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,101 @@ +/* + * CircuitFactory.java + * + * Created on July 12, 2006, 3:01 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.util.Stack; + +/** + * + */ +public class CircuitFactory { + + /** Creates a new instance of CircuitFactory */ + private CircuitFactory() { + } + + public final static Circuit join (final Circuit c1, final Circuit c2, final Operation op) { + return new Circuit () { + public char evaluate(Stack input) throws IllegalArgumentException { + return op.evaluate(c1.evaluate(input), c2.evaluate(input)); + } + }; + } + + public final static Circuit2 join (final Circuit2 c1, final Circuit2 c2, final Operation op) { + return new Circuit2 () { + public char evaluate(Stack input) throws IllegalArgumentException { + return op.evaluate(c1.evaluate(input), c2.evaluate(input)); + } + public double evaluate(double ... input) throws IllegalArgumentException { + return op.evaluate(c1.evaluate(input), c2.evaluate(input)); + } + }; + } + + public final static Circuit2 getBasicCircuit (final Operation op) { + return new Circuit2 () { + public double evaluate(double... input) throws IllegalArgumentException { + if (input == null || input.length == 1) { + throw new IllegalArgumentException ("Invalid input array."); + } + return op.evaluate(input[0], input[1]); + } + + public char evaluate(Stack input) throws IllegalArgumentException { + // special handling of unary oparation + if (op instanceof Operation.Neg) { + return op.evaluate(input.pop(), input.peek()); + } else { + return op.evaluate(input.pop(), input.pop()); + } + } + }; + } +// public final static Circuit2 getBasicCircuit (final Operation op, final int posX, final int posY) { +// return new Circuit2 () { +// public double evaluate(double... input) throws IllegalArgumentException { +// return op.evaluate(input[posX], input[posY]); +// } +// +// public char evaluate(Stack input) throws IllegalArgumentException { +// return getBasicCircuit (op).evaluate(input); +// } +// }; +// } +// public final static Circuit2 getBasicCircuit (final Operation op, final Circuit2 c1, final Circuit2 c2) { +// return new Circuit2 () { +// public double evaluate(double... input) throws IllegalArgumentException { +// return op.evaluate(c2.evaluate(input), c2.evaluate(input)); +// } +// +// public char evaluate(Stack input) throws IllegalArgumentException { +// return getBasicCircuit (op).evaluate(input); +// } +// }; +// } + public final static Circuit getTrivialCircuit () { + return new Circuit () { + public char evaluate(Stack input) throws IllegalArgumentException { + return input.peek(); + } + }; + } + public final static Circuit2 getTrivialCircuit (final int posX) { + return new Circuit2 () { + public double evaluate(double... input) throws IllegalArgumentException { + return input[posX]; + } + + public char evaluate(Stack input) throws IllegalArgumentException { + return getTrivialCircuit ().evaluate(input); + } + }; + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/Operation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/stackbasedsolution/src/org/netbeans/apifest/boolcircuit/Operation.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,84 @@ +/* + * Operation.java + * + * Created on July 12, 2006, 3:06 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + */ +public interface Operation { + public char evaluate (char i1, char i2) throws IllegalArgumentException; + public double evaluate (double i1, double i2) throws IllegalArgumentException; + public final static Operation OR = new Or (); + public final static Operation AND = new And (); + public final static Operation NEG = new Neg (); + + + static class And implements Operation { + public char evaluate(char i1, char i2) throws IllegalArgumentException { + if (i1 != '0' && i1 != '1') { + throw new IllegalArgumentException ("Invalid input parameter: " + i1); + } + if (i2 != '0' && i2 != '1') { + throw new IllegalArgumentException ("Invalid input parameter: " + i2); + } + return i1 == '1' && i2 == '1' ? '1' : '0'; + } + + public double evaluate(double i1, double i2) throws IllegalArgumentException { + if (i1 < 0 || i1 > 1) { + throw new IllegalArgumentException ("Invalid input parameter: " + i1); + } + if (i2 < 0 || i2 > 1) { + throw new IllegalArgumentException ("Invalid input parameter: " + i2); + } + return i1 * i2; + } + } + static class Or implements Operation { + public char evaluate(char i1, char i2) throws IllegalArgumentException { + if (i1 != '0' && i1 != '1') { + throw new IllegalArgumentException ("Invalid input parameter: " + i1); + } + if (i2 != '0' && i2 != '1') { + throw new IllegalArgumentException ("Invalid input parameter: " + i2); + } + return i1 == '1' || i2 == '1' ? '1' : '0'; + } + + public double evaluate(double i1, double i2) throws IllegalArgumentException { + if (i1 < 0 || i1 > 1) { + throw new IllegalArgumentException ("Invalid input parameter: " + i1); + } + if (i2 < 0 || i2 > 1) { + throw new IllegalArgumentException ("Invalid input parameter: " + i2); + } + return 1 - (1 - i1) * (1 - i2); + } + } + static class Neg implements Operation { + public char evaluate(char i1, char i2) throws IllegalArgumentException { + if (i1 != '0' && i1 != '1') { + throw new IllegalArgumentException ("Invalid input parameter: " + i1); + } + return i1 == '1' ? '0' : '1'; + } + + public double evaluate(double i1, double i2) throws IllegalArgumentException { + if (i1 < 0 || i1 > 1) { + throw new IllegalArgumentException ("Invalid input parameter: " + i1); + } + if (i2 < 0 || i2 > 1) { + throw new IllegalArgumentException ("Invalid input parameter: " + i2); + } + return 1 - i1; + } + } +} + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/stackbasedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/stackbasedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,107 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.util.Arrays; +import java.util.Stack; +import junit.framework.TestCase; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

    + *
  • negation - has one input and one output and changes 0 on input to + * on output 1 and 1 to 0 + *
  • and - has two inputs and one output. The output is 1 only if both + * inputs are 1, otherwise it is 0 + *
  • or - has two inputs and one output. The output is 1 always, except + * in the case when both inputs are 0 + *
+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + Stack s = new Stack (); + s.addAll(Arrays.asList('1', '1')); + assertEquals("'1' for '11' input.", '1', CircuitFactory.getBasicCircuit(Operation.AND).evaluate(s)); + s.addAll(Arrays.asList('1', '0')); + assertEquals("'0' for '10' input.", '0', CircuitFactory.getBasicCircuit(Operation.AND).evaluate(s)); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + Stack s = new Stack (); + s.addAll(Arrays.asList('0', '1', '0')); + assertEquals("'0' for '010' input.", '0', CircuitFactory.join(CircuitFactory.getTrivialCircuit(), CircuitFactory.getBasicCircuit(Operation.OR), Operation.AND).evaluate(s)); + s.addAll(Arrays.asList('0', '0', '1')); + assertEquals("'1' for '001' input.", '1', CircuitFactory.join(CircuitFactory.getTrivialCircuit(), CircuitFactory.getBasicCircuit(Operation.OR), Operation.AND).evaluate(s)); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + Circuit alwaysTrue = CircuitFactory.join(CircuitFactory.getTrivialCircuit(), CircuitFactory.getBasicCircuit(Operation.NEG), Operation.OR); + Stack s = new Stack (); + s.addAll(Arrays.asList('0', '0')); + assertEquals ("'1' for '00'", '1', alwaysTrue.evaluate(s)); + s.addAll(Arrays.asList('1', '1')); + assertEquals ("'1' for '11'", '1', alwaysTrue.evaluate(s)); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/stackbasedsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/stackbasedsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,153 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Stack; +import junit.framework.TestCase; +import junit.framework.*; + +/** This file contains the APIFest quest for day 2. Simply, turn the + * boolean circuit into circuit that can compute with double values from 0 to 1. + *

+ * This means that where ever a boolean was used to represent input or + * output values, one can now use any double number from >= 0 and <= 1. + * Still, to support backward compatibility, the operations with booleans + * has to be kept available and have to work. In fact False shall be + * treated as 0 and True as 1. + *

+ * The basic elements has to be modified to work on doubles in the following + * way: + *

    + *
  • negation - neg(x) = 1 - x, this is correct extension as neg(false)=neg(0)=1-0=1=true + *
  • and - and(x,y) = x * y, again this is fine as and(true,true)=1*1=true and also + * and(false,true)=0*1=0=false + *
  • or - or(x,y) = 1 - (1 - x) * (1 - y) and this is also ok as + * or(false,false) = 1 - (1 - 0) * (1 - 0) = 1 - 1 = 0 = false + * or(true,false) = 1 - (1 - 1) * (1 - 0) = 1 - 0 * 1 = 1 = true + *
+ *

+ * However as the circuits with doubles are more rich than plain boolean circuits, + * there is additional requirement to allow any user of your API to write its + * own "element" type. This is all going to be exercise in the tests bellow + * which you are supposed to implement. + */ +public class RealTest extends TestCase { + static { + // your code shall run without any permissions + } + + public RealTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** First of all create a circuit which will evaluate + * expression (X1 and X2) or not(x1). Hold the circuit + * in some variable. + * + * Feed this circuit with x1=true, x2=false, assert result is false + * + * Feed the same circuit with x1=false, x2=true, assert result is true + * + * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0 + * + * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625 + * + * Feed the same circuit with x1=0.0, x2=2.0, make sure it throws an exception + */ + public void testX1andX2orNotX1() { + Circuit2 trivX1 = CircuitFactory.getTrivialCircuit(0); + Circuit2 trivX2 = CircuitFactory.getTrivialCircuit(1); + Circuit2 cAnd = CircuitFactory.join(trivX1, trivX2, Operation.AND); + Circuit2 cNeg = CircuitFactory.join(trivX1, trivX2, Operation.NEG); + Circuit2 cOr = CircuitFactory.join(CircuitFactory.getBasicCircuit (Operation.AND), CircuitFactory.getBasicCircuit(Operation.NEG), Operation.OR); + + Stack s = new Stack (); + s.addAll(Arrays.asList('1', '1', '0', '1')); + + assertEquals ("Feed this circuit with x1=true, x2=false, assert result is false", '0', cOr.evaluate(s)); + assertEquals ("Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0", 1.0, cOr.evaluate(0.0,1.0)); + assertEquals ("Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625", 0.625, cOr.evaluate(0.5,0.5)); + try { + assertEquals ("Feed the same circuit with x1=0.0, x2=2.0, make sure it throws an exception", 0, cOr.evaluate(0.0,2.0)); + fail ("Feed the same circuit with x1=0.0, x2=2.0, make sure it throws an exception"); + } catch (Exception x) { + } + } + + /** Ensure that one variable cannot be filled with two different values. + * Create a circuit for x1 and x1. Make sure that for any usage of your + * API that would not lead to x1 * x1 result, an exception is thrown. + * For example if there was a way to feed the circuit with two different + * values 0.3 and 0.5 an exception is thrown indicating that this is + * improper use of the circuit. + */ + public void testImproperUseOfTheCircuit() { + Circuit2 trivX1 = CircuitFactory.getTrivialCircuit(0); + assertEquals ("0.25", 0.25, CircuitFactory.join(trivX1, trivX1, Operation.AND).evaluate(0.5, 2)); + } + + /** Write your own element type called "gte" that will have two inputs and one output. + * The output value will be 1 if x1 >= x2 and 0 otherwise. + * + * Create + * circuit for following expression: (x1 and not(x1)) gte x1 + * + * Feed the circuit with 0.5 and verify the result is 0 + * + * Feed the same circuit with 1 and verify the result is 0 + * + * Feed the same circuit with 0 and verify the result is 1 + */ + public void testGreaterThanEqualElement() { +// fail("task3"); + Operation gte = new Operation () { + + public char evaluate(char i1, char i2) throws IllegalArgumentException { + assert false : "Not supported"; + return 'x'; + } + + public double evaluate(double i1, double i2) throws IllegalArgumentException { + if (i1 < 0 || i1 > 1) { + throw new IllegalArgumentException ("Invalid input parameter: " + i1); + } + if (i2 < 0 || i2 > 1) { + throw new IllegalArgumentException ("Invalid input parameter: " + i2); + } + return i1 >= i2 ? 1 : 0; + } + }; + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/subclassingsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/subclassingsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project boolcircuit. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/subclassingsolution/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/subclassingsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/subclassingsolution/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/subclassingsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=2ab820eb +build.xml.script.CRC32=58a52595 +build.xml.stylesheet.CRC32=a12b3d02 +# 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=0f6dc18a +nbproject/build-impl.xml.script.CRC32=079f4b62 +nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/subclassingsolution/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/subclassingsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,54 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +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} +src.dir=src +test.src.dir=test +libs.junit.classpath=../../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/subclassingsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/subclassingsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + subclassingsolution + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/subclassingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/subclassingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,90 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + + +/** Usefull class for building your own circuits. + *
+ * Notice that this API nobly generously permits using operator overloading + *
+ * :-) Sometimes when you find an unfixable bug. The best thing to do is to + * make it a fature. + * + */ +public abstract class Circuit extends Object { + + /** For your conveninece */ + public static FuzzyCircuit AND = new FuzzyCircuit() { + + @Override + public boolean evaluate(boolean[] in) { + checkParams( 2, in ); + return in[0] && in[1]; + } + + public double evaluate(double[] in) { + checkParams( 2, in ); + return in[0] * in[1]; + } + + }; + + /** For your conveninece */ + public static FuzzyCircuit OR = new FuzzyCircuit() { + + @Override + public boolean evaluate(boolean[] in) { + checkParams( 2, in ); + return in[0] || in[1]; + } + + @Override + public double evaluate(double[] in) { + checkParams( 2, in ); + return 1 - (1 - in[0]) * (1 - in[1]); + } + }; + + + /** For your conveninece */ + public static FuzzyCircuit NOT = new FuzzyCircuit() { + + @Override + public boolean evaluate(boolean[] in) { + checkParams( 1, in ); + return !in[0]; + } + + @Override + public double evaluate(double[] in) { + checkParams( 1, in ); + return 1 - in[0]; + } + + + }; + + /** Feel free to implement and don't hesitate to throw IllegalArgumentEception + */ + public abstract boolean evaluate(boolean... in); + + + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/subclassingsolution/src/org/netbeans/apifest/boolcircuit/FuzzyCircuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/subclassingsolution/src/org/netbeans/apifest/boolcircuit/FuzzyCircuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,58 @@ +/* + * FuzzyCircuit.java + * + * Created on July 13, 2006, 2:31 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + * + * @author phrebejk + */ +public abstract class FuzzyCircuit extends Circuit { + + /** Feel free to implement and don't hesitate to throw IllegalArgumentEception + */ + public abstract double evaluate(double... in); + + public static final void checkParams( int expectedLenght, boolean... in ) { + + // :-) in real world add a test for null too + + if (expectedLenght != in.length) { + + // :-) Probably unnecessary unless this is a competition + switch ( expectedLenght ) { + case 1: + throw new IllegalArgumentException("Should have one parameter"); + case 2: + throw new IllegalArgumentException("Should have two parameters"); + default: + throw new IllegalArgumentException("Wrong number of parameters!"); + } + } + } + + public static final void checkParams( int expectedLenght, double ... in ) { + if ( in == null ) { + throw new IllegalArgumentException( "Parameter in must not be null!"); + } + if (expectedLenght != in.length) { + throw new IllegalArgumentException("Wrong number of parameters!"); + } + + for( int i = 0; i < in.length; i++ ) { + if ( in[i] < 0.0 || in[i] > 1.0 ) { + throw new IllegalArgumentException( + "All params have to be in the range <0.0, 1.0>! " + + "param at index " + i + " is " + in[i]); + } + } + + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/subclassingsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/subclassingsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,136 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +import static org.netbeans.apifest.boolcircuit.Circuit.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

    + *
  • negation - has one input and one output and changes 0 on input to + * on output 1 and 1 to 0 + *
  • and - has two inputs and one output. The output is 1 only if both + * inputs are 1, otherwise it is 0 + *
  • or - has two inputs and one output. The output is 1 always, except + * in the case when both inputs are 0 + *
+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + + + + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + + assertFalse( AND.evaluate( false, true )); + assertTrue( AND.evaluate( true, true )); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + + Circuit c = new Circuit() { + + @Override + public boolean evaluate(boolean[] in) { + if ( in.length != 3) { + throw new IllegalArgumentException( "Should have one parameter"); + } + return OR.evaluate( AND.evaluate( in[0], in[1] ), in[2] ); + } + + }; + + assertFalse( c.evaluate( false, true, false ) ); + assertTrue( c.evaluate( false, false, true ) ); + + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + + Circuit c = new Circuit() { + + @Override + public boolean evaluate(boolean[] in) { + if ( in.length != 1) { + throw new IllegalArgumentException( "Should have three parameters"); + } + return OR.evaluate( in[0], NOT.evaluate( in[0] ) ); + } + + }; + + assertTrue( c.evaluate( true ) ); + assertTrue( c.evaluate( false ) ); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/subclassingsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/subclassingsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,242 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** This file contains the APIFest quest for day 2. Simply, turn the + * boolean circuit into circuit that can compute with double values from 0 to 1. + *

+ * This means that where ever a boolean was used to represent input or + * output values, one can now use any double number from >= 0 and <= 1. + * Still, to support backward compatibility, the operations with booleans + * has to be kept available and have to work. In fact False shall be + * treated as 0 and True as 1. + *

+ * The basic elements has to be modified to work on doubles in the following + * way: + *

    + *
  • negation - neg(x) = 1 - x, this is correct extension as neg(false)=neg(0)=1-0=1=true + *
  • and - and(x,y) = x * y, again this is fine as and(true,true)=1*1=true and also + * and(false,true)=0*1=0=false + *
  • or - or(x,y) = 1 - (1 - x) * (1 - y) and this is also ok as + * or(false,false) = 1 - (1 - 0) * (1 - 0) = 1 - 1 = 0 = false + * or(true,false) = 1 - (1 - 1) * (1 - 0) = 1 - 0 * 1 = 1 = true + *
+ *

+ * However as the circuits with doubles are more rich than plain boolean circuits, + * there is additional requirement to allow any user of your API to write its + * own "element" type. This is all going to be exercise in the tests bellow + * which you are supposed to implement. + */ +public class RealTest extends TestCase { + static { + // your code shall run without any permissions + } + + public RealTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + + /** First of all create a circuit which will evaluate + * expression (X1 and X2) or not(x1). Hold the circuit + * in some variable. + * + * Feed this circuit with x1=true, x2=false, assert result is false + * + * Feed the same circuit with x1=false, x2=true, assert result is true + * + * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0 + * + * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625 + * + * Feed the same circuit with x1=0.0, x2=2.0, make sure it throws an exception + */ + public void testX1andX2orNotX1() { + FuzzyCircuit c = new CircuitSupport( 2 ) { + + @Override + public boolean ev(boolean[] in) { + return OR.evaluate( AND.evaluate( in[0], in[1] ), NOT.evaluate( in[0] ) ); + } + + @Override + public double ev(double[] in) { + return OR.evaluate( AND.evaluate( in[0], in[1] ), NOT.evaluate( in[0] ) ); + } + + }; + + assertFalse( c.evaluate(true, false) ); + assertTrue( c.evaluate(false, true) ); + assertEquals(c.evaluate(0.0, 1.0), 1.0, 0.0001); + assertEquals(c.evaluate(0.5, 0.5), 0.625, 0.0001); + try { + c.evaluate(0.0, 2.0); + } + catch ( IllegalArgumentException e ) { + return; + } + fail(); + } + + /** Ensure that one variable cannot be filled with two different values. + * Create a circuit for x1 and x1. Make sure that for any usage of your + * API that would not lead to x1 * x1 result, an exception is thrown. + * For example if there was a way to feed the circuit with two different + * values 0.3 and 0.5 an exception is thrown indicating that this is + * improper use of the circuit. + */ + public void testImproperUseOfTheCircuit() { + FuzzyCircuit c = new CircuitSupport( 1 ) { + + @Override + public boolean ev(boolean[] in) { + return AND.evaluate( in[0], in[0] ); + } + + @Override + public double ev(double[] in) { + return AND.evaluate( in[0], in[0] ); + } + + }; + + // Empty array + IllegalArgumentException ex = null; + try { + c.evaluate(new boolean[]{} ); + } catch ( IllegalArgumentException e) { + ex = e ; + } + if ( ex == null ) { + fail(); + } + + // Other sizes + int MAX = 4; // :-) This test obviously requires a nonsese. + // For testing nonsese Integer.MAX_VALUE + for( int i = 2; i < MAX ; i++ ) { + double a[] = new double[i]; + ex = null; + try { + c.evaluate( a ); + } + catch ( IllegalArgumentException e) { + ex = e ; + } + if ( ex == null ) { + fail(); + } + } + + } + + /** Write your own element type called "gte" that will have two inputs and one output. + * The output value will be 1 if x1 >= x2 and 0 otherwise. + * + * Create + * circuit for following expression: (x1 and not(x1)) gte x1 + * + * Feed the circuit with 0.5 and verify the result is 0 + * + * Feed the same circuit with 1 and verify the result is 0 + * + * Feed the same circuit with 0 and verify the result is 1 + */ + public void testGreaterThanEqualElement() { + final FuzzyCircuit gte = new CircuitSupport( 2 ) { + + // Assumes true > false + @Override + public boolean ev(boolean[] in) { + return in[0] || ( !in[0] && in[1] ); // May be + } + + @Override + public double ev(double[] in) { + return in[0] >= in[1] ? 1.0 : 0.0; + } + + }; + + FuzzyCircuit c = new CircuitSupport( 1 ) { + + // Assumes true > false + @Override + public boolean ev(boolean[] in) { + return gte.evaluate( AND.evaluate( in[0], NOT.evaluate( in[0] ) ), in[0]); + } + + @Override + public double ev(double[] in) { + return gte.evaluate( AND.evaluate( in[0], NOT.evaluate( in[0] ) ), in[0]); + } + + }; + + + assertEquals(c.evaluate(0.5), 0.0, 0.0001); + assertEquals(c.evaluate(1.0), 0.0, 0.0001); + assertEquals(c.evaluate(0.0), 1.0, 0.0001); + + } + + + private abstract static class CircuitSupport extends FuzzyCircuit { + + private int paramCount; + + CircuitSupport( int paramCount ) { + this.paramCount = paramCount; + } + + abstract boolean ev( boolean in[] ); + abstract double ev( double in[] ); + + public boolean evaluate(boolean[] in) { + checkParams( paramCount, in ); + return ev( in ); + } + + public double evaluate(double[] in) { + checkParams( paramCount, in ); + return ev( in ); + } + + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/welltestedsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/welltestedsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project welltestedsolution. + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/welltestedsolution/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/welltestedsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 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 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/welltestedsolution/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/welltestedsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=3022b908 +build.xml.script.CRC32=fdb77cae +build.xml.stylesheet.CRC32=a12b3d02 +# 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=3022b908 +nbproject/build-impl.xml.script.CRC32=b9627854 +nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/welltestedsolution/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/welltestedsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,56 @@ +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}/boolcircuit.jar +dist.javadoc.dir=${dist.dir}/javadoc +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# Property libs.junit.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.junit.classpath=../../../../../usr/local/lib/netbeans/ide8/modules/ext/junit-3.8.2.jar +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} +src.dir=src +test.src.dir=test diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/welltestedsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/welltestedsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + welltestedsolution + 1.6.5 + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/welltestedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/welltestedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,177 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +/** + */ +public abstract class Circuit { + + /** Creates a simple Circuit that is associated with given input pin. + * @since day2 + */ + public static Circuit input(int pin) { + return new Input(pin); + } + + /** Create circuit that inverts results of input circuit. + */ + public static Circuit createNotCircuit(Circuit in) { + return new Not(in); + } + + public static Circuit createOrCircuit(Circuit in1, Circuit in2) { + return new Binary(in1, in2, true); + } + + public static Circuit createAndCircuit(Circuit in1, Circuit in2) { + return new Binary(in1, in2, false); + } + + public Circuit() { + + } + + public final boolean evaluate(Boolean ... inputs) { + if (inputs == null) + throw new IllegalArgumentException(); + double[] vals = new double [inputs.length]; + for (int i = 0; i < inputs.length; i++) + vals[i] = inputs[i]? 1.0: 0.0; + return evaluateFuzzy(vals) == 1.0; + } + + public final double evaluateFuzzy(double ... inputs) { + if (inputs == null) + throw new IllegalArgumentException(); + return doEvaluate(inputs); + } + + protected abstract double doEvaluate(double ... inputs); + + public abstract int maxInputs(); + + private interface OldEval { + + double doEvaluate1(int offset, double ... inputs); + } + + private static class Input extends Circuit { + + int pin; + + Input(int pin) { + this.pin = pin; + } + + protected double doEvaluate(double ... inputs) { + if (inputs == null || inputs.length < maxInputs()) + throw new IllegalArgumentException(); + + return inputs[pin]; + } + + public int maxInputs() { + return pin + 1; + } + + } + + private static class Not extends Circuit implements OldEval { + + private Circuit in; + + Not (Circuit in) { + this.in = in; + } + + public double doEvaluate(double ... inputs) { + return doEvaluate1(0, inputs); + } + + public double doEvaluate1(int i, double ... inputs) { + if (in == null) { + if (inputs == null || inputs.length < i + 1) + throw new IllegalArgumentException(); + return 1 - inputs[i]; + } + + if (in instanceof OldEval) { + return 1 - ((OldEval)in).doEvaluate1(i, inputs[i]); + } + else { + return 1 - in.evaluateFuzzy(inputs); + } + } + + public int maxInputs() { + return in != null? in.maxInputs(): 1; + } + } + + private static class Binary extends Circuit implements OldEval { + + private Circuit in1, in2; + boolean or; + + Binary (Circuit in1, Circuit in2, boolean or) { + this.in1 = in1; + this.in2 = in2; + this.or = or; + } + + public double doEvaluate(double ... inputs) { + return doEvaluate1(0, inputs); + } + + public double doEvaluate1(int i, double ... inputs) { + double x1, x2; + if (in1 == null) { + if (inputs == null || inputs.length < i + 1) + throw new IllegalArgumentException(); + x1 = inputs[i]; + } else { + if (in1 instanceof OldEval) { + x1 = ((OldEval)in1).doEvaluate1(i, inputs); + } + else { + x1 = in1.evaluateFuzzy(inputs); + } + } + if (in2 == null) { + if (inputs == null || inputs.length < i + (in1 != null? in1.maxInputs(): 1) + 1) + throw new IllegalArgumentException(); + x2 = inputs[i + (in1 != null? in1.maxInputs(): 1)]; + } else { + if (in2 instanceof OldEval) { + x2 = ((OldEval)in2).doEvaluate1(i + (in1 != null? in1.maxInputs(): 1), inputs); + } + else { + x2 = in2.evaluateFuzzy(inputs); + } + } + return or? 1 - (1 - x1) * (1 - x2) : x1 * x2; + } + + public int maxInputs() { + return (in1 != null? in1.maxInputs(): 1) + + (in2 != null? in2.maxInputs(): 1) ; + } + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/welltestedsolution/src/org/netbeans/apifest/custom/Gte.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/welltestedsolution/src/org/netbeans/apifest/custom/Gte.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,46 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.custom; + +import org.netbeans.apifest.boolcircuit.Circuit; + +/** + */ +public class Gte extends Circuit{ + + private Circuit in1; + private Circuit in2; + + public Gte (Circuit in1, Circuit in2) { + if (in1 == null || in2 == null) + throw new IllegalArgumentException(); + this.in1 = in1; + this.in2 = in2; + } + + protected double doEvaluate(double... inputs) { + return (in1.evaluateFuzzy(inputs) >= in2.evaluateFuzzy(inputs))? 1.0: 0.0; + } + + public int maxInputs() { + return Math.max(in1.maxInputs(), in2.maxInputs()); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/welltestedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/welltestedsolution/test/org/netbeans/apifest/boolcircuit/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,221 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +/** The initial quest for this APIFest is to create an API for boolean + * circuits. Such API shall be able to compose a boolean circuit from + * basic elements and evaluate the result given initial values for + * input variables. + *

+ * The basic elements include: + *

    + *
  • negation - has one input and one output and changes 0 on input to + * on output 1 and 1 to 0 + *
  • and - has two inputs and one output. The output is 1 only if both + * inputs are 1, otherwise it is 0 + *
  • or - has two inputs and one output. The output is 1 always, except + * in the case when both inputs are 0 + *
+ * + *

+ * The boolean circuit can be used to represent boolean formulas and compute + * the results for certain values of its inputs. The individual tasks described + * as tests bellow. + * + *

+ * Links of interest: + *

+ */ +public class CircuitTest extends TestCase { + static { + // your code shall run without any permissions + } + + public CircuitTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** + * Create a circuit to evaluate x1 and x2 and then + * verify that its result is false for input (false, true) and + * it is true for input (true, true). + */ + public void testX1andX2() { + assertFalse("x1 and x2 for (false, true)", Circuit.createAndCircuit(null, null).evaluate(false, true)); + assertTrue("x1 and x2 for (true, true)", Circuit.createAndCircuit(null, null).evaluate(true, true)); + } + + /** + * Create a circuit to evaluate (x1 and x2) or x3 and then + * verify that its result is false for input (false, true, false) and + * it is true for input (false, false, true). + */ + public void testX1andX2orX3() { + Circuit c = Circuit.createOrCircuit(Circuit.createAndCircuit(null, null), null); + assertFalse("(x1 and x2) or x3", c.evaluate(false, true, false)); + assertTrue("(x1 and x2) or x3", c.evaluate(false, false, true)); + + assertTrue("(x1 and x2) or x3", c.evaluate(true, true, true)); + assertFalse("(x1 and x2) or x3", c.evaluate(true, false, false)); + } + /** + * Create a circuit to evaluate (x1 or not(x1)) and then + * verify that its result is true for all values of x1. + */ + public void testAlwaysTrue() { + Circuit c = Circuit.createOrCircuit(null, Circuit.createNotCircuit(null)); + assertTrue("(x1 or not(x1)) for false", c.evaluate(false, false)); + assertTrue("(x1 or not(x1)) for false", c.evaluate(true, true)); + } + + public void testOr() { + Circuit c = Circuit.createOrCircuit(null, null); + try { + c.evaluate(); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true, true, true); + } catch (IllegalArgumentException iae) { // expected + } + assertFalse("(x1 or x2)", c.evaluate(false, false)); + assertTrue("(x1 or x2)", c.evaluate(true, false)); + assertTrue("(x1 or x2)", c.evaluate(false, true)); + assertTrue("(x1 or x2)", c.evaluate(true, true)); + assertEquals("0.0, 0.0", 0.0, c.evaluateFuzzy(0.0, 0.0), 0.0); + assertEquals("0.0, 1.0", 1.0, c.evaluateFuzzy(0.0, 1.0), 0.0); + assertEquals("1.0, 1.0", 1.0, c.evaluateFuzzy(1.0, 1.0), 0.0); + assertEquals("0.3, 0.5", 0.65, c.evaluateFuzzy(0.3, 0.5), 0.0); + + } + + public void testOrCorrectly() { + Circuit c = Circuit.createOrCircuit(null, null); + try { + c.evaluate(); + fail("missing"); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true); + fail("missing"); + } catch (IllegalArgumentException iae) { // expected + } + } + + public void testAnd() { + Circuit c = Circuit.createAndCircuit(null, null); + try { + c.evaluate(); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true, true, true); + } catch (IllegalArgumentException iae) { // expected + } + assertFalse("(x1 or x2)", c.evaluate(false, false)); + assertFalse("(x1 or x2)", c.evaluate(true, false)); + assertFalse("(x1 or x2)", c.evaluate(false, true)); + assertTrue("(x1 or x2)", c.evaluate(true, true)); + + assertEquals("0.0, 0.0", 0.0, c.evaluateFuzzy(0.0, 0.0), 0.0); + assertEquals("0.0, 1.0", 0.0, c.evaluateFuzzy(0.0, 1.0), 0.0); + assertEquals("1.0, 1.0", 1.0, c.evaluateFuzzy(1.0, 1.0), 0.0); + assertEquals("0.3, 0.5", 0.15, c.evaluateFuzzy(0.3, 0.5), 0.0); + } + + public void testAndCorrectly() { + Circuit c = Circuit.createAndCircuit(null, null); + try { + c.evaluate(); + fail("missing"); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true); + fail("missing"); + } catch (IllegalArgumentException iae) { // expected + } + // actually if more values are passed they are ignored + /* + try { + c.evaluate(true, true, true); + fail("too much"); + } catch (IllegalArgumentException iae) { // expected + } + */ + } + + public void testNot() { + Circuit c = Circuit.createNotCircuit(null); + try { + c.evaluate(); + } catch (IllegalArgumentException iae) { // expected + } + try { + c.evaluate(true, true); + } catch (IllegalArgumentException iae) { // expected + } + assertFalse("(x1 or x2)", c.evaluate(true)); + assertTrue("(x1 or x2)", c.evaluate(false)); + + assertEquals("0.0", 1.0, c.evaluateFuzzy(0.0), 0.0); + assertEquals("1.0", 0.0, c.evaluateFuzzy(1.0), 0.0); + assertEquals("0.2", 0.8, c.evaluateFuzzy(0.2), 0.0); + } + + public void testNotCorrectly() { + Circuit c = Circuit.createNotCircuit(null); + try { + c.evaluate(); + fail("missing"); + } catch (IllegalArgumentException iae) { // expected + } + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day2/welltestedsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/welltestedsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,173 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; +import org.netbeans.apifest.custom.Gte; + +/** This file contains the APIFest quest for day 2. Simply, turn the + * boolean circuit into circuit that can compute with double values from 0 to 1. + *

+ * This means that where ever a boolean was used to represent input or + * output values, one can now use any double number from >= 0 and <= 1. + * Still, to support backward compatibility, the operations with booleans + * has to be kept available and have to work. In fact False shall be + * treated as 0 and True as 1. + *

+ * The basic elements has to be modified to work on doubles in the following + * way: + *

    + *
  • negation - neg(x) = 1 - x, this is correct extension as neg(false)=neg(0)=1-0=1=true + *
  • and - and(x,y) = x * y, again this is fine as and(true,true)=1*1=true and also + * and(false,true)=0*1=0=false + *
  • or - or(x,y) = 1 - (1 - x) * (1 - y) and this is also ok as + * or(false,false) = 1 - (1 - 0) * (1 - 0) = 1 - 1 = 0 = false + * or(true,false) = 1 - (1 - 1) * (1 - 0) = 1 - 0 * 1 = 1 = true + *
+ *

+ * However as the circuits with doubles are more rich than plain boolean circuits, + * there is additional requirement to allow any user of your API to write its + * own "element" type. This is all going to be exercise in the tests bellow + * which you are supposed to implement. + */ +public class RealTest extends TestCase { + static { + // your code shall run without any permissions + } + + public RealTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + } + + protected void tearDown() throws Exception { + } + + + /** First of all create a circuit which will evaluate + * expression (X1 and X2) or not(x1). Hold the circuit + * in some variable. + * + * Feed this circuit with x1=true, x2=false, assert result is false + * + * Feed the same circuit with x1=false, x2=true, assert result is true + * + * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0 + * + * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625 + * + * Feed the same circuit with x1=0.0, x2=2.0, make sure it throws an exception + */ + public void testX1andX2orNotX1() { + Circuit c = Circuit.createOrCircuit( + Circuit.createAndCircuit(Circuit.input(0), Circuit.input(1)), + Circuit.createNotCircuit(Circuit.input(0)) + ); + assertFalse("true, false", c.evaluate(true, false)); + assertTrue("false, true", c.evaluate(false, true)); + assertEquals("0.0, 1.0", 1.0, c.evaluateFuzzy(0.0, 1.0), 0.0); + } + + /** Ensure that one variable cannot be filled with two different values. + * Create a circuit for x1 and x1. Make sure that for any usage of your + * API that would not lead to x1 * x1 result, an exception is thrown. + * For example if there was a way to feed the circuit with two different + * values 0.3 and 0.5 an exception is thrown indicating that this is + * improper use of the circuit. + */ + public void testImproperUseOfTheCircuit() { + // does not apply + + Circuit x1 = Circuit.input(0); + Circuit c = Circuit.createOrCircuit(x1, x1); + assertTrue("x1 or x1", c.evaluate(true)); + assertFalse("x1 or x1", c.evaluate(false)); + try { + c.evaluate(); + fail("x1 or x1 with wrong params"); + } catch (IllegalArgumentException iea) { + //expected + } + // the same with two instances of pin + c = Circuit.createOrCircuit(Circuit.input(0), Circuit.input(0)); + assertTrue("x1 or x1", c.evaluate(true)); + assertTrue("x1 or x1", c.evaluate(true, false)); + assertTrue("x1 or x1", c.evaluate(true, true)); + assertFalse("x1 or x1", c.evaluate(false)); + try { + c.evaluate(); + fail("x1 or x1 with wrong params"); + } catch (IllegalArgumentException iea) { + //expected + } + } + + /** Write your own element type called "gte" that will have two inputs and one output. + * The output value will be 1 if x1 >= x2 and 0 otherwise. + * + * Create + * circuit for following expression: (x1 and not(x1)) gte x1 + * + * Feed the circuit with 0.5 and verify the result is 0 + * + * Feed the same circuit with 1 and verify the result is 0 + * + * Feed the same circuit with 0 and verify the result is 1 + */ + public void testGreaterThanEqualElement() { + Circuit gte = new Gte(Circuit.createAndCircuit( + Circuit.input(0), + Circuit.createNotCircuit(Circuit.input(0))), + Circuit.input(0) + ); + assertEquals("0.5", 0.0, gte.evaluateFuzzy(0.5), 0.0); + assertEquals("1.0", 0.0, gte.evaluateFuzzy(1.0), 0.0); + assertEquals("0.0", 1.0, gte.evaluateFuzzy(0.0), 0.0); + + } + + public void testSilly() { + // (x1 and not x2) or x3 + Circuit c = Circuit.createOrCircuit( + Circuit.createAndCircuit( + null, + Circuit.createNotCircuit(null)), + null + ); + assertEquals("1 1 1", 1.0, c.evaluateFuzzy(1.0, 1.0, 1.0), 0.0); + assertEquals("1 1 0", 0.0, c.evaluateFuzzy(1.0, 1.0, 0.0), 0.0); + assertEquals("1 0 1", 1.0, c.evaluateFuzzy(1.0, 0.0, 1.0), 0.0); + assertEquals("1 0 0", 1.0, c.evaluateFuzzy(1.0, 0.0, 0.0), 0.0); + assertEquals("0 1 1", 1.0, c.evaluateFuzzy(0.0, 1.0, 1.0), 0.0); + assertEquals("0 1 0", 0.0, c.evaluateFuzzy(0.0, 1.0, 0.0), 0.0); + assertEquals("0 0 1", 1.0, c.evaluateFuzzy(0.0, 0.0, 1.0), 0.0); + assertEquals("0 0 0", 0.0, c.evaluateFuzzy(0.0, 0.0, 0.0), 0.0); + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day3-intermezzo/jtulach/against-pinbasedsolution/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day3-intermezzo/jtulach/against-pinbasedsolution/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,97 @@ + + + + Builds the test against first version and runs them against two + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day3-intermezzo/jtulach/against-pinbasedsolution/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day3-intermezzo/jtulach/against-pinbasedsolution/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,77 @@ + + + org.netbeans.modules.ant.freeform + + + + testing-template + + build.xml + project.properties + + + + + java + test + + + + + + compile + + + + clean + + + + test + + + + test + + + + clean + compile + + + + folder + build/tests + + compile + + + + + + test + + + ${ant.script} + + + + + + + + + + + + + + + test + ${apiA}:${apifest}/lib/junit-3.8.2.jar + build/tests + 1.5 + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day3-intermezzo/jtulach/against-pinbasedsolution/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day3-intermezzo/jtulach/against-pinbasedsolution/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,17 @@ + +# location to root of the repository with apifest projects +apifest=../../.. + +# name of a project to test +apitotest=pinbasedsolution + +# the test shall expose a problem between two versions +# of one API. select the first version - dayA and a second +# version of the of the API dayB +dayA=${apifest}/day1 +dayB=${apifest}/day2 + +# usual locations of API classes for each version +apiA=${dayA}/${apitotest}/build/classes/ +apiB=${dayB}/${apitotest}/build/classes/ + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/day3-intermezzo/jtulach/against-pinbasedsolution/test/apifest/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day3-intermezzo/jtulach/against-pinbasedsolution/test/apifest/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,33 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package apifest; + +import junit.framework.TestCase; + + +/** Write a test that works with version from day A and fails with version B. + */ +public class CircuitTest extends TestCase { + public CircuitTest(String n) { + super(n); + } + + public void testClass() throws Exception { + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + + + + Builds, tests, and runs the project org.netbeans.apifest.testingtemplate. + + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/manifest.mf Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: org.netbeans.apifest.testingtemplate +OpenIDE-Module-Layer: org/netbeans/apifest/testingtemplate/layer.xml +OpenIDE-Module-Localizing-Bundle: org/netbeans/apifest/testingtemplate/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=d0464ec2 +build.xml.script.CRC32=356df90d +build.xml.stylesheet.CRC32=77ef55dd +# 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=d0464ec2 +nbproject/build-impl.xml.script.CRC32=46a2ac01 +nbproject/build-impl.xml.stylesheet.CRC32=2607fe5f diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/nbproject/platform.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/nbproject/platform.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,1 @@ +nbplatform.active=default diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,80 @@ + + + org.netbeans.modules.apisupport.project + + + org.netbeans.apifest.testingtemplate + + + + org.jdesktop.layout + + + + 1 + 1.4 + + + + org.netbeans.modules.projectapi + + + + 1 + 1.10 + + + + org.netbeans.modules.projectuiapi + + + + 1 + 1.15.0.5 + + + + org.openide.awt + + + + 6.8.0.1 + + + + org.openide.dialogs + + + + 7.0 + + + + org.openide.filesystems + + + + 7.0 + + + + org.openide.loaders + + + + 5.11 + + + + org.openide.util + + + + 7.2.1 + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/project/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/project/build.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,97 @@ + + + + Builds the test against first version and runs them against two + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/project/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/project/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,77 @@ + + + org.netbeans.modules.ant.freeform + + + + testing-template + + build.xml + project.properties + + + + + java + test + + + + + + compile + + + + clean + + + + test + + + + test + + + + clean + compile + + + + folder + build/tests + + compile + + + + + + test + + + ${ant.script} + + + + + + + + + + + + + + + test + ${apiA}:${apifest}/lib/junit-3.8.2.jar + build/tests + 1.5 + + + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/project/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/project/project.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,17 @@ + +# location to root of the repository with apifest projects +apifest=../../.. + +# name of a project to test +apitotest=alwayscreatenewcircuit + +# the test shall expose a problem between two versions +# of one API. select the first version - dayA and a second +# version of the of the API dayB +dayA=${apifest}/day1 +dayB=${apifest}/day2 + +# usual locations of API classes for each version +apiA=${dayA}/${apitotest}/build/classes/ +apiB=${dayB}/${apitotest}/build/classes/ + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/project/test/apifest/CircuitTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/project/test/apifest/CircuitTest.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,33 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package apifest; + +import junit.framework.TestCase; + + +/** Write a test that works with version from day A and fails with version B. + */ +public class CircuitTest extends TestCase { + public CircuitTest(String n) { + super(n); + } + + public void testClass() throws Exception { + } +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/Bundle.properties Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,3 @@ +LBL_CreateProjectStep=Name and Location +OpenIDE-Module-Name=Template to create testing project +Templates/Project/APIFest/TestingTemplateProject.zip=API Fest Testing Project diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/TestingTemplateDescription.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/TestingTemplateDescription.html Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,5 @@ + + + Sample API Fest Testing Project project + + diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/TestingTemplatePanelVisual.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/TestingTemplatePanelVisual.form Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,107 @@ + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/TestingTemplatePanelVisual.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/TestingTemplatePanelVisual.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,260 @@ +package org.netbeans.apifest.testingtemplate; + +import java.io.File; +import javax.swing.JFileChooser; +import javax.swing.JPanel; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.text.Document; +import org.netbeans.spi.project.ui.support.ProjectChooser; +import org.openide.WizardDescriptor; +import org.openide.WizardValidationException; +import org.openide.filesystems.FileUtil; + +public class TestingTemplatePanelVisual extends JPanel implements DocumentListener { + + public static final String PROP_PROJECT_NAME = "projectName"; + + private TestingTemplateWizardPanel panel; + + /** Creates new form PanelProjectLocationVisual */ + public TestingTemplatePanelVisual(TestingTemplateWizardPanel panel) { + initComponents(); + this.panel = panel; + // Register listener on the textFields to make the automatic updates + projectNameTextField.getDocument().addDocumentListener(this); + projectLocationTextField.getDocument().addDocumentListener(this); + } + + + public String getProjectName() { + return this.projectNameTextField.getText(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + projectNameLabel = new javax.swing.JLabel(); + projectNameTextField = new javax.swing.JTextField(); + projectLocationLabel = new javax.swing.JLabel(); + projectLocationTextField = new javax.swing.JTextField(); + browseButton = new javax.swing.JButton(); + createdFolderLabel = new javax.swing.JLabel(); + createdFolderTextField = new javax.swing.JTextField(); + + projectNameLabel.setLabelFor(projectNameTextField); + org.openide.awt.Mnemonics.setLocalizedText(projectNameLabel, "Project &Name:"); + + projectLocationLabel.setLabelFor(projectLocationTextField); + org.openide.awt.Mnemonics.setLocalizedText(projectLocationLabel, "Project &Location:"); + + org.openide.awt.Mnemonics.setLocalizedText(browseButton, "Br&owse..."); + browseButton.setActionCommand("BROWSE"); + browseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + browseButtonActionPerformed(evt); + } + }); + + createdFolderLabel.setLabelFor(createdFolderTextField); + org.openide.awt.Mnemonics.setLocalizedText(createdFolderLabel, "Project &Folder:"); + + createdFolderTextField.setEditable(false); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(projectNameLabel) + .add(projectLocationLabel) + .add(createdFolderLabel)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, projectNameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.TRAILING, projectLocationTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.TRAILING, createdFolderTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(browseButton) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(projectNameLabel) + .add(projectNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(projectLocationLabel) + .add(projectLocationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(browseButton)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(createdFolderLabel) + .add(createdFolderTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(213, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed + String command = evt.getActionCommand(); + if ("BROWSE".equals(command)) { + JFileChooser chooser = new JFileChooser(); + FileUtil.preventFileChooserSymlinkTraversal(chooser, null); + chooser.setDialogTitle("Select Project Location"); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + String path = this.projectLocationTextField.getText(); + if (path.length() > 0) { + File f = new File(path); + if (f.exists()) { + chooser.setSelectedFile(f); + } + } + if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { + File projectDir = chooser.getSelectedFile(); + projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath()); + } + panel.fireChangeEvent(); + } + + }//GEN-LAST:event_browseButtonActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton browseButton; + private javax.swing.JLabel createdFolderLabel; + private javax.swing.JTextField createdFolderTextField; + private javax.swing.JLabel projectLocationLabel; + private javax.swing.JTextField projectLocationTextField; + private javax.swing.JLabel projectNameLabel; + private javax.swing.JTextField projectNameTextField; + // End of variables declaration//GEN-END:variables + + public void addNotify() { + super.addNotify(); + //same problem as in 31086, initial focus on Cancel button + projectNameTextField.requestFocus(); + } + + boolean valid(WizardDescriptor wizardDescriptor) { + + if (projectNameTextField.getText().length() == 0) { + wizardDescriptor.putProperty("WizardPanel_errorMessage", + "Project Name is not a valid folder name."); + return false; // Display name not specified + } + File f = FileUtil.normalizeFile(new File(projectLocationTextField.getText()).getAbsoluteFile()); + if (!f.isDirectory()) { + String message = "Project Folder is not a valid path."; + wizardDescriptor.putProperty("WizardPanel_errorMessage", message); + return false; + } + final File destFolder = FileUtil.normalizeFile(new File(createdFolderTextField.getText()).getAbsoluteFile()); + + File projLoc = destFolder; + while (projLoc != null && !projLoc.exists()) { + projLoc = projLoc.getParentFile(); + } + if (projLoc == null || !projLoc.canWrite()) { + wizardDescriptor.putProperty("WizardPanel_errorMessage", + "Project Folder cannot be created."); + return false; + } + + if (FileUtil.toFileObject(projLoc) == null) { + String message = "Project Folder is not a valid path."; + wizardDescriptor.putProperty("WizardPanel_errorMessage", message); + return false; + } + + File[] kids = destFolder.listFiles(); + if (destFolder.exists() && kids != null && kids.length > 0) { + // Folder exists and is not empty + wizardDescriptor.putProperty("WizardPanel_errorMessage", + "Project Folder already exists and is not empty."); + return false; + } + wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); + return true; + } + + void store(WizardDescriptor d) { + String name = projectNameTextField.getText().trim(); + String folder = createdFolderTextField.getText().trim(); + + d.putProperty("projdir", new File(folder)); + d.putProperty("name", name); + } + + void read(WizardDescriptor settings) { + File projectLocation = (File) settings.getProperty("projdir"); + if (projectLocation == null || projectLocation.getParentFile() == null || !projectLocation.getParentFile().isDirectory()) { + projectLocation = ProjectChooser.getProjectsFolder(); + } else { + projectLocation = projectLocation.getParentFile(); + } + this.projectLocationTextField.setText(projectLocation.getAbsolutePath()); + + String projectName = (String) settings.getProperty("name"); + if(projectName == null) { + projectName = "TestingTemplate"; + } + this.projectNameTextField.setText(projectName); + this.projectNameTextField.selectAll(); + } + + void validate(WizardDescriptor d) throws WizardValidationException { + // nothing to validate + } + + // Implementation of DocumentListener -------------------------------------- + + public void changedUpdate(DocumentEvent e) { + updateTexts(e); + if (this.projectNameTextField.getDocument() == e.getDocument()) { + firePropertyChange(PROP_PROJECT_NAME,null,this.projectNameTextField.getText()); + } + } + + public void insertUpdate(DocumentEvent e) { + updateTexts(e); + if (this.projectNameTextField.getDocument() == e.getDocument()) { + firePropertyChange(PROP_PROJECT_NAME,null,this.projectNameTextField.getText()); + } + } + + public void removeUpdate(DocumentEvent e) { + updateTexts(e); + if (this.projectNameTextField.getDocument() == e.getDocument()) { + firePropertyChange(PROP_PROJECT_NAME,null,this.projectNameTextField.getText()); + } + } + + /** Handles changes in the Project name and project directory, */ + private void updateTexts(DocumentEvent e) { + + Document doc = e.getDocument(); + + if (doc == projectNameTextField.getDocument() || doc == projectLocationTextField.getDocument()) { + // Change in the project name + + String projectName = projectNameTextField.getText(); + String projectFolder = projectLocationTextField.getText(); + + //if (projectFolder.trim().length() == 0 || projectFolder.equals(oldName)) { + createdFolderTextField.setText(projectFolder + File.separatorChar + projectName); + //} + + } + panel.fireChangeEvent(); // Notify that the panel changed + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/TestingTemplateWizardIterator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/TestingTemplateWizardIterator.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,171 @@ +package org.netbeans.apifest.testingtemplate; + +import java.awt.Component; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.text.MessageFormat; +import java.util.Enumeration; +import java.util.LinkedHashSet; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import javax.swing.JComponent; +import javax.swing.event.ChangeListener; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.spi.project.ui.support.ProjectChooser; +import org.netbeans.spi.project.ui.templates.support.Templates; +import org.openide.WizardDescriptor; +import org.openide.filesystems.FileLock; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.NbBundle; + +public class TestingTemplateWizardIterator implements WizardDescriptor.InstantiatingIterator { + + private int index; + private WizardDescriptor.Panel[] panels; + private WizardDescriptor wiz; + + public TestingTemplateWizardIterator() {} + + public static TestingTemplateWizardIterator createIterator() { + return new TestingTemplateWizardIterator(); + } + + private WizardDescriptor.Panel[] createPanels() { + return new WizardDescriptor.Panel[] { + new TestingTemplateWizardPanel(), + }; + } + + private String[] createSteps() { + return new String[] { + NbBundle.getMessage(TestingTemplateWizardIterator.class, "LBL_CreateProjectStep") + }; + } + + public Set/**/ instantiate() throws IOException { + Set resultSet = new LinkedHashSet(); + File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); + dirF.mkdirs(); + + FileObject template = Templates.getTemplate(wiz); + FileObject dir = FileUtil.toFileObject(dirF); + unZipFile(template.getInputStream(), dir); + + // Always open top dir as a project: + resultSet.add(dir); + // Look for nested projects to open as well: + Enumeration e = dir.getFolders(true); + while (e.hasMoreElements()) { + FileObject subfolder = (FileObject) e.nextElement(); + if (ProjectManager.getDefault().isProject(subfolder)) { + resultSet.add(subfolder); + } + } + + File parent = dirF.getParentFile(); + if (parent != null && parent.exists()) { + ProjectChooser.setProjectsFolder(parent); + } + + return resultSet; + } + + public void initialize(WizardDescriptor wiz) { + this.wiz = wiz; + index = 0; + panels = createPanels(); + // Make sure list of steps is accurate. + String[] steps = createSteps(); + for (int i = 0; i < panels.length; i++) { + Component c = panels[i].getComponent(); + if (steps[i] == null) { + // Default step name to component name of panel. + // Mainly useful for getting the name of the target + // chooser to appear in the list of steps. + steps[i] = c.getName(); + } + if (c instanceof JComponent) { // assume Swing components + JComponent jc = (JComponent) c; + // Step #. + jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); + // Step name (actually the whole list for reference). + jc.putClientProperty("WizardPanel_contentData", steps); + } + } + } + + public void uninitialize(WizardDescriptor wiz) { + this.wiz.putProperty("projdir",null); + this.wiz.putProperty("name",null); + this.wiz = null; + panels = null; + } + + public String name() { + return MessageFormat.format("{0} of {1}", + new Object[] {new Integer(index + 1), new Integer(panels.length)}); + } + + public boolean hasNext() { + return index < panels.length - 1; + } + + public boolean hasPrevious() { + return index > 0; + } + + public void nextPanel() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + index++; + } + + public void previousPanel() { + if (!hasPrevious()) { + throw new NoSuchElementException(); + } + index--; + } + + public WizardDescriptor.Panel current() { + return panels[index]; + } + + // If nothing unusual changes in the middle of the wizard, simply: + public final void addChangeListener(ChangeListener l) {} + public final void removeChangeListener(ChangeListener l) {} + + private static void unZipFile(InputStream source, FileObject projectRoot) throws IOException { + try { + ZipInputStream str = new ZipInputStream(source); + ZipEntry entry; + while ((entry = str.getNextEntry()) != null) { + if (entry.isDirectory()) { + FileUtil.createFolder(projectRoot, entry.getName()); + } else { + FileObject fo = FileUtil.createData(projectRoot, entry.getName()); + FileLock lock = fo.lock(); + try { + OutputStream out = fo.getOutputStream(lock); + try { + FileUtil.copy(str, out); + } finally { + out.close(); + } + } finally { + lock.releaseLock(); + } + } + } + } finally { + source.close(); + } + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/TestingTemplateWizardPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/TestingTemplateWizardPanel.java Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,85 @@ +package org.netbeans.apifest.testingtemplate; + +import java.awt.Component; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import org.openide.WizardDescriptor; +import org.openide.WizardValidationException; +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; + +/** + * Panel just asking for basic info. + */ +public class TestingTemplateWizardPanel implements WizardDescriptor.Panel, + WizardDescriptor.ValidatingPanel, WizardDescriptor.FinishablePanel { + + private WizardDescriptor wizardDescriptor; + private TestingTemplatePanelVisual component; + + /** Creates a new instance of templateWizardPanel */ + public TestingTemplateWizardPanel() { + } + + public Component getComponent() { + if (component == null) { + component = new TestingTemplatePanelVisual(this); + component.setName(NbBundle.getMessage(TestingTemplateWizardPanel.class, "LBL_CreateProjectStep")); + } + return component; + } + + public HelpCtx getHelp() { + return new HelpCtx(TestingTemplateWizardPanel.class); + } + + public boolean isValid() { + getComponent(); + return component.valid(wizardDescriptor); + } + + private final Set/**/ listeners = new HashSet(1); + public final void addChangeListener(ChangeListener l) { + synchronized (listeners) { + listeners.add(l); + } + } + public final void removeChangeListener(ChangeListener l) { + synchronized (listeners) { + listeners.remove(l); + } + } + protected final void fireChangeEvent() { + Iterator it; + synchronized (listeners) { + it = new HashSet(listeners).iterator(); + } + ChangeEvent ev = new ChangeEvent(this); + while (it.hasNext()) { + ((ChangeListener) it.next()).stateChanged(ev); + } + } + + public void readSettings(Object settings) { + wizardDescriptor = (WizardDescriptor) settings; + component.read(wizardDescriptor); + } + + public void storeSettings(Object settings) { + WizardDescriptor d = (WizardDescriptor) settings; + component.store(d); + } + + public boolean isFinishPanel() { + return true; + } + + public void validate() throws WizardValidationException { + getComponent(); + component.validate(wizardDescriptor); + } + +} diff -r 130e099942d8 -r 4257f4cf226b samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/layer.xml Sat Jun 14 09:52:45 2008 +0200 @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + +