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