<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasFunctionParserFunctionBasic.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.parser.function.util</a> > <span class="el_source">MtasFunctionParserFunctionBasic.java</span></div><h1>MtasFunctionParserFunctionBasic.java</h1><pre class="source lang-java linenums">package mtas.parser.function.util; import java.io.IOException; import java.util.ArrayList; import mtas.codec.util.CodecUtil; import mtas.parser.function.ParseException; /** * The Class MtasFunctionParserFunctionBasic. */ public class MtasFunctionParserFunctionBasic extends MtasFunctionParserFunction { /** The first type. */ private String firstType; /** The first id. */ private int firstId; /** The tmp parser longs. */ <span class="fc" id="L22"> private ArrayList<MtasFunctionParserFunction> tmpParserLongs = new ArrayList<>();</span> /** The tmp parser doubles. */ <span class="fc" id="L25"> private ArrayList<MtasFunctionParserFunction> tmpParserDoubles = new ArrayList<>();</span> /** The tmp constant longs. */ <span class="fc" id="L28"> private ArrayList<Long> tmpConstantLongs = new ArrayList<>();</span> /** The tmp constant doubles. */ <span class="fc" id="L31"> private ArrayList<Double> tmpConstantDoubles = new ArrayList<>();</span> /** The number. */ private int number; /** The operator list. */ private String[] operatorList; /** The type list. */ private String[] typeList; /** The id list. */ private int[] idList; /** The tmp operator list. */ <span class="fc" id="L46"> private ArrayList<String> tmpOperatorList = new ArrayList<>();</span> /** The tmp type list. */ <span class="fc" id="L49"> private ArrayList<String> tmpTypeList = new ArrayList<>();</span> /** The tmp id list. */ <span class="fc" id="L52"> private ArrayList<Integer> tmpIdList = new ArrayList<>();</span> /** The Constant BASIC_OPERATOR_ADD. */ public static final String BASIC_OPERATOR_ADD = "add"; /** The Constant BASIC_OPERATOR_SUBTRACT. */ public static final String BASIC_OPERATOR_SUBTRACT = "subtract"; /** The Constant BASIC_OPERATOR_MULTIPLY. */ public static final String BASIC_OPERATOR_MULTIPLY = "multiply"; /** The Constant BASIC_OPERATOR_DIVIDE. */ public static final String BASIC_OPERATOR_DIVIDE = "divide"; /** The Constant BASIC_OPERATOR_POWER. */ public static final String BASIC_OPERATOR_POWER = "power"; /** * Instantiates a new mtas function parser function basic. * * @param item the item * @throws ParseException the parse exception */ public MtasFunctionParserFunctionBasic(MtasFunctionParserItem item) <span class="fc" id="L76"> throws ParseException {</span> <span class="fc" id="L77"> sumRule = true;</span> <span class="fc" id="L78"> String type = item.getType();</span> MtasFunctionParserFunction parser; <span class="fc" id="L80"> firstType = type;</span> <span class="fc" id="L81"> degree = item.getDegree();</span> <span class="pc bpc" id="L82" title="14 of 26 branches missed."> switch (type) {</span> case MtasFunctionParserItem.TYPE_N: <span class="fc" id="L84"> firstId = 0;</span> <span class="fc" id="L85"> dataType = CodecUtil.DATA_TYPE_LONG;</span> <span class="fc" id="L86"> needPositions = true;</span> <span class="fc" id="L87"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="fc" id="L89"> firstId = tmpConstantLongs.size();</span> <span class="fc" id="L90"> dataType = CodecUtil.DATA_TYPE_LONG;</span> <span class="fc" id="L91"> tmpConstantLongs.add(item.getValueLong());</span> <span class="fc" id="L92"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L94"> firstId = tmpConstantDoubles.size();</span> <span class="nc" id="L95"> dataType = CodecUtil.DATA_TYPE_DOUBLE;</span> <span class="nc" id="L96"> tmpConstantDoubles.add(item.getValueDouble());</span> <span class="nc" id="L97"> break;</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="fc" id="L99"> firstType = type;</span> <span class="fc" id="L100"> firstId = item.getId();</span> <span class="fc" id="L101"> dataType = CodecUtil.DATA_TYPE_LONG;</span> <span class="fc" id="L102"> needArgument.add(item.getId());</span> <span class="fc" id="L103"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="fc" id="L105"> parser = item.getParser();</span> <span class="fc" id="L106"> parser.close();</span> <span class="pc bpc" id="L107" title="1 of 2 branches missed."> if (parser.getType().equals(CodecUtil.DATA_TYPE_LONG)) {</span> <span class="fc" id="L108"> firstId = tmpParserLongs.size();</span> <span class="fc" id="L109"> tmpParserLongs.add(parser);</span> <span class="fc" id="L110"> sumRule = parser.sumRule();</span> <span class="fc" id="L111"> dataType = CodecUtil.DATA_TYPE_LONG;</span> <span class="pc bpc" id="L112" title="1 of 2 branches missed."> needPositions = needPositions ? needPositions : parser.needPositions();</span> <span class="fc" id="L113"> needArgument.addAll(parser.needArgument);</span> } else { <span class="nc" id="L115"> throw new ParseException("incorrect dataType");</span> } break; case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L119"> parser = item.getParser();</span> <span class="nc" id="L120"> parser.close();</span> <span class="nc bnc" id="L121" title="All 2 branches missed."> if (parser.getType().equals(CodecUtil.DATA_TYPE_DOUBLE)) {</span> <span class="nc" id="L122"> firstId = tmpParserDoubles.size();</span> <span class="nc" id="L123"> tmpParserDoubles.add(parser);</span> <span class="nc" id="L124"> sumRule = parser.sumRule();</span> <span class="nc" id="L125"> dataType = CodecUtil.DATA_TYPE_DOUBLE;</span> <span class="nc bnc" id="L126" title="All 2 branches missed."> needPositions = needPositions ? needPositions : parser.needPositions();</span> <span class="nc" id="L127"> needArgument.addAll(parser.needArgument);</span> } else { <span class="nc" id="L129"> throw new ParseException("incorrect dataType");</span> } break; default: <span class="nc" id="L133"> throw new ParseException("unknown type");</span> } <span class="fc" id="L135"> }</span> /* * (non-Javadoc) * * @see mtas.parser.function.util.MtasFunctionParserFunction#close() */ @Override public void close() throws ParseException { <span class="pc bpc" id="L144" title="1 of 2 branches missed."> if (!defined()) {</span> <span class="fc" id="L145"> super.close();</span> <span class="fc bfc" id="L146" title="All 2 branches covered."> if (!tmpParserLongs.isEmpty()) {</span> <span class="fc" id="L147"> parserLongs = new MtasFunctionParserFunction[tmpParserLongs.size()];</span> <span class="fc" id="L148"> parserLongs = tmpParserLongs.toArray(parserLongs);</span> } <span class="fc bfc" id="L150" title="All 2 branches covered."> if (!tmpParserDoubles.isEmpty()) {</span> <span class="fc" id="L151"> parserDoubles = new MtasFunctionParserFunction[tmpParserDoubles.size()];</span> <span class="fc" id="L152"> parserDoubles = tmpParserDoubles.toArray(parserDoubles);</span> } <span class="fc bfc" id="L154" title="All 2 branches covered."> if (!tmpConstantLongs.isEmpty()) {</span> <span class="fc" id="L155"> constantLongs = new long[tmpConstantLongs.size()];</span> <span class="fc bfc" id="L156" title="All 2 branches covered."> for (int i = 0; i < tmpConstantLongs.size(); i++) {</span> <span class="fc" id="L157"> constantLongs[i] = tmpConstantLongs.get(i);</span> } } <span class="fc bfc" id="L160" title="All 2 branches covered."> if (!tmpConstantDoubles.isEmpty()) {</span> <span class="fc" id="L161"> constantDoubles = new Double[tmpConstantDoubles.size()];</span> <span class="fc bfc" id="L162" title="All 2 branches covered."> for (int i = 0; i < tmpConstantDoubles.size(); i++) {</span> <span class="fc" id="L163"> constantDoubles[i] = tmpConstantDoubles.get(i);</span> } } <span class="pc bpc" id="L166" title="1 of 2 branches missed."> if (firstType == null) {</span> <span class="nc" id="L167"> throw new ParseException("incorrect definition: no firstType");</span> } <span class="fc bfc" id="L169" title="All 2 branches covered."> if (!tmpOperatorList.isEmpty()) {</span> <span class="fc" id="L170"> number = tmpOperatorList.size();</span> <span class="pc bpc" id="L171" title="2 of 4 branches missed."> if ((tmpTypeList.size() != number) || (tmpIdList.size() != number)) {</span> <span class="nc" id="L172"> throw new ParseException("incorrect definition additional items");</span> } else { <span class="fc" id="L174"> operatorList = new String[number];</span> <span class="fc" id="L175"> operatorList = tmpOperatorList.toArray(operatorList);</span> <span class="fc" id="L176"> typeList = new String[number];</span> <span class="fc" id="L177"> typeList = tmpTypeList.toArray(typeList);</span> <span class="fc" id="L178"> idList = new int[number];</span> <span class="fc bfc" id="L179" title="All 2 branches covered."> for (int i = 0; i < number; i++) {</span> <span class="fc" id="L180"> idList[i] = tmpIdList.get(i).intValue();</span> } } } else { <span class="fc" id="L184"> number = 0;</span> <span class="fc" id="L185"> operatorList = null;</span> <span class="fc" id="L186"> typeList = null;</span> <span class="fc" id="L187"> idList = null;</span> } } <span class="fc" id="L190"> }</span> /** * Adds the. * * @param item the item * @throws ParseException the parse exception */ public void add(MtasFunctionParserItem item) throws ParseException { <span class="fc" id="L199"> basic(BASIC_OPERATOR_ADD, item);</span> <span class="fc" id="L200"> }</span> /** * Subtract. * * @param item the item * @throws ParseException the parse exception */ public void subtract(MtasFunctionParserItem item) throws ParseException { <span class="fc" id="L209"> basic(BASIC_OPERATOR_SUBTRACT, item);</span> <span class="fc" id="L210"> }</span> /** * Multiply. * * @param item the item * @throws ParseException the parse exception */ public void multiply(MtasFunctionParserItem item) throws ParseException { <span class="fc" id="L219"> basic(BASIC_OPERATOR_MULTIPLY, item);</span> <span class="fc" id="L220"> }</span> /** * Divide. * * @param item the item * @throws ParseException the parse exception */ public void divide(MtasFunctionParserItem item) throws ParseException { <span class="fc" id="L229"> basic(BASIC_OPERATOR_DIVIDE, item);</span> <span class="fc" id="L230"> }</span> /** * Power. * * @param item the item * @throws ParseException the parse exception */ public void power(MtasFunctionParserItem item) throws ParseException { <span class="fc" id="L239"> basic(BASIC_OPERATOR_POWER, item);</span> <span class="fc" id="L240"> }</span> /** * Basic. * * @param operator the operator * @param item the item * @throws ParseException the parse exception */ private void basic(String operator, MtasFunctionParserItem item) throws ParseException { <span class="pc bpc" id="L251" title="1 of 2 branches missed."> if (!defined()) {</span> <span class="fc" id="L252"> String type = item.getType();</span> MtasFunctionParserFunction parser; <span class="fc" id="L254"> tmpOperatorList.add(operator);</span> <span class="fc bfc" id="L255" title="All 2 branches covered."> if (operator.equals(BASIC_OPERATOR_DIVIDE)) {</span> <span class="fc" id="L256"> dataType = CodecUtil.DATA_TYPE_DOUBLE;</span> } <span class="pc bpc" id="L258" title="8 of 26 branches missed."> switch (type) {</span> case MtasFunctionParserItem.TYPE_N: <span class="fc" id="L260"> tmpTypeList.add(type);</span> <span class="fc" id="L261"> tmpIdList.add(0);</span> <span class="fc" id="L262"> needPositions = true;</span> <span class="pc bpc" id="L263" title="1 of 4 branches missed."> if (sumRule && degree != null) {</span> <span class="fc bfc" id="L264" title="All 2 branches covered."> if (operator.equals(BASIC_OPERATOR_ADD)</span> <span class="fc bfc" id="L265" title="All 2 branches covered."> || operator.equals(BASIC_OPERATOR_SUBTRACT)) {</span> <span class="pc bpc" id="L266" title="1 of 2 branches missed."> if (degree < 0) {</span> <span class="nc" id="L267"> sumRule = false;</span> <span class="nc" id="L268"> degree = null;</span> <span class="pc bpc" id="L269" title="1 of 2 branches missed."> } else if (degree > 0) {</span> <span class="fc" id="L270"> sumRule = false;</span> } <span class="pc bpc" id="L272" title="3 of 4 branches missed."> } else if (operator.equals(BASIC_OPERATOR_POWER) && (degree != 0)) {</span> <span class="nc" id="L273"> sumRule = false;</span> <span class="nc" id="L274"> degree = null;</span> } } break; case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="fc" id="L279"> tmpTypeList.add(type);</span> <span class="fc" id="L280"> tmpIdList.add(item.getId());</span> <span class="fc" id="L281"> needArgument.add(item.getId());</span> <span class="pc bpc" id="L282" title="1 of 4 branches missed."> if (sumRule && degree != null) {</span> <span class="fc bfc" id="L283" title="All 2 branches covered."> if (operator.equals(BASIC_OPERATOR_ADD)</span> <span class="fc bfc" id="L284" title="All 2 branches covered."> || operator.equals(BASIC_OPERATOR_SUBTRACT)) {</span> <span class="fc bfc" id="L285" title="All 2 branches covered."> if (degree != 1) {</span> <span class="fc" id="L286"> sumRule = false;</span> } <span class="pc bpc" id="L288" title="1 of 2 branches missed."> if (degree >= 0) {</span> <span class="fc" id="L289"> degree = Math.max(degree, 1);</span> } else { <span class="nc" id="L291"> degree = null;</span> } <span class="fc bfc" id="L293" title="All 2 branches covered."> } else if (operator.equals(BASIC_OPERATOR_MULTIPLY)) {</span> <span class="fc bfc" id="L294" title="All 2 branches covered."> if (degree != 0) {</span> <span class="fc" id="L295"> sumRule = false;</span> } <span class="fc" id="L297"> degree += 1;</span> <span class="fc bfc" id="L298" title="All 2 branches covered."> } else if (operator.equals(BASIC_OPERATOR_DIVIDE)) {</span> <span class="fc" id="L299"> sumRule = false;</span> <span class="fc" id="L300"> degree -= 1;</span> <span class="pc bpc" id="L301" title="1 of 2 branches missed."> } else if (operator.equals(BASIC_OPERATOR_POWER)) {</span> <span class="fc" id="L302"> sumRule = false;</span> <span class="fc" id="L303"> degree = null;</span> } } break; case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="fc" id="L308"> tmpTypeList.add(type);</span> <span class="fc" id="L309"> tmpIdList.add(tmpConstantLongs.size());</span> <span class="fc" id="L310"> tmpConstantLongs.add(item.getValueLong());</span> <span class="pc bpc" id="L311" title="1 of 4 branches missed."> if (sumRule && degree != null) {</span> <span class="pc bpc" id="L312" title="1 of 2 branches missed."> if (operator.equals(BASIC_OPERATOR_ADD)</span> <span class="nc bnc" id="L313" title="All 2 branches missed."> || operator.equals(BASIC_OPERATOR_SUBTRACT)) {</span> <span class="pc bpc" id="L314" title="1 of 2 branches missed."> if (degree < 0) {</span> <span class="nc" id="L315"> sumRule = false;</span> <span class="nc" id="L316"> degree = null;</span> <span class="fc bfc" id="L317" title="All 2 branches covered."> } else if (degree > 0) {</span> <span class="fc" id="L318"> sumRule = false;</span> } <span class="nc bnc" id="L320" title="All 4 branches missed."> } else if (operator.equals(BASIC_OPERATOR_POWER) && (degree != 0)) {</span> <span class="nc" id="L321"> sumRule = false;</span> <span class="nc" id="L322"> degree = null;</span> } } break; case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="fc" id="L327"> tmpTypeList.add(type);</span> <span class="fc" id="L328"> tmpIdList.add(tmpConstantDoubles.size());</span> <span class="fc" id="L329"> dataType = CodecUtil.DATA_TYPE_DOUBLE;</span> <span class="fc" id="L330"> tmpConstantDoubles.add(item.getValueDouble());</span> <span class="pc bpc" id="L331" title="2 of 4 branches missed."> if (sumRule && degree != null) {</span> <span class="pc bpc" id="L332" title="1 of 2 branches missed."> if (operator.equals(BASIC_OPERATOR_ADD)</span> <span class="nc bnc" id="L333" title="All 2 branches missed."> || operator.equals(BASIC_OPERATOR_SUBTRACT)) {</span> <span class="pc bpc" id="L334" title="1 of 2 branches missed."> if (degree < 0) {</span> <span class="nc" id="L335"> sumRule = false;</span> <span class="nc" id="L336"> degree = null;</span> <span class="pc bpc" id="L337" title="1 of 2 branches missed."> } else if (degree > 0) {</span> <span class="nc" id="L338"> sumRule = false;</span> } <span class="nc bnc" id="L340" title="All 4 branches missed."> } else if (operator.equals(BASIC_OPERATOR_POWER) && (degree != 0)) {</span> <span class="nc" id="L341"> sumRule = false;</span> <span class="nc" id="L342"> degree = null;</span> } } break; case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="fc" id="L347"> tmpTypeList.add(type);</span> <span class="fc" id="L348"> tmpIdList.add(tmpParserLongs.size());</span> <span class="fc" id="L349"> parser = item.getParser();</span> <span class="fc" id="L350"> parser.close();</span> <span class="fc" id="L351"> tmpParserLongs.add(parser);</span> <span class="pc bpc" id="L352" title="1 of 2 branches missed."> sumRule = sumRule ? parser.sumRule() : false;</span> <span class="fc bfc" id="L353" title="All 2 branches covered."> needPositions = needPositions ? needPositions : parser.needPositions();</span> <span class="fc" id="L354"> needArgument.addAll(parser.needArgument);</span> <span class="pc bpc" id="L355" title="1 of 4 branches missed."> if (sumRule && degree != null) {</span> <span class="pc bpc" id="L356" title="1 of 2 branches missed."> if (operator.equals(BASIC_OPERATOR_ADD)</span> <span class="pc bpc" id="L357" title="1 of 2 branches missed."> || operator.equals(BASIC_OPERATOR_SUBTRACT)) {</span> <span class="nc bnc" id="L358" title="All 2 branches missed."> if (!parser.degree.equals(degree)) {</span> <span class="nc" id="L359"> sumRule = false;</span> <span class="nc bnc" id="L360" title="All 2 branches missed."> if (degree < 0) {</span> <span class="nc" id="L361"> degree = null;</span> } else { <span class="nc" id="L363"> degree = Math.max(degree, parser.degree);</span> } } <span class="fc bfc" id="L366" title="All 2 branches covered."> } else if (operator.equals(BASIC_OPERATOR_MULTIPLY)) {</span> <span class="pc bpc" id="L367" title="2 of 4 branches missed."> if (degree != 0 || parser.degree != 0) {</span> <span class="fc" id="L368"> sumRule = false;</span> } <span class="fc" id="L370"> degree += parser.degree;</span> <span class="pc bpc" id="L371" title="3 of 4 branches missed."> } else if (operator.equals(BASIC_OPERATOR_POWER) && (degree != 0)) {</span> <span class="nc" id="L372"> sumRule = false;</span> <span class="nc" id="L373"> degree = null;</span> } } break; case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="fc" id="L378"> tmpTypeList.add(type);</span> <span class="fc" id="L379"> tmpIdList.add(tmpParserDoubles.size());</span> <span class="fc" id="L380"> dataType = CodecUtil.DATA_TYPE_DOUBLE;</span> <span class="fc" id="L381"> parser = item.getParser();</span> <span class="fc" id="L382"> parser.close();</span> <span class="fc" id="L383"> tmpParserDoubles.add(parser);</span> <span class="pc bpc" id="L384" title="1 of 2 branches missed."> sumRule = sumRule ? parser.sumRule() : false;</span> <span class="pc bpc" id="L385" title="1 of 2 branches missed."> needPositions = needPositions ? needPositions : parser.needPositions();</span> <span class="fc" id="L386"> needArgument.addAll(parser.needArgument);</span> <span class="pc bpc" id="L387" title="2 of 4 branches missed."> if (sumRule && degree != null) {</span> <span class="pc bpc" id="L388" title="1 of 2 branches missed."> if (operator.equals(BASIC_OPERATOR_ADD)</span> <span class="nc bnc" id="L389" title="All 2 branches missed."> || operator.equals(BASIC_OPERATOR_SUBTRACT)) {</span> <span class="pc bpc" id="L390" title="1 of 2 branches missed."> if (!parser.degree.equals(degree)) {</span> <span class="fc" id="L391"> sumRule = false;</span> <span class="pc bpc" id="L392" title="1 of 2 branches missed."> if (degree < 0) {</span> <span class="nc" id="L393"> degree = null;</span> } else { <span class="fc" id="L395"> degree = Math.max(degree, parser.degree);</span> } } <span class="nc bnc" id="L398" title="All 2 branches missed."> } else if (operator.equals(BASIC_OPERATOR_MULTIPLY)) {</span> <span class="nc bnc" id="L399" title="All 4 branches missed."> if (degree != 0 || parser.degree != 0) {</span> <span class="nc" id="L400"> sumRule = false;</span> } <span class="nc" id="L402"> degree += parser.degree;</span> <span class="nc bnc" id="L403" title="All 4 branches missed."> } else if (operator.equals(BASIC_OPERATOR_POWER) && (degree != 0)) {</span> <span class="nc" id="L404"> sumRule = false;</span> <span class="nc" id="L405"> degree = null;</span> } } break; default: <span class="nc" id="L410"> throw new ParseException("incorrect type");</span> } <span class="fc" id="L412"> } else {</span> <span class="nc" id="L413"> throw new ParseException("already defined");</span> } <span class="fc" id="L415"> }</span> /* * (non-Javadoc) * * @see * mtas.parser.function.util.MtasFunctionParserFunction#getValueDouble(long[], * long) */ @Override public double getValueDouble(long[] args, long n) throws IOException { double sum; <span class="pc bpc" id="L427" title="17 of 26 branches missed."> switch (firstType) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="nc" id="L429"> sum = args[firstId];</span> <span class="nc" id="L430"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L432"> sum = parserDoubles[firstId].getValueDouble(args, n);</span> <span class="nc" id="L433"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="fc" id="L435"> sum = parserLongs[firstId].getValueLong(args, n);</span> <span class="fc" id="L436"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L438"> sum = constantDoubles[firstId];</span> <span class="nc" id="L439"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="fc" id="L441"> sum = constantLongs[firstId];</span> <span class="fc" id="L442"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="fc" id="L444"> sum = n;</span> <span class="fc" id="L445"> break;</span> default: <span class="nc" id="L447"> throw new IOException("no first value");</span> } <span class="fc bfc" id="L449" title="All 2 branches covered."> for (int i = 0; i < number; i++) {</span> <span class="pc bpc" id="L450" title="10 of 22 branches missed."> switch (operatorList[i]) {</span> case BASIC_OPERATOR_ADD: <span class="pc bpc" id="L452" title="11 of 26 branches missed."> switch (typeList[i]) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="fc" id="L454"> sum += args[idList[i]];</span> <span class="fc" id="L455"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="fc" id="L457"> sum += parserDoubles[idList[i]].getValueDouble(args, n);</span> <span class="fc" id="L458"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="nc" id="L460"> sum += parserLongs[idList[i]].getValueLong(args, n);</span> <span class="nc" id="L461"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="fc" id="L463"> sum += constantDoubles[idList[i]];</span> <span class="fc" id="L464"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="fc" id="L466"> sum += constantLongs[idList[i]];</span> <span class="fc" id="L467"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="fc" id="L469"> sum += n;</span> <span class="fc" id="L470"> break;</span> default: <span class="nc" id="L472"> throw new IOException("unknown type");</span> } <span class="fc" id="L474"> break;</span> case BASIC_OPERATOR_SUBTRACT: <span class="pc bpc" id="L476" title="20 of 26 branches missed."> switch (typeList[i]) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="fc" id="L478"> sum -= args[idList[i]];</span> <span class="fc" id="L479"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L481"> sum -= parserDoubles[idList[i]].getValueDouble(args, n);</span> <span class="nc" id="L482"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="nc" id="L484"> sum -= parserLongs[idList[i]].getValueLong(args, n);</span> <span class="nc" id="L485"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L487"> sum -= constantDoubles[idList[i]];</span> <span class="nc" id="L488"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="nc" id="L490"> sum -= constantLongs[idList[i]];</span> <span class="nc" id="L491"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="fc" id="L493"> sum -= n;</span> <span class="fc" id="L494"> break;</span> default: <span class="nc" id="L496"> throw new IOException("unknown type");</span> } <span class="fc" id="L498"> break;</span> case BASIC_OPERATOR_MULTIPLY: <span class="pc bpc" id="L500" title="17 of 26 branches missed."> switch (typeList[i]) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="fc" id="L502"> sum *= args[idList[i]];</span> <span class="fc" id="L503"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L505"> sum *= parserDoubles[idList[i]].getValueDouble(args, n);</span> <span class="nc" id="L506"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="fc" id="L508"> sum *= parserLongs[idList[i]].getValueLong(args, n);</span> <span class="fc" id="L509"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L511"> sum *= constantDoubles[idList[i]];</span> <span class="nc" id="L512"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="nc" id="L514"> sum *= constantLongs[idList[i]];</span> <span class="nc" id="L515"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="fc" id="L517"> sum *= n;</span> <span class="fc" id="L518"> break;</span> default: <span class="nc" id="L520"> throw new IOException("unknown type");</span> } <span class="fc" id="L522"> break;</span> case BASIC_OPERATOR_DIVIDE: double v; <span class="pc bpc" id="L525" title="17 of 26 branches missed."> switch (typeList[i]) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="fc" id="L527"> v = args[idList[i]];</span> <span class="fc" id="L528"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L530"> v = parserDoubles[idList[i]].getValueDouble(args, n);</span> <span class="nc" id="L531"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="fc" id="L533"> v = parserLongs[idList[i]].getValueLong(args, n);</span> <span class="fc" id="L534"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L536"> v = constantDoubles[idList[i]];</span> <span class="nc" id="L537"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="nc" id="L539"> v = constantLongs[idList[i]];</span> <span class="nc" id="L540"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="fc" id="L542"> v = n;</span> <span class="fc" id="L543"> break;</span> default: <span class="nc" id="L545"> throw new IOException("unknown type");</span> } <span class="fc bfc" id="L547" title="All 2 branches covered."> if (v != 0) {</span> <span class="fc" id="L548"> sum /= v;</span> } else { <span class="fc" id="L550"> throw new IOException("division by zero");</span> } break; case BASIC_OPERATOR_POWER: <span class="nc bnc" id="L554" title="All 26 branches missed."> switch (typeList[i]) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="nc" id="L556"> sum = Math.pow(sum, args[idList[i]]);</span> <span class="nc" id="L557"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L559"> sum = Math.pow(sum, parserDoubles[idList[i]].getValueDouble(args, n));</span> <span class="nc" id="L560"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="nc" id="L562"> sum = Math.pow(sum, parserLongs[idList[i]].getValueLong(args, n));</span> <span class="nc" id="L563"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L565"> sum = Math.pow(sum, constantDoubles[idList[i]]);</span> <span class="nc" id="L566"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="nc" id="L568"> sum = Math.pow(sum, constantLongs[idList[i]]);</span> <span class="nc" id="L569"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="nc" id="L571"> sum = Math.pow(sum, n);</span> <span class="nc" id="L572"> break;</span> default: <span class="nc" id="L574"> throw new IOException("unknown type");</span> } <span class="nc" id="L576"> break;</span> default: <span class="nc" id="L578"> throw new IOException("unknown operator");</span> } } <span class="fc" id="L581"> return sum;</span> } /* * (non-Javadoc) * * @see * mtas.parser.function.util.MtasFunctionParserFunction#getValueLong(long[], * long) */ @Override public long getValueLong(long[] args, long n) throws IOException { try { long sum; <span class="pc bpc" id="L595" title="17 of 26 branches missed."> switch (firstType) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="fc" id="L597"> sum = args[firstId];</span> <span class="fc" id="L598"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L600"> sum = (long) parserDoubles[firstId].getValueDouble(args, n);</span> <span class="nc" id="L601"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="nc" id="L603"> sum = parserLongs[firstId].getValueLong(args, n);</span> <span class="nc" id="L604"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L606"> sum = constantDoubles[firstId].longValue();</span> <span class="nc" id="L607"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="fc" id="L609"> sum = constantLongs[firstId];</span> <span class="fc" id="L610"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="fc" id="L612"> sum = n;</span> <span class="fc" id="L613"> break;</span> default: <span class="nc" id="L615"> throw new IOException("no first value");</span> } <span class="fc bfc" id="L617" title="All 2 branches covered."> for (int i = 0; i < number; i++) {</span> <span class="pc bpc" id="L618" title="10 of 22 branches missed."> switch (operatorList[i]) {</span> case BASIC_OPERATOR_ADD: <span class="pc bpc" id="L620" title="20 of 26 branches missed."> switch (typeList[i]) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="fc" id="L622"> sum += args[idList[i]];</span> <span class="fc" id="L623"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L625"> sum += (long) parserDoubles[idList[i]].getValueDouble(args, n);</span> <span class="nc" id="L626"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="nc" id="L628"> sum += parserLongs[idList[i]].getValueLong(args, n);</span> <span class="nc" id="L629"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L631"> sum += constantDoubles[idList[i]].longValue();</span> <span class="nc" id="L632"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="nc" id="L634"> sum += constantLongs[idList[i]];</span> <span class="nc" id="L635"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="fc" id="L637"> sum += n;</span> <span class="fc" id="L638"> break;</span> default: <span class="nc" id="L640"> throw new IOException("unknown type");</span> } <span class="fc" id="L642"> break;</span> case BASIC_OPERATOR_SUBTRACT: <span class="pc bpc" id="L644" title="20 of 26 branches missed."> switch (typeList[i]) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="fc" id="L646"> sum -= args[idList[i]];</span> <span class="fc" id="L647"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L649"> sum -= (long) parserDoubles[idList[i]].getValueDouble(args, n);</span> <span class="nc" id="L650"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="nc" id="L652"> sum -= parserLongs[idList[i]].getValueLong(args, n);</span> <span class="nc" id="L653"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L655"> sum -= constantDoubles[idList[i]].longValue();</span> <span class="nc" id="L656"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="nc" id="L658"> sum -= constantLongs[idList[i]];</span> <span class="nc" id="L659"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="fc" id="L661"> sum -= n;</span> <span class="fc" id="L662"> break;</span> default: <span class="nc" id="L664"> throw new IOException("unknown type");</span> } <span class="fc" id="L666"> break;</span> case BASIC_OPERATOR_MULTIPLY: <span class="pc bpc" id="L668" title="20 of 26 branches missed."> switch (typeList[i]) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="fc" id="L670"> sum *= args[idList[i]];</span> <span class="fc" id="L671"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L673"> sum *= (long) parserDoubles[idList[i]].getValueDouble(args, n);</span> <span class="nc" id="L674"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="nc" id="L676"> sum *= parserLongs[idList[i]].getValueLong(args, n);</span> <span class="nc" id="L677"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L679"> sum *= constantDoubles[idList[i]].longValue();</span> <span class="nc" id="L680"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="nc" id="L682"> sum *= constantLongs[idList[i]];</span> <span class="nc" id="L683"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="fc" id="L685"> sum *= n;</span> <span class="fc" id="L686"> break;</span> default: <span class="nc" id="L688"> throw new IOException("unknown type");</span> } <span class="fc" id="L690"> break;</span> case BASIC_OPERATOR_DIVIDE: long v; <span class="nc bnc" id="L693" title="All 26 branches missed."> switch (typeList[i]) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="nc" id="L695"> v = args[idList[i]];</span> <span class="nc" id="L696"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L698"> v = (long) parserDoubles[idList[i]].getValueDouble(args, n);</span> <span class="nc" id="L699"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="nc" id="L701"> v = parserLongs[idList[i]].getValueLong(args, n);</span> <span class="nc" id="L702"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L704"> v = constantDoubles[idList[i]].longValue();</span> <span class="nc" id="L705"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="nc" id="L707"> v = constantLongs[idList[i]];</span> <span class="nc" id="L708"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="nc" id="L710"> v = n;</span> <span class="nc" id="L711"> break;</span> default: <span class="nc" id="L713"> throw new IOException("unknown type");</span> } <span class="nc bnc" id="L715" title="All 2 branches missed."> if (v != 0) {</span> <span class="nc" id="L716"> sum /= v;</span> } else { <span class="nc" id="L718"> throw new IOException("division by zero");</span> } break; case BASIC_OPERATOR_POWER: <span class="pc bpc" id="L722" title="23 of 26 branches missed."> switch (typeList[i]) {</span> case MtasFunctionParserItem.TYPE_ARGUMENT: <span class="fc" id="L724"> sum = sum ^ args[idList[i]];</span> <span class="fc" id="L725"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_DOUBLE: <span class="nc" id="L727"> sum = sum ^ (long) parserDoubles[idList[i]].getValueDouble(args, n);</span> <span class="nc" id="L728"> break;</span> case MtasFunctionParserItem.TYPE_PARSER_LONG: <span class="nc" id="L730"> sum = sum ^ parserLongs[idList[i]].getValueLong(args, n);</span> <span class="nc" id="L731"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE: <span class="nc" id="L733"> sum = sum ^ constantDoubles[idList[i]].longValue();</span> <span class="nc" id="L734"> break;</span> case MtasFunctionParserItem.TYPE_CONSTANT_LONG: <span class="nc" id="L736"> sum = sum ^ constantLongs[idList[i]];</span> <span class="nc" id="L737"> break;</span> case MtasFunctionParserItem.TYPE_N: <span class="nc" id="L739"> sum = sum ^ n;</span> <span class="nc" id="L740"> break;</span> default: <span class="nc" id="L742"> throw new IOException("unknown type");</span> } <span class="fc" id="L744"> break;</span> default: <span class="nc" id="L746"> throw new IOException("unknown operator");</span> } } <span class="fc" id="L749"> return sum;</span> <span class="nc" id="L750"> } catch (java.lang.ArithmeticException e) {</span> <span class="nc" id="L751"> throw new IOException(e);</span> } } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { <span class="pc bpc" id="L762" title="1 of 2 branches missed."> if (firstType != null) {</span> <span class="fc" id="L763"> StringBuilder text = new StringBuilder(toString(firstType, firstId));</span> <span class="fc bfc" id="L764" title="All 2 branches covered."> for (int i = 0; i < tmpOperatorList.size(); i++) {</span> <span class="fc" id="L765"> String operator = tmpOperatorList.get(i);</span> <span class="fc bfc" id="L766" title="All 2 branches covered."> if (operator.equals(BASIC_OPERATOR_ADD)) {</span> <span class="fc" id="L767"> text.append(" + ");</span> <span class="fc bfc" id="L768" title="All 2 branches covered."> } else if (operator.equals(BASIC_OPERATOR_SUBTRACT)) {</span> <span class="fc" id="L769"> text.append(" - ");</span> <span class="fc bfc" id="L770" title="All 2 branches covered."> } else if (operator.equals(BASIC_OPERATOR_MULTIPLY)) {</span> <span class="fc" id="L771"> text.append(" * ");</span> <span class="fc bfc" id="L772" title="All 2 branches covered."> } else if (operator.equals(BASIC_OPERATOR_DIVIDE)) {</span> <span class="fc" id="L773"> text.append(" / ");</span> <span class="pc bpc" id="L774" title="1 of 2 branches missed."> } else if (operator.equals(BASIC_OPERATOR_POWER)) {</span> <span class="fc" id="L775"> text.append(" ^ ");</span> } else { <span class="nc" id="L777"> text.append(" ? ");</span> } <span class="fc" id="L779"> text.append(toString(tmpTypeList.get(i), tmpIdList.get(i)));</span> } <span class="fc" id="L781"> return text.toString();</span> } else { <span class="nc" id="L783"> return "?";</span> } } /** * To string. * * @param type the type * @param id the id * @return the string */ private String toString(String type, int id) { <span class="fc bfc" id="L795" title="All 2 branches covered."> if (type.equals(MtasFunctionParserItem.TYPE_CONSTANT_LONG)) {</span> <span class="fc" id="L796"> return tmpConstantLongs.get(id).toString();</span> <span class="fc bfc" id="L797" title="All 2 branches covered."> } else if (type.equals(MtasFunctionParserItem.TYPE_CONSTANT_DOUBLE)) {</span> <span class="fc" id="L798"> return tmpConstantDoubles.get(id).toString();</span> <span class="fc bfc" id="L799" title="All 2 branches covered."> } else if (type.equals(MtasFunctionParserItem.TYPE_PARSER_LONG)) {</span> <span class="fc" id="L800"> return "(" + tmpParserLongs.get(id).toString() + ")";</span> <span class="fc bfc" id="L801" title="All 2 branches covered."> } else if (type.equals(MtasFunctionParserItem.TYPE_PARSER_DOUBLE)) {</span> <span class="fc" id="L802"> return "(" + tmpParserDoubles.get(id).toString() + ")";</span> <span class="fc bfc" id="L803" title="All 2 branches covered."> } else if (type.equals(MtasFunctionParserItem.TYPE_ARGUMENT)) {</span> <span class="fc" id="L804"> return "$q" + id;</span> <span class="pc bpc" id="L805" title="1 of 2 branches missed."> } else if (type.equals(MtasFunctionParserItem.TYPE_N)) {</span> <span class="fc" id="L806"> return "$n";</span> } else { <span class="nc" id="L808"> return "..";</span> } } } </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>