MtasFunctionParserItem.java

  1. package mtas.parser.function.util;

  2. import mtas.parser.function.ParseException;

  3. /**
  4.  * The Class MtasFunctionParserItem.
  5.  */
  6. public class MtasFunctionParserItem {

  7.   /** The type. */
  8.   private String type = null;

  9.   /** The id. */
  10.   private Integer id = null;

  11.   /** The value long. */
  12.   private Long valueLong = null;

  13.   /** The value double. */
  14.   private Double valueDouble = null;

  15.   /** The degree. */
  16.   private Integer degree = null;

  17.   /** The parser. */
  18.   private MtasFunctionParserFunction parser = null;

  19.   /** The Constant TYPE_CONSTANT_LONG. */
  20.   public static final String TYPE_CONSTANT_LONG = "constantLong";

  21.   /** The Constant TYPE_CONSTANT_DOUBLE. */
  22.   public static final String TYPE_CONSTANT_DOUBLE = "constantDouble";

  23.   /** The Constant TYPE_PARSER_LONG. */
  24.   public static final String TYPE_PARSER_LONG = "parserLong";

  25.   /** The Constant TYPE_PARSER_DOUBLE. */
  26.   public static final String TYPE_PARSER_DOUBLE = "parserDouble";

  27.   /** The Constant TYPE_ARGUMENT. */
  28.   public static final String TYPE_ARGUMENT = "argument";

  29.   /** The Constant TYPE_N. */
  30.   public static final String TYPE_N = "n";

  31.   /**
  32.    * Instantiates a new mtas function parser item.
  33.    *
  34.    * @param t the t
  35.    * @throws ParseException the parse exception
  36.    */
  37.   public MtasFunctionParserItem(String t) throws ParseException {
  38.     if (t.equals(TYPE_N)) {
  39.       type = t;
  40.       degree = 0;
  41.     } else {
  42.       throw new ParseException("unknown type " + t);
  43.     }
  44.   }

  45.   /**
  46.    * Instantiates a new mtas function parser item.
  47.    *
  48.    * @param t the t
  49.    * @param i the i
  50.    * @throws ParseException the parse exception
  51.    */
  52.   public MtasFunctionParserItem(String t, int i) throws ParseException {
  53.     if (t.equals(TYPE_ARGUMENT)) {
  54.       type = t;
  55.       id = i;
  56.       degree = 1;
  57.     } else {
  58.       throw new ParseException("unknown type " + t);
  59.     }
  60.   }

  61.   /**
  62.    * Instantiates a new mtas function parser item.
  63.    *
  64.    * @param t the t
  65.    * @param l the l
  66.    * @throws ParseException the parse exception
  67.    */
  68.   public MtasFunctionParserItem(String t, long l) throws ParseException {
  69.     if (t.equals(TYPE_CONSTANT_LONG)) {
  70.       type = t;
  71.       valueLong = l;
  72.       degree = 0;
  73.     } else {
  74.       throw new ParseException("unknown type " + t);
  75.     }
  76.   }

  77.   /**
  78.    * Instantiates a new mtas function parser item.
  79.    *
  80.    * @param t the t
  81.    * @param d the d
  82.    * @throws ParseException the parse exception
  83.    */
  84.   public MtasFunctionParserItem(String t, double d) throws ParseException {
  85.     if (t.equals(TYPE_CONSTANT_DOUBLE)) {
  86.       type = t;
  87.       valueDouble = d;
  88.       degree = 0;
  89.     } else {
  90.       throw new ParseException("unknown type " + t);
  91.     }
  92.   }

  93.   /**
  94.    * Instantiates a new mtas function parser item.
  95.    *
  96.    * @param t the t
  97.    * @param p the p
  98.    * @throws ParseException the parse exception
  99.    */
  100.   public MtasFunctionParserItem(String t, MtasFunctionParserFunction p)
  101.       throws ParseException {
  102.     if (t.equals(TYPE_PARSER_LONG)) {
  103.       type = t;
  104.       parser = p;
  105.       degree = parser.degree;
  106.     } else if (t.equals(TYPE_PARSER_DOUBLE)) {
  107.       type = t;
  108.       parser = p;
  109.       degree = parser.degree;
  110.     } else {
  111.       throw new ParseException("unknown type " + t);
  112.     }
  113.   }

  114.   /**
  115.    * Gets the type.
  116.    *
  117.    * @return the type
  118.    */
  119.   public String getType() {
  120.     return type;
  121.   }

  122.   /**
  123.    * Gets the id.
  124.    *
  125.    * @return the id
  126.    */
  127.   public int getId() {
  128.     return id.intValue();
  129.   }

  130.   /**
  131.    * Gets the degree.
  132.    *
  133.    * @return the degree
  134.    */
  135.   public Integer getDegree() {
  136.     return degree;
  137.   }

  138.   /**
  139.    * Gets the value long.
  140.    *
  141.    * @return the value long
  142.    */
  143.   public long getValueLong() {
  144.     return valueLong.longValue();
  145.   }

  146.   /**
  147.    * Gets the value double.
  148.    *
  149.    * @return the value double
  150.    */
  151.   public double getValueDouble() {
  152.     return valueDouble.doubleValue();
  153.   }

  154.   /**
  155.    * Gets the parser.
  156.    *
  157.    * @return the parser
  158.    */
  159.   public MtasFunctionParserFunction getParser() {
  160.     return parser;
  161.   }

  162. }