MtasDataItemLongFull.java.html 15 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>MtasDataItemLongFull.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">MtasDataItemLongFull.java</span></div><h1>MtasDataItemLongFull.java</h1><pre class="source lang-java linenums">package mtas.codec.util.collector;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.ArrayUtils;
import mtas.codec.util.CodecUtil;

/**
 * The Class MtasDataItemLongFull.
 */
class MtasDataItemLongFull extends MtasDataItemFull&lt;Long, Double&gt; {

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

  /** The fp argument. */
<span class="fc" id="L21">  private static Pattern fpArgument = Pattern.compile(&quot;([^=,]+)=([^,]*)&quot;);</span>

  /**
   * Instantiates a new mtas data item long full.
   *
   * @param value the value
   * @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 sourceNumber the source number
   */
  public MtasDataItemLongFull(long[] value, MtasDataCollector&lt;?, ?&gt; sub,
      Set&lt;String&gt; statsItems, String sortType, String sortDirection,
      int errorNumber, Map&lt;String, Integer&gt; errorList, int sourceNumber) {
<span class="fc" id="L38">    super(ArrayUtils.toObject(value), sub, statsItems, sortType, sortDirection,</span>
        errorNumber, errorList, new MtasDataLongOperations(), sourceNumber);
<span class="fc" id="L40">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.codec.util.DataCollector.MtasDataItemFull#getDistribution(java.lang.
   * String)
   */
  @Override
  protected HashMap&lt;String, Object&gt; getDistribution(String argument) {
<span class="nc" id="L51">    HashMap&lt;String, Object&gt; result = new LinkedHashMap&lt;&gt;();</span>
<span class="nc" id="L52">    Long start = null;</span>
<span class="nc" id="L53">    Long end = null;</span>
<span class="nc" id="L54">    Long step = null;</span>
<span class="nc" id="L55">    Integer number = null;</span>
<span class="nc bnc" id="L56" title="All 2 branches missed.">    if (argument != null) {</span>
<span class="nc" id="L57">      Matcher m = fpArgument.matcher(argument);</span>
      // get settings
<span class="nc bnc" id="L59" title="All 2 branches missed.">      while (m.find()) {</span>
<span class="nc bnc" id="L60" title="All 2 branches missed.">        if (m.group(1).trim().equals(&quot;start&quot;)) {</span>
<span class="nc" id="L61">          start = Long.parseLong(m.group(2));</span>
<span class="nc bnc" id="L62" title="All 2 branches missed.">        } else if (m.group(1).trim().equals(&quot;end&quot;)) {</span>
<span class="nc" id="L63">          end = Long.parseLong(m.group(2));</span>
<span class="nc bnc" id="L64" title="All 2 branches missed.">        } else if (m.group(1).trim().equals(&quot;step&quot;)) {</span>
<span class="nc" id="L65">          step = Long.parseLong(m.group(2));</span>
<span class="nc bnc" id="L66" title="All 2 branches missed.">        } else if (m.group(1).trim().equals(&quot;number&quot;)) {</span>
<span class="nc" id="L67">          number = Integer.parseInt(m.group(2));</span>
        }
      }
    }
    // always exactly one of (positive) number and (positive) step, other null
<span class="nc bnc" id="L72" title="All 8 branches missed.">    if ((number == null || number &lt; 1) &amp;&amp; (step == null || step &lt; 1)) {</span>
<span class="nc" id="L73">      number = 10;</span>
<span class="nc" id="L74">      step = null;</span>
<span class="nc bnc" id="L75" title="All 4 branches missed.">    } else if (step != null &amp;&amp; step &lt; 1) {</span>
<span class="nc" id="L76">      step = null;</span>
<span class="nc bnc" id="L77" title="All 4 branches missed.">    } else if (number != null &amp;&amp; number &lt; 1) {</span>
<span class="nc" id="L78">      number = null;</span>
<span class="nc bnc" id="L79" title="All 2 branches missed.">    } else if (step != null) {</span>
<span class="nc" id="L80">      number = null;</span>
    }
    // sanity checks start/end
<span class="nc" id="L83">    createStats();</span>
<span class="nc" id="L84">    long tmpStart = Double.valueOf(Math.floor(stats.getMin())).longValue();</span>
<span class="nc" id="L85">    long tmpEnd = Double.valueOf(Math.ceil(stats.getMax())).longValue();</span>
<span class="nc bnc" id="L86" title="All 6 branches missed.">    if (start != null &amp;&amp; end != null &amp;&amp; start &gt; end) {</span>
<span class="nc" id="L87">      return null;</span>
<span class="nc bnc" id="L88" title="All 4 branches missed.">    } else if (start != null &amp;&amp; start &gt; tmpEnd) {</span>
<span class="nc" id="L89">      return null;</span>
<span class="nc bnc" id="L90" title="All 4 branches missed.">    } else if (end != null &amp;&amp; end &lt; tmpStart) {</span>
<span class="nc" id="L91">      return null;</span>
    }
    // check start and end
<span class="nc bnc" id="L94" title="All 4 branches missed.">    if (start == null &amp;&amp; end == null) {</span>
<span class="nc bnc" id="L95" title="All 2 branches missed.">      if (step == null) {</span>
<span class="nc" id="L96">        step = -Math.floorDiv((tmpStart - tmpEnd - 1), number);</span>
      }
<span class="nc" id="L98">      number = Long.valueOf(-Math.floorDiv((tmpStart - tmpEnd - 1), step))</span>
<span class="nc" id="L99">          .intValue();</span>
<span class="nc" id="L100">      start = tmpStart;</span>
<span class="nc" id="L101">      end = start + (number * step);</span>
<span class="nc bnc" id="L102" title="All 2 branches missed.">    } else if (start == null) {</span>
<span class="nc bnc" id="L103" title="All 2 branches missed.">      if (step == null) {</span>
<span class="nc" id="L104">        step = -Math.floorDiv((tmpStart - end - 1), number);</span>
      }
<span class="nc" id="L106">      number = Long.valueOf(-Math.floorDiv((tmpStart - end - 1), step))</span>
<span class="nc" id="L107">          .intValue();</span>
<span class="nc" id="L108">      start = end - (number * step);</span>
<span class="nc bnc" id="L109" title="All 2 branches missed.">    } else if (end == null) {</span>
<span class="nc bnc" id="L110" title="All 2 branches missed.">      if (step == null) {</span>
<span class="nc" id="L111">        step = -Math.floorDiv((start - tmpEnd - 1), number);</span>
      }
<span class="nc" id="L113">      number = Long.valueOf(-Math.floorDiv((start - tmpEnd - 1), step))</span>
<span class="nc" id="L114">          .intValue();</span>
<span class="nc" id="L115">      end = start + (number * step);</span>
    } else {
<span class="nc bnc" id="L117" title="All 2 branches missed.">      if (step == null) {</span>
<span class="nc" id="L118">        step = -Math.floorDiv((start - end - 1), number);</span>
      }
<span class="nc" id="L120">      number = Long.valueOf(-Math.floorDiv((start - end - 1), step)).intValue();</span>
    }
<span class="nc" id="L122">    long[] list = new long[number];</span>
<span class="nc bnc" id="L123" title="All 2 branches missed.">    for (Long v : fullValues) {</span>
<span class="nc bnc" id="L124" title="All 4 branches missed.">      if (v &gt;= start &amp;&amp; v &lt;= end) {</span>
<span class="nc" id="L125">        int i = Long.valueOf(Math.floorDiv((v - start), step)).intValue();</span>
<span class="nc" id="L126">        list[i]++;</span>
      }
    }
<span class="nc bnc" id="L129" title="All 2 branches missed.">    for (int i = 0; i &lt; number; i++) {</span>
<span class="nc" id="L130">      Long l = start + i * step;</span>
<span class="nc" id="L131">      Long r = Math.min(end, l + step - 1);</span>
      String key;
<span class="nc bnc" id="L133" title="All 4 branches missed.">      if (step &gt; 1 &amp;&amp; r &gt; l) {</span>
<span class="nc" id="L134">        key = &quot;[&quot; + l + &quot;,&quot; + r + &quot;]&quot;;</span>
      } else {
<span class="nc" id="L136">        key = &quot;[&quot; + l + &quot;]&quot;;</span>
      }
<span class="nc" id="L138">      result.put(key, list[i]);</span>
    }
<span class="nc" id="L140">    return result;</span>
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Comparable#compareTo(java.lang.Object)
   */
  @SuppressWarnings({ &quot;rawtypes&quot;, &quot;unchecked&quot; })
  public int compareTo(MtasDataItem&lt;Long, Double&gt; o) {
<span class="nc" id="L150">    int compare = 0;</span>
<span class="nc bnc" id="L151" title="All 2 branches missed.">    if (o instanceof MtasDataItemLongFull) {</span>
<span class="nc" id="L152">      MtasDataItemLongFull to = (MtasDataItemLongFull) o;</span>
<span class="nc" id="L153">      MtasDataItemNumberComparator c1 = getComparableValue();</span>
<span class="nc" id="L154">      MtasDataItemNumberComparator c2 = to.getComparableValue();</span>
<span class="nc bnc" id="L155" title="All 4 branches missed.">      compare = (c1 != null &amp;&amp; c2 != null) ? c1.compareTo(c2.getValue()) : 0;</span>
    }
<span class="nc bnc" id="L157" title="All 2 branches missed.">    return sortDirection.equals(CodecUtil.SORT_DESC) ? -1 * compare : compare;</span>
  }

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.collector.MtasDataItem#getCompareValue1()
   */
  @Override
  public MtasDataItemNumberComparator&lt;Long&gt; getCompareValue1() {
<span class="nc" id="L167">    createStats();</span>
<span class="nc bnc" id="L168" title="All 18 branches missed.">    switch (sortType) {</span>
    case CodecUtil.STATS_TYPE_SUM:
<span class="nc" id="L170">      return new MtasDataItemNumberComparator&lt;&gt;(Math.round(stats.getSum()),</span>
          sortDirection);
    case CodecUtil.STATS_TYPE_MAX:
<span class="nc" id="L173">      return new MtasDataItemNumberComparator&lt;&gt;(Math.round(stats.getMax()),</span>
          sortDirection);
    case CodecUtil.STATS_TYPE_MIN:
<span class="nc" id="L176">      return new MtasDataItemNumberComparator&lt;&gt;(Math.round(stats.getMin()),</span>
          sortDirection);
    case CodecUtil.STATS_TYPE_SUMSQ:
<span class="nc" id="L179">      return new MtasDataItemNumberComparator&lt;&gt;(Math.round(stats.getSumsq()),</span>
          sortDirection);
    default:
<span class="nc" id="L182">      return null;</span>
    }
  }

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.collector.MtasDataItem#getCompareValue2()
   */
  @Override
  public MtasDataItemNumberComparator&lt;Double&gt; getCompareValue2() {
<span class="nc" id="L193">    createStats();</span>
<span class="nc bnc" id="L194" title="All 42 branches missed.">    switch (sortType) {</span>
    case CodecUtil.STATS_TYPE_SUMOFLOGS:
<span class="nc" id="L196">      return new MtasDataItemNumberComparator&lt;&gt;(</span>
<span class="nc" id="L197">          stats.getN() * Math.log(stats.getGeometricMean()), sortDirection);</span>
    case CodecUtil.STATS_TYPE_MEAN:
<span class="nc" id="L199">      return new MtasDataItemNumberComparator&lt;&gt;(stats.getMean(), sortDirection);</span>
    case CodecUtil.STATS_TYPE_GEOMETRICMEAN:
<span class="nc" id="L201">      return new MtasDataItemNumberComparator&lt;&gt;(stats.getGeometricMean(),</span>
          sortDirection);
    case CodecUtil.STATS_TYPE_STANDARDDEVIATION:
<span class="nc" id="L204">      return new MtasDataItemNumberComparator&lt;&gt;(stats.getStandardDeviation(),</span>
          sortDirection);
    case CodecUtil.STATS_TYPE_VARIANCE:
<span class="nc" id="L207">      return new MtasDataItemNumberComparator&lt;&gt;(stats.getVariance(),</span>
          sortDirection);
    case CodecUtil.STATS_TYPE_POPULATIONVARIANCE:
<span class="nc" id="L210">      return new MtasDataItemNumberComparator&lt;&gt;(stats.getPopulationVariance(),</span>
          sortDirection);
    case CodecUtil.STATS_TYPE_QUADRATICMEAN:
<span class="nc" id="L213">      return new MtasDataItemNumberComparator&lt;&gt;(Math.sqrt(stats.getSumsq()/stats.getN()),</span>
          sortDirection);
    case CodecUtil.STATS_TYPE_KURTOSIS:
<span class="nc" id="L216">      return new MtasDataItemNumberComparator&lt;&gt;(stats.getKurtosis(),</span>
          sortDirection);
    case CodecUtil.STATS_TYPE_MEDIAN:
<span class="nc" id="L219">      return new MtasDataItemNumberComparator&lt;&gt;(stats.getPercentile(50),</span>
          sortDirection);
    case CodecUtil.STATS_TYPE_SKEWNESS:
<span class="nc" id="L222">      return new MtasDataItemNumberComparator&lt;&gt;(stats.getSkewness(),</span>
          sortDirection);
    default:
<span class="nc" id="L225">      return null;</span>
    }
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#toString()
   */
  public String toString() {
<span class="nc" id="L235">    return this.getClass().getSimpleName() + &quot;[&quot; + fullValues.length + &quot;]&quot;;</span>
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(Object obj) {
<span class="nc bnc" id="L245" title="All 2 branches missed.">    if (this == obj)</span>
<span class="nc" id="L246">      return true;</span>
<span class="nc bnc" id="L247" title="All 2 branches missed.">    if (obj == null)</span>
<span class="nc" id="L248">      return false;</span>
<span class="nc bnc" id="L249" title="All 2 branches missed.">    if (getClass() != obj.getClass())</span>
<span class="nc" id="L250">      return false;</span>
<span class="nc" id="L251">    MtasDataItemLongFull that = (MtasDataItemLongFull) obj;</span>
<span class="nc" id="L252">    MtasDataItemNumberComparator&lt;?&gt; c1 = getComparableValue();</span>
<span class="nc" id="L253">    MtasDataItemNumberComparator&lt;?&gt; c2 = that.getComparableValue();</span>
<span class="nc bnc" id="L254" title="All 6 branches missed.">    return (c1 != null &amp;&amp; c2 != null &amp;&amp; c1.equals(c2));</span>
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode() {
<span class="nc" id="L264">    int h = this.getClass().getSimpleName().hashCode();</span>
<span class="nc" id="L265">    h = (h * 7) ^ getComparableValue().hashCode();</span>
<span class="nc" id="L266">    return h;</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>