samples/apifest1/day1/inputandoperation/src/org/netbeans/apifest/boolcircuit/Factory.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:52:45 +0200
changeset 52 4257f4cf226b
permissions -rw-r--r--
Adding samples from API fest to the repository, including pieces of their code in the document, not just links
     1 /*
     2  * Factory.java
     3  *
     4  * Created on July 12, 2006, 2:21 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 /**
    13  *
    14  */
    15 public class Factory {
    16     
    17     /** Creates a new instance of Factory */
    18     private Factory() {
    19     }
    20     
    21     public static Input createSimpleBooleanInput(boolean value) {
    22         return new BooleanInput(value);
    23     }
    24     
    25     /**
    26      * @throws IllegalArgument if the boolean operation was already used as input for another operation..
    27      */
    28     public static Input createOperationBasedBooleanInput(Operation op) throws IllegalArgumentException {
    29         assert op != null;
    30         if (op.isUsed()) {
    31             throw new IllegalArgumentException("Cannot use a single operation repeatedly.");
    32         }
    33         op.markOperationAsUsed();
    34         return new OperationInput(op);
    35     }
    36     
    37     public static Operation createAndOperation(Input one, Input two) {
    38         assert one != null;
    39         assert two != null;
    40         return new AndOperation(one, two);
    41     }
    42     
    43     public static Operation createOrOperation(Input one, Input two) {
    44         assert one != null;
    45         assert two != null;
    46         return new OrOperation(one, two);
    47     }
    48     
    49     public static Operation createNotOperation(Input one) {
    50         assert one != null;
    51         return new NotOperation(one);
    52     }
    53     
    54     
    55 }