FunctionParameter.java

  1. /**
  2.  * Copyright (c) 2014 European Organisation for Nuclear Research (CERN), All Rights Reserved.
  3.  */

  4. package cern.accsoft.steering.jmad.kernel.cmd.param;

  5. /**
  6.  * Gives the possibility to assign a function (by function name) with given function value like tgauss(1.2) or ranf(); <br>
  7.  * <br>
  8.  * NOTE: function value of null results into no values such that: {@literal tgauss(null) -> tgauss();}
  9.  *
  10.  * @author agorzaws
  11.  */
  12. public class FunctionParameter extends AbstractParameter {

  13.     private String name;
  14.     private String functionName;
  15.     private Double value;
  16.     private Double functionValue;

  17.     /**
  18.      * @param name name of the parameter
  19.      * @param functionName name of the function
  20.      * @param value value of the parameter
  21.      * @param functionValue value of the function (<b>null</b> if none)
  22.      */
  23.     public FunctionParameter(String name, String functionName, Double value, Double functionValue) {
  24.         super();
  25.         this.name = name;
  26.         this.functionName = functionName;
  27.         this.functionValue = functionValue;
  28.         this.value = value;
  29.     }

  30.     @Override
  31.     public String compose() {
  32.         if (value != null) {
  33.             String functionCall = functionName + "(" + (functionValue == null ? "" : functionValue.doubleValue()) + ")";
  34.             return name + ":=" + functionCall + "*" + value;
  35.         }
  36.         return "";
  37.     }

  38.     @Override
  39.     public boolean isSet() {
  40.         return (value != null);
  41.     }

  42. }