MtasDataItemBasic.java.html 7.7 KB
<?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>MtasDataItemBasic.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> &gt; <a href="index.source.html" class="el_package">mtas.codec.util.collector</a> &gt; <span class="el_source">MtasDataItemBasic.java</span></div><h1>MtasDataItemBasic.java</h1><pre class="source lang-java linenums">package mtas.codec.util.collector;

import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import mtas.codec.util.CodecUtil;

/**
 * The Class MtasDataItemBasic.
 *
 * @param &lt;T1&gt; the generic type
 * @param &lt;T2&gt; the generic type
 */
abstract class MtasDataItemBasic&lt;T1 extends Number &amp; Comparable&lt;T1&gt;, T2 extends Number &amp; Comparable&lt;T2&gt;&gt;
    extends MtasDataItem&lt;T1, T2&gt; implements Serializable {

  /** The Constant serialVersionUID. */
  private static final long serialVersionUID = 1L;

  /** The value sum. */
  protected T1 valueSum;

  /** The value N. */
  protected Long valueN;

  /** The operations. */
  protected MtasDataOperations&lt;T1, T2&gt; operations;

  /**
   * Instantiates a new mtas data item basic.
   *
   * @param valueSum the value sum
   * @param valueN the value N
   * @param sub the sub
   * @param statsItems the stats items
   * @param sortType the sort type
   * @param sortDirection the sort direction
   * @param errorNumber the error number
   * @param errorList the error list
   * @param operations the operations
   * @param sourceNumber the source number
   */
  public MtasDataItemBasic(T1 valueSum, long valueN,
      MtasDataCollector&lt;?, ?&gt; sub, Set&lt;String&gt; statsItems, String sortType,
      String sortDirection, int errorNumber, Map&lt;String, Integer&gt; errorList,
      MtasDataOperations&lt;T1, T2&gt; operations, int sourceNumber) {
<span class="fc" id="L51">    super(sub, statsItems, sortType, sortDirection, errorNumber, errorList,</span>
        sourceNumber);
<span class="fc" id="L53">    this.valueSum = valueSum;</span>
<span class="fc" id="L54">    this.valueN = valueN;</span>
<span class="fc" id="L55">    this.operations = operations;</span>
<span class="fc" id="L56">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.DataCollector.MtasDataItem#add(mtas.codec.util.
   * DataCollector.MtasDataItem)
   */
  @Override
  public void add(MtasDataItem&lt;T1, T2&gt; newItem) throws IOException {
<span class="nc bnc" id="L66" title="All 2 branches missed.">    if (newItem instanceof MtasDataItemBasic) {</span>
<span class="nc" id="L67">      MtasDataItemBasic&lt;T1, T2&gt; newTypedItem = (MtasDataItemBasic&lt;T1, T2&gt;) newItem;</span>
<span class="nc" id="L68">      this.valueSum = operations.add11(this.valueSum, newTypedItem.valueSum);</span>
<span class="nc" id="L69">      this.valueN += newTypedItem.valueN;</span>
<span class="nc" id="L70">      recomputeComparableSortValue = true;</span>
<span class="nc" id="L71">    } else {</span>
<span class="nc" id="L72">      throw new IOException(&quot;can only add MtasDataItemBasic&quot;);</span>
    }
<span class="nc" id="L74">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.DataCollector.MtasDataItem#rewrite()
   */
  @Override
  public Map&lt;String, Object&gt; rewrite(boolean showDebugInfo) throws IOException {
<span class="fc" id="L83">    Map&lt;String, Object&gt; response = new HashMap&lt;&gt;();</span>
<span class="fc bfc" id="L84" title="All 2 branches covered.">    for (String statsItem : getStatsItems()) {</span>
<span class="fc bfc" id="L85" title="All 2 branches covered.">      if (statsItem.equals(CodecUtil.STATS_TYPE_SUM)) {</span>
<span class="fc" id="L86">        response.put(statsItem, valueSum);</span>
<span class="fc bfc" id="L87" title="All 2 branches covered.">      } else if (statsItem.equals(CodecUtil.STATS_TYPE_N)) {</span>
<span class="fc" id="L88">        response.put(statsItem, valueN);</span>
<span class="pc bpc" id="L89" title="1 of 2 branches missed.">      } else if (statsItem.equals(CodecUtil.STATS_TYPE_MEAN)) {</span>
<span class="fc" id="L90">        response.put(statsItem, getValue(statsItem));</span>
      } else {
<span class="nc" id="L92">        response.put(statsItem, null);</span>
      }
<span class="fc" id="L94">    }</span>
<span class="pc bpc" id="L95" title="1 of 2 branches missed.">    if (errorNumber &gt; 0) {</span>
<span class="nc" id="L96">      Map&lt;String, Object&gt; errorResponse = new HashMap&lt;String, Object&gt;();</span>
<span class="nc bnc" id="L97" title="All 2 branches missed.">      for (Entry&lt;String, Integer&gt; entry : getErrorList().entrySet()) {</span>
<span class="nc" id="L98">        errorResponse.put(entry.getKey(), entry.getValue());</span>
<span class="nc" id="L99">      }</span>
<span class="nc" id="L100">      response.put(&quot;errorNumber&quot;, errorNumber);</span>
<span class="nc" id="L101">      response.put(&quot;errorList&quot;, errorResponse);</span>
    }
<span class="pc bpc" id="L103" title="1 of 2 branches missed.">    if (showDebugInfo) {</span>
<span class="nc" id="L104">      response.put(&quot;sourceNumber&quot;, sourceNumber);</span>
<span class="nc" id="L105">      response.put(&quot;stats&quot;, &quot;basic&quot;);</span>
    }
<span class="fc" id="L107">    return response;</span>
  }

  /**
   * Gets the value.
   *
   * @param statsType the stats type
   * @return the value
   */
  protected T2 getValue(String statsType) {
<span class="pc bpc" id="L117" title="1 of 2 branches missed.">    if (statsType.equals(CodecUtil.STATS_TYPE_MEAN)) {</span>
<span class="fc" id="L118">      return operations.divide1(valueSum, valueN);</span>
    } else {
<span class="nc" id="L120">      return null;</span>
    }
  }

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.collector.MtasDataItem#getCompareValueType()
   */
  public final int getCompareValueType() throws IOException {
<span class="pc bpc" id="L130" title="9 of 14 branches missed.">    switch (sortType) {</span>
    case CodecUtil.STATS_TYPE_N:
<span class="nc" id="L132">      return 0;</span>
    case CodecUtil.STATS_TYPE_SUM:
<span class="fc" id="L134">      return 1;</span>
    case CodecUtil.STATS_TYPE_MEAN:
<span class="nc" id="L136">      return 2;</span>
    default:
<span class="fc" id="L138">      throw new IOException(&quot;sortType &quot; + sortType + &quot; not supported&quot;);</span>
    }
  }

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.collector.MtasDataItem#getCompareValue0()
   */
  public final MtasDataItemNumberComparator&lt;Long&gt; getCompareValue0() {
<span class="nc bnc" id="L148" title="All 6 branches missed.">    switch (sortType) {</span>
    case CodecUtil.STATS_TYPE_N:
<span class="nc" id="L150">      return new MtasDataItemNumberComparator&lt;Long&gt;(valueN, sortDirection);</span>
    default:
<span class="nc" id="L152">      return null;</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>