samples/apifest1/day2/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     /**
    22      * @deprecated use for constants only.. use VariableInput instead..
    23      */
    24     public static Input createSimpleBooleanInput(boolean value) {
    25         return new BooleanInput(value);
    26     }
    27     
    28     public static VariableInput createVariableInput() {
    29         return new VariableInput();
    30     }
    31     /**
    32      * @throws IllegalArgument if the boolean operation was already used as input for another operation..
    33      * @deprecated
    34      */
    35     public static Input createOperationBasedBooleanInput(Operation op) throws IllegalArgumentException {
    36         assert op != null;
    37         if (op.isUsed()) {
    38             throw new IllegalArgumentException("Cannot use a single operation repeatedly.");
    39         }
    40         op.markOperationAsUsed();
    41         return new OperationInput(op);
    42     }
    43     
    44     /**
    45      * WTF, just make another reasonable sounding factory method now that we have reals..
    46      */
    47     
    48     public static Input createOperationBasedInput(Operation op) throws IllegalArgumentException {
    49         return createOperationBasedBooleanInput(op);
    50     }
    51     
    52     public static Operation createAndOperation(Input one, Input two) {
    53         assert one != null;
    54         assert two != null;
    55         return new AndOperation(one, two);
    56     }
    57     
    58     public static Operation createOrOperation(Input one, Input two) {
    59         assert one != null;
    60         assert two != null;
    61         return new OrOperation(one, two);
    62     }
    63     
    64     public static Operation createNotOperation(Input one) {
    65         assert one != null;
    66         return new NotOperation(one);
    67     }
    68     
    69     
    70 }