samples/apifest1/day1/parsingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:56:12 +0200
changeset 132 3bc4c54f4bcc
parent 52 4257f4cf226b
child 133 50bf1b976c0d
permissions -rw-r--r--
Truncating all examples to 80 characters per line
     1 /*
     2  * The contents of this file are subject to the terms of the Common Development
     3  * and Distribution License (the License). You may not use this file except in
     4  * compliance with the License.
     5  *
     6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
     7  * or http://www.netbeans.org/cddl.txt.
     8  *
     9  * When distributing Covered Code, include this CDDL Header Notice in each file
    10  * and include the License file at http://www.netbeans.org/cddl.txt.
    11  * If applicable, add the following below the CDDL Header, with the fields
    12  * enclosed by brackets [] replaced by your own identifying information:
    13  * "Portions Copyrighted [year] [name of copyright owner]"
    14  *
    15  * The Original Software is NetBeans. The Initial Developer of the Original
    16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
    17  * Microsystems, Inc. All Rights Reserved.
    18  */
    19 
    20 package org.netbeans.apifest.boolcircuit;
    21 
    22 // BEGIN: apifest.day1.parsingsolution.Circuit
    23 /**
    24  * Usage:
    25  * First method parse must be called with valid logical expression on input.
    26  * If it returns zero then it is possible to call method evaluate with array
    27  * of input values as parameter. Method evaluate can be invoked many time with
    28  * different input values.
    29  * Method parse can be called anytime to change logical expression.
    30  */
    31 public class Circuit {
    32     
    33     /** Parses logical expression
    34      * @param string representation of logical expression
    35      * Valid tokens:
    36      * Input values are represented by x and number starting from 1 eg.: x1
    37      * AND, NOT, OR and brackets '(',')' can be used.
    38      * Example of valid expression: x1 AND x2
    39      * @return 0 when input expression is validated and parsed. 
    40      * Return nonzero value otherwise.
    41      */
    42     public int parse(String expression) {
    43         return 0;
    44     }
    45     
    46     /** Evaluate logical expression
    47      * @param array of boolean input values. Size of array must
    48      * correspond to number of variables used in expression
    49      * If size of array is bigger then only first N values are used 
    50      * to evaluate expression. Remaining values are ignored.
    51      * If size of array is smaller then IllegalArgumentException is thrown.
    52      * If no expression is set by method parse then 
    53      * IllegalStateException is thrown.
    54      */
    55     public boolean evaluate(boolean [] x) {
    56         return true;
    57         
    58     }
    59     
    60 }
    61 // END: apifest.day1.parsingsolution.Circuit
    62