samples/apifest1/day2/subclassingsolution/src/org/netbeans/apifest/boolcircuit/FuzzyCircuit.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:52:48 +0200
changeset 54 45b0d58e66ca
parent 52 4257f4cf226b
permissions -rw-r--r--
Getting the solutions from the CVS, not just from the ZIP file
jtulach@52
     1
/*
jtulach@52
     2
 * FuzzyCircuit.java
jtulach@52
     3
 *
jtulach@52
     4
 * Created on July 13, 2006, 2:31 PM
jtulach@52
     5
 *
jtulach@52
     6
 * To change this template, choose Tools | Template Manager
jtulach@52
     7
 * and open the template in the editor.
jtulach@52
     8
 */
jtulach@52
     9
jtulach@52
    10
package org.netbeans.apifest.boolcircuit;
jtulach@52
    11
jtulach@52
    12
public abstract class FuzzyCircuit extends Circuit {
jtulach@52
    13
    
jtulach@52
    14
    /** Feel free to implement and don't hesitate to throw IllegalArgumentEception 
jtulach@52
    15
     */
jtulach@52
    16
    public abstract double evaluate(double... in);
jtulach@52
    17
    
jtulach@52
    18
    public static final void checkParams( int expectedLenght, boolean... in  ) {
jtulach@52
    19
        
jtulach@52
    20
        // :-) in real world add a test for null too
jtulach@52
    21
        
jtulach@52
    22
        if (expectedLenght != in.length) {
jtulach@52
    23
            
jtulach@52
    24
            // :-) Probably unnecessary unless this is a competition 
jtulach@52
    25
            switch ( expectedLenght ) {
jtulach@52
    26
                case 1:
jtulach@52
    27
                    throw new IllegalArgumentException("Should have one parameter");
jtulach@52
    28
                case 2:
jtulach@52
    29
                    throw new IllegalArgumentException("Should have two parameters");
jtulach@52
    30
                default:
jtulach@52
    31
                    throw new IllegalArgumentException("Wrong number of parameters!");
jtulach@52
    32
            }                       
jtulach@52
    33
        }
jtulach@52
    34
    }
jtulach@52
    35
    
jtulach@52
    36
    public static final void checkParams( int expectedLenght, double ... in ) {
jtulach@52
    37
        if ( in == null ) {
jtulach@52
    38
            throw new IllegalArgumentException( "Parameter in must not be null!");
jtulach@52
    39
        }
jtulach@52
    40
        if (expectedLenght != in.length) {
jtulach@52
    41
            throw new IllegalArgumentException("Wrong number of parameters!");
jtulach@52
    42
        }
jtulach@52
    43
        
jtulach@52
    44
        for( int i = 0; i < in.length; i++ ) {
jtulach@52
    45
            if ( in[i] < 0.0 || in[i] > 1.0 ) {
jtulach@52
    46
                throw new IllegalArgumentException( 
jtulach@52
    47
                        "All params have to be in the range <0.0, 1.0>! " +
jtulach@52
    48
                        "param at index " + i + " is " + in[i]);
jtulach@52
    49
            }
jtulach@52
    50
        }
jtulach@52
    51
        
jtulach@52
    52
    }
jtulach@52
    53
          
jtulach@52
    54
}