samples/apifest1/day2/subclassingsolution/src/org/netbeans/apifest/boolcircuit/FuzzyCircuit.java
Adding samples from API fest to the repository, including pieces of their code in the document, not just links
4 * Created on July 13, 2006, 2:31 PM
6 * To change this template, choose Tools | Template Manager
7 * and open the template in the editor.
10 package org.netbeans.apifest.boolcircuit;
16 public abstract class FuzzyCircuit extends Circuit {
18 /** Feel free to implement and don't hesitate to throw IllegalArgumentEception
20 public abstract double evaluate(double... in);
22 public static final void checkParams( int expectedLenght, boolean... in ) {
24 // :-) in real world add a test for null too
26 if (expectedLenght != in.length) {
28 // :-) Probably unnecessary unless this is a competition
29 switch ( expectedLenght ) {
31 throw new IllegalArgumentException("Should have one parameter");
33 throw new IllegalArgumentException("Should have two parameters");
35 throw new IllegalArgumentException("Wrong number of parameters!");
40 public static final void checkParams( int expectedLenght, double ... in ) {
42 throw new IllegalArgumentException( "Parameter in must not be null!");
44 if (expectedLenght != in.length) {
45 throw new IllegalArgumentException("Wrong number of parameters!");
48 for( int i = 0; i < in.length; i++ ) {
49 if ( in[i] < 0.0 || in[i] > 1.0 ) {
50 throw new IllegalArgumentException(
51 "All params have to be in the range <0.0, 1.0>! " +
52 "param at index " + i + " is " + in[i]);