samples/apifest1/day1/parsingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:58:11 +0200
changeset 154 0fd5e9c500b9
parent 153 b5cbb797ec0a
permissions -rw-r--r--
Merge: Geertjan's changs up to 2000
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
// BEGIN: apifest.day1.parsingsolution.Circuit
jtulach@52
    23
/**
jtulach@52
    24
 * Usage:
jtulach@154
    25
 * First method parse must be called with valid logical expression on 
jtulach@154
    26
 * input.
jtulach@154
    27
 * If it returns zero then it is possible to call method evaluate with 
jtulach@154
    28
 * array of input values as parameter. Method evaluate can be invoked 
jtulach@154
    29
 * many time with different input values.
jtulach@52
    30
 * Method parse can be called anytime to change logical expression.
jtulach@52
    31
 */
jtulach@52
    32
public class Circuit {
jtulach@52
    33
    
jtulach@52
    34
    /** Parses logical expression
jtulach@52
    35
     * @param string representation of logical expression
jtulach@52
    36
     * Valid tokens:
jtulach@52
    37
     * Input values are represented by x and number starting from 1 eg.: x1
jtulach@52
    38
     * AND, NOT, OR and brackets '(',')' can be used.
jtulach@52
    39
     * Example of valid expression: x1 AND x2
jtulach@154
    40
     * @return 0 when input expression is validated and parsed. 
jtulach@154
    41
     * Return nonzero value otherwise.
jtulach@52
    42
     */
jtulach@52
    43
    public int parse(String expression) {
jtulach@52
    44
        return 0;
jtulach@52
    45
    }
jtulach@52
    46
    
jtulach@52
    47
    /** Evaluate logical expression
jtulach@154
    48
     * @param array of boolean input values. Size of array must
jtulach@154
    49
     * correspond to number of variables used in expression
jtulach@154
    50
     * If size of array is bigger then only first N values are used 
jtulach@154
    51
     * to evaluate expression. Remaining values are ignored.
jtulach@52
    52
     * If size of array is smaller then IllegalArgumentException is thrown.
jtulach@154
    53
     * If no expression is set by method parse then 
jtulach@154
    54
     * IllegalStateException is thrown.
jtulach@52
    55
     */
jtulach@52
    56
    public boolean evaluate(boolean [] x) {
jtulach@52
    57
        return true;
jtulach@52
    58
        
jtulach@52
    59
    }
jtulach@52
    60
    
jtulach@52
    61
}
jtulach@52
    62
// END: apifest.day1.parsingsolution.Circuit
jtulach@52
    63