author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:58:11 +0200 | |
changeset 154 | 0fd5e9c500b9 |
parent 153 | b5cbb797ec0a |
permissions | -rw-r--r-- |
jtulach@52 | 1 |
/* |
jtulach@52 | 2 |
* The contents of this file are subject to the terms of the Common Development |
jtulach@52 | 3 |
* and Distribution License (the License). You may not use this file except in |
jtulach@52 | 4 |
* compliance with the License. |
jtulach@52 | 5 |
* |
jtulach@52 | 6 |
* You can obtain a copy of the License at http://www.netbeans.org/cddl.html |
jtulach@52 | 7 |
* or http://www.netbeans.org/cddl.txt. |
jtulach@52 | 8 |
* |
jtulach@52 | 9 |
* When distributing Covered Code, include this CDDL Header Notice in each file |
jtulach@52 | 10 |
* and include the License file at http://www.netbeans.org/cddl.txt. |
jtulach@52 | 11 |
* If applicable, add the following below the CDDL Header, with the fields |
jtulach@52 | 12 |
* enclosed by brackets [] replaced by your own identifying information: |
jtulach@52 | 13 |
* "Portions Copyrighted [year] [name of copyright owner]" |
jtulach@52 | 14 |
* |
jtulach@52 | 15 |
* The Original Software is NetBeans. The Initial Developer of the Original |
jtulach@52 | 16 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun |
jtulach@52 | 17 |
* Microsystems, Inc. All Rights Reserved. |
jtulach@52 | 18 |
*/ |
jtulach@52 | 19 |
|
jtulach@52 | 20 |
package org.netbeans.apifest.boolcircuit; |
jtulach@52 | 21 |
|
jtulach@52 | 22 |
|
jtulach@53 | 23 |
// BEGIN: apifest.day1.subclassingsolution |
jtulach@52 | 24 |
/** Usefull class for building your own circuits. |
jtulach@52 | 25 |
* |
jtulach@52 | 26 |
*/ |
jtulach@52 | 27 |
public abstract class Circuit extends Object { |
jtulach@52 | 28 |
|
jtulach@52 | 29 |
/** For your conveninece */ |
jtulach@52 | 30 |
public static Circuit AND = new Circuit() { |
jtulach@52 | 31 |
|
jtulach@52 | 32 |
@Override |
jtulach@52 | 33 |
public boolean evaluate(boolean[] in) { |
jtulach@52 | 34 |
if ( in.length != 2) { |
jtulach@154 | 35 |
throw new IllegalArgumentException( |
jtulach@154 | 36 |
"Should have two parameters" |
jtulach@154 | 37 |
); |
jtulach@52 | 38 |
} |
jtulach@52 | 39 |
return in[0] && in[1]; |
jtulach@52 | 40 |
} |
jtulach@52 | 41 |
|
jtulach@52 | 42 |
}; |
jtulach@52 | 43 |
|
jtulach@52 | 44 |
public static Circuit OR = new Circuit() { |
jtulach@52 | 45 |
|
jtulach@52 | 46 |
@Override |
jtulach@52 | 47 |
public boolean evaluate(boolean[] in) { |
jtulach@52 | 48 |
if ( in.length != 2) { |
jtulach@154 | 49 |
throw new IllegalArgumentException( |
jtulach@154 | 50 |
"Should have two parameters" |
jtulach@154 | 51 |
); |
jtulach@52 | 52 |
} |
jtulach@52 | 53 |
return in[0] || in[1]; |
jtulach@52 | 54 |
} |
jtulach@52 | 55 |
|
jtulach@52 | 56 |
}; |
jtulach@52 | 57 |
|
jtulach@52 | 58 |
public static Circuit NOT = new Circuit() { |
jtulach@52 | 59 |
|
jtulach@52 | 60 |
@Override |
jtulach@52 | 61 |
public boolean evaluate(boolean[] in) { |
jtulach@52 | 62 |
if ( in.length != 1) { |
jtulach@154 | 63 |
throw new IllegalArgumentException( |
jtulach@154 | 64 |
"Should have one parameter" |
jtulach@154 | 65 |
); |
jtulach@52 | 66 |
} |
jtulach@52 | 67 |
return !in[0]; |
jtulach@52 | 68 |
} |
jtulach@52 | 69 |
|
jtulach@52 | 70 |
}; |
jtulach@52 | 71 |
|
jtulach@52 | 72 |
|
jtulach@154 | 73 |
/** Feel free to implement and don't hesitate to throw |
jtulach@154 | 74 |
* IllegalArgumentEception |
jtulach@52 | 75 |
*/ |
jtulach@52 | 76 |
public abstract boolean evaluate(boolean... in); |
jtulach@52 | 77 |
|
jtulach@52 | 78 |
} |
jtulach@53 | 79 |
// END: apifest.day1.subclassingsolution |
jtulach@53 | 80 |
|
jtulach@53 | 81 |