Package ket.math

Source Code of ket.math.SymbolicFunctionBuilder

/*
* Copyright (C) 2011  Alasdair C. Hamilton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>
*/

package ket.math;

import java.awt.*; // Why?
import java.util.*;

import ket.display.*;
import ket.display.box.Box;
import ket.display.box.BoxWord;
import ket.display.box.BoxTools;
import ket.math.purpose.function.*;
import ket.math.purpose.SymbolicState;
import ket.math.purpose.symbolicFunctions.*;
import ketUI.Ket;

/**
* This is an example of the builder design pattern for SymbolicFunction.  It
* is in Function.java because this is where constants are defined.
*/
public class SymbolicFunctionBuilder {
  final String name;
  final int[] numberOfChildren;
  final int precedence;
  SymbolicState prefix; 
  SymbolicState infix; 
  SymbolicState postfix; 
  boolean hasBranckets;
  SymbolicFunctionForm form;

  public SymbolicFunctionBuilder(String name, int[] numberOfChildren, int precedence) {
    this.name = name;
    this.numberOfChildren = numberOfChildren;
    this.precedence = precedence;
    SymbolicState prefix = null
    SymbolicState infix = null;
    SymbolicState postfix = null;
    boolean hasBranckets = false; // <--- This is only used for '?'; it could generalize, but may be simpler to remove for now.
    form = null; // Ensure this is not null before use.
  }
  public SymbolicFunctionBuilder setPrefix(SymbolicState prefix) {
    this.prefix = prefix;
    return this;
  }
  public SymbolicFunctionBuilder setInfix(SymbolicState infix) {
    this.infix = infix;
    return this;
  }
  public SymbolicFunctionBuilder setPostfix(SymbolicState postfix) {
    this.postfix = postfix;
    return this;
  }
  public SymbolicFunctionBuilder setShowBrackets() {
    this.hasBranckets = true;
    return this;
  }
  public SymbolicFunctionBuilder setForm(SymbolicFunctionForm form) {
    this.form = form;
    return this;
  }
  public SymbolicFunction build() {
    if (prefix==null && infix==null && postfix==null) {
      Ket.out.println(" !!! Invalid function: no prefix, infix or postfix specified !!! ");
      return null;
    }
    return new SymbolicFunction(name, numberOfChildren, precedence, prefix, infix, postfix, hasBranckets, form);
  }
}
TOP

Related Classes of ket.math.SymbolicFunctionBuilder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.