samples/apifest1/day1/parsingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java
changeset 52 4257f4cf226b
child 132 3bc4c54f4bcc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/apifest1/day1/parsingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java	Sat Jun 14 09:52:45 2008 +0200
     1.3 @@ -0,0 +1,60 @@
     1.4 +/*
     1.5 + * The contents of this file are subject to the terms of the Common Development
     1.6 + * and Distribution License (the License). You may not use this file except in
     1.7 + * compliance with the License.
     1.8 + *
     1.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
    1.10 + * or http://www.netbeans.org/cddl.txt.
    1.11 + *
    1.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
    1.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
    1.14 + * If applicable, add the following below the CDDL Header, with the fields
    1.15 + * enclosed by brackets [] replaced by your own identifying information:
    1.16 + * "Portions Copyrighted [year] [name of copyright owner]"
    1.17 + *
    1.18 + * The Original Software is NetBeans. The Initial Developer of the Original
    1.19 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
    1.20 + * Microsystems, Inc. All Rights Reserved.
    1.21 + */
    1.22 +
    1.23 +package org.netbeans.apifest.boolcircuit;
    1.24 +
    1.25 +// BEGIN: apifest.day1.parsingsolution.Circuit
    1.26 +/**
    1.27 + * Usage:
    1.28 + * First method parse must be called with valid logical expression on input.
    1.29 + * If it returns zero then it is possible to call method evaluate with array
    1.30 + * of input values as parameter. Method evaluate can be invoked many time with
    1.31 + * different input values.
    1.32 + * Method parse can be called anytime to change logical expression.
    1.33 + */
    1.34 +public class Circuit {
    1.35 +    
    1.36 +    /** Parses logical expression
    1.37 +     * @param string representation of logical expression
    1.38 +     * Valid tokens:
    1.39 +     * Input values are represented by x and number starting from 1 eg.: x1
    1.40 +     * AND, NOT, OR and brackets '(',')' can be used.
    1.41 +     * Example of valid expression: x1 AND x2
    1.42 +     * @return 0 when input expression is validated and parsed. Return nonzero value otherwise.
    1.43 +     */
    1.44 +    public int parse(String expression) {
    1.45 +        return 0;
    1.46 +    }
    1.47 +    
    1.48 +    /** Evaluate logical expression
    1.49 +     * @param array of boolean input values. Size of array must correspond to number
    1.50 +     * of variables used in expression
    1.51 +     * If size of array is bigger then only first N values are used to evaluate expression.
    1.52 +     * Remaining values are ignored.
    1.53 +     * If size of array is smaller then IllegalArgumentException is thrown.
    1.54 +     * If no expression is set by method parse then IllegalStateException is thrown.
    1.55 +     */
    1.56 +    public boolean evaluate(boolean [] x) {
    1.57 +        return true;
    1.58 +        
    1.59 +    }
    1.60 +    
    1.61 +}
    1.62 +// END: apifest.day1.parsingsolution.Circuit
    1.63 +