author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:52:45 +0200 | |
changeset 52 | 4257f4cf226b |
child 54 | 45b0d58e66ca |
permissions | -rw-r--r-- |
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 |
/** |
jtulach@52 | 13 |
* |
jtulach@52 | 14 |
* @author phrebejk |
jtulach@52 | 15 |
*/ |
jtulach@52 | 16 |
public abstract class FuzzyCircuit extends Circuit { |
jtulach@52 | 17 |
|
jtulach@52 | 18 |
/** Feel free to implement and don't hesitate to throw IllegalArgumentEception |
jtulach@52 | 19 |
*/ |
jtulach@52 | 20 |
public abstract double evaluate(double... in); |
jtulach@52 | 21 |
|
jtulach@52 | 22 |
public static final void checkParams( int expectedLenght, boolean... in ) { |
jtulach@52 | 23 |
|
jtulach@52 | 24 |
// :-) in real world add a test for null too |
jtulach@52 | 25 |
|
jtulach@52 | 26 |
if (expectedLenght != in.length) { |
jtulach@52 | 27 |
|
jtulach@52 | 28 |
// :-) Probably unnecessary unless this is a competition |
jtulach@52 | 29 |
switch ( expectedLenght ) { |
jtulach@52 | 30 |
case 1: |
jtulach@52 | 31 |
throw new IllegalArgumentException("Should have one parameter"); |
jtulach@52 | 32 |
case 2: |
jtulach@52 | 33 |
throw new IllegalArgumentException("Should have two parameters"); |
jtulach@52 | 34 |
default: |
jtulach@52 | 35 |
throw new IllegalArgumentException("Wrong number of parameters!"); |
jtulach@52 | 36 |
} |
jtulach@52 | 37 |
} |
jtulach@52 | 38 |
} |
jtulach@52 | 39 |
|
jtulach@52 | 40 |
public static final void checkParams( int expectedLenght, double ... in ) { |
jtulach@52 | 41 |
if ( in == null ) { |
jtulach@52 | 42 |
throw new IllegalArgumentException( "Parameter in must not be null!"); |
jtulach@52 | 43 |
} |
jtulach@52 | 44 |
if (expectedLenght != in.length) { |
jtulach@52 | 45 |
throw new IllegalArgumentException("Wrong number of parameters!"); |
jtulach@52 | 46 |
} |
jtulach@52 | 47 |
|
jtulach@52 | 48 |
for( int i = 0; i < in.length; i++ ) { |
jtulach@52 | 49 |
if ( in[i] < 0.0 || in[i] > 1.0 ) { |
jtulach@52 | 50 |
throw new IllegalArgumentException( |
jtulach@52 | 51 |
"All params have to be in the range <0.0, 1.0>! " + |
jtulach@52 | 52 |
"param at index " + i + " is " + in[i]); |
jtulach@52 | 53 |
} |
jtulach@52 | 54 |
} |
jtulach@52 | 55 |
|
jtulach@52 | 56 |
} |
jtulach@52 | 57 |
|
jtulach@52 | 58 |
} |