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