samples/apifest1/day2/subclassingsolution/src/org/netbeans/apifest/boolcircuit/FuzzyCircuit.java
changeset 52 4257f4cf226b
child 54 45b0d58e66ca
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/apifest1/day2/subclassingsolution/src/org/netbeans/apifest/boolcircuit/FuzzyCircuit.java	Sat Jun 14 09:52:45 2008 +0200
     1.3 @@ -0,0 +1,58 @@
     1.4 +/*
     1.5 + * FuzzyCircuit.java
     1.6 + *
     1.7 + * Created on July 13, 2006, 2:31 PM
     1.8 + *
     1.9 + * To change this template, choose Tools | Template Manager
    1.10 + * and open the template in the editor.
    1.11 + */
    1.12 +
    1.13 +package org.netbeans.apifest.boolcircuit;
    1.14 +
    1.15 +/**
    1.16 + *
    1.17 + * @author phrebejk
    1.18 + */
    1.19 +public abstract class FuzzyCircuit extends Circuit {
    1.20 +    
    1.21 +    /** Feel free to implement and don't hesitate to throw IllegalArgumentEception 
    1.22 +     */
    1.23 +    public abstract double evaluate(double... in);
    1.24 +    
    1.25 +    public static final void checkParams( int expectedLenght, boolean... in  ) {
    1.26 +        
    1.27 +        // :-) in real world add a test for null too
    1.28 +        
    1.29 +        if (expectedLenght != in.length) {
    1.30 +            
    1.31 +            // :-) Probably unnecessary unless this is a competition 
    1.32 +            switch ( expectedLenght ) {
    1.33 +                case 1:
    1.34 +                    throw new IllegalArgumentException("Should have one parameter");
    1.35 +                case 2:
    1.36 +                    throw new IllegalArgumentException("Should have two parameters");
    1.37 +                default:
    1.38 +                    throw new IllegalArgumentException("Wrong number of parameters!");
    1.39 +            }                       
    1.40 +        }
    1.41 +    }
    1.42 +    
    1.43 +    public static final void checkParams( int expectedLenght, double ... in ) {
    1.44 +        if ( in == null ) {
    1.45 +            throw new IllegalArgumentException( "Parameter in must not be null!");
    1.46 +        }
    1.47 +        if (expectedLenght != in.length) {
    1.48 +            throw new IllegalArgumentException("Wrong number of parameters!");
    1.49 +        }
    1.50 +        
    1.51 +        for( int i = 0; i < in.length; i++ ) {
    1.52 +            if ( in[i] < 0.0 || in[i] > 1.0 ) {
    1.53 +                throw new IllegalArgumentException( 
    1.54 +                        "All params have to be in the range <0.0, 1.0>! " +
    1.55 +                        "param at index " + i + " is " + in[i]);
    1.56 +            }
    1.57 +        }
    1.58 +        
    1.59 +    }
    1.60 +          
    1.61 +}