samples/apifest1/day2/subclassingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java
changeset 52 4257f4cf226b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/apifest1/day2/subclassingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java	Sat Jun 14 09:52:45 2008 +0200
     1.3 @@ -0,0 +1,90 @@
     1.4 +/*
     1.5 + * The contents of this file are subject to the terms of the Common Development
     1.6 + * and Distribution License (the License). You may not use this file except in
     1.7 + * compliance with the License.
     1.8 + *
     1.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
    1.10 + * or http://www.netbeans.org/cddl.txt.
    1.11 + *
    1.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
    1.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
    1.14 + * If applicable, add the following below the CDDL Header, with the fields
    1.15 + * enclosed by brackets [] replaced by your own identifying information:
    1.16 + * "Portions Copyrighted [year] [name of copyright owner]"
    1.17 + *
    1.18 + * The Original Software is NetBeans. The Initial Developer of the Original
    1.19 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
    1.20 + * Microsystems, Inc. All Rights Reserved.
    1.21 + */
    1.22 +
    1.23 +package org.netbeans.apifest.boolcircuit;
    1.24 +
    1.25 +
    1.26 +/** Usefull class for building your own circuits. 
    1.27 + * </br>
    1.28 + *  Notice that this API nobly generously permits using operator overloading
    1.29 + *  </br>
    1.30 + *  :-) Sometimes when you find an unfixable bug. The best thing to do is to 
    1.31 + *  make it a fature.
    1.32 + * 
    1.33 + */
    1.34 +public abstract class Circuit extends Object {
    1.35 +    
    1.36 +    /** For your conveninece */   
    1.37 +    public static FuzzyCircuit AND = new FuzzyCircuit() {
    1.38 +
    1.39 +        @Override
    1.40 +        public boolean evaluate(boolean[] in) {
    1.41 +            checkParams( 2, in );
    1.42 +            return in[0] && in[1];
    1.43 +        }
    1.44 +
    1.45 +        public double evaluate(double[] in) {
    1.46 +            checkParams( 2, in );
    1.47 +            return in[0] * in[1];
    1.48 +        }
    1.49 +        
    1.50 +    };
    1.51 +    
    1.52 +    /** For your conveninece */
    1.53 +    public static FuzzyCircuit OR = new FuzzyCircuit() {
    1.54 +
    1.55 +        @Override
    1.56 +        public boolean evaluate(boolean[] in) {
    1.57 +            checkParams( 2, in );            
    1.58 +            return in[0] || in[1];
    1.59 +        }
    1.60 +
    1.61 +        @Override
    1.62 +        public double evaluate(double[] in) {
    1.63 +            checkParams( 2, in );            
    1.64 +            return 1 - (1 - in[0]) * (1 - in[1]);
    1.65 +        }
    1.66 +    };
    1.67 +    
    1.68 +    
    1.69 +    /** For your conveninece */
    1.70 +    public static FuzzyCircuit NOT = new FuzzyCircuit() {
    1.71 +
    1.72 +        @Override
    1.73 +        public boolean evaluate(boolean[] in) {
    1.74 +            checkParams( 1, in );            
    1.75 +            return !in[0];
    1.76 +        }
    1.77 +
    1.78 +        @Override
    1.79 +        public double evaluate(double[] in) {
    1.80 +            checkParams( 1, in );            
    1.81 +            return 1 - in[0];
    1.82 +        }
    1.83 +        
    1.84 +        
    1.85 +    };
    1.86 +            
    1.87 +    /** Feel free to implement and don't hesitate to throw IllegalArgumentEception 
    1.88 +     */
    1.89 +    public abstract boolean evaluate(boolean... in);
    1.90 +        
    1.91 +    
    1.92 +    
    1.93 +}