jtulach@52: /* jtulach@52: * The contents of this file are subject to the terms of the Common Development jtulach@52: * and Distribution License (the License). You may not use this file except in jtulach@52: * compliance with the License. jtulach@52: * jtulach@52: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html jtulach@52: * or http://www.netbeans.org/cddl.txt. jtulach@52: * jtulach@52: * When distributing Covered Code, include this CDDL Header Notice in each file jtulach@52: * and include the License file at http://www.netbeans.org/cddl.txt. jtulach@52: * If applicable, add the following below the CDDL Header, with the fields jtulach@52: * enclosed by brackets [] replaced by your own identifying information: jtulach@52: * "Portions Copyrighted [year] [name of copyright owner]" jtulach@52: * jtulach@52: * The Original Software is NetBeans. The Initial Developer of the Original jtulach@52: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun jtulach@52: * Microsystems, Inc. All Rights Reserved. jtulach@52: */ jtulach@52: jtulach@52: package org.netbeans.apifest.boolcircuit; jtulach@52: jtulach@52: jtulach@53: // BEGIN: apifest.day1.subclassingsolution jtulach@52: /** Usefull class for building your own circuits. jtulach@52: * jtulach@52: */ jtulach@52: public abstract class Circuit extends Object { jtulach@52: jtulach@52: /** For your conveninece */ jtulach@52: public static Circuit AND = new Circuit() { jtulach@52: jtulach@52: @Override jtulach@52: public boolean evaluate(boolean[] in) { jtulach@52: if ( in.length != 2) { jtulach@132: throw new IllegalArgumentException( jtulach@132: "Should have two parameters" jtulach@132: ); jtulach@52: } jtulach@52: return in[0] && in[1]; jtulach@52: } jtulach@52: jtulach@52: }; jtulach@52: jtulach@52: public static Circuit OR = new Circuit() { jtulach@52: jtulach@52: @Override jtulach@52: public boolean evaluate(boolean[] in) { jtulach@52: if ( in.length != 2) { jtulach@132: throw new IllegalArgumentException( jtulach@132: "Should have two parameters" jtulach@132: ); jtulach@52: } jtulach@52: return in[0] || in[1]; jtulach@52: } jtulach@52: jtulach@52: }; jtulach@52: jtulach@52: public static Circuit NOT = new Circuit() { jtulach@52: jtulach@52: @Override jtulach@52: public boolean evaluate(boolean[] in) { jtulach@52: if ( in.length != 1) { jtulach@132: throw new IllegalArgumentException( jtulach@132: "Should have one parameter" jtulach@132: ); jtulach@52: } jtulach@52: return !in[0]; jtulach@52: } jtulach@52: jtulach@52: }; jtulach@52: jtulach@52: jtulach@132: /** Feel free to implement and don't hesitate to throw jtulach@132: * IllegalArgumentEception jtulach@52: */ jtulach@52: public abstract boolean evaluate(boolean... in); jtulach@52: jtulach@52: } jtulach@53: // END: apifest.day1.subclassingsolution jtulach@53: jtulach@53: