<?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>MtasDataItemFull.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.codec.util.collector</a> > <span class="el_source">MtasDataItemFull.java</span></div><h1>MtasDataItemFull.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 java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import mtas.codec.util.CodecUtil;
/**
* The Class MtasDataItemFull.
*
* @param <T1> the generic type
* @param <T2> the generic type
*/
abstract class MtasDataItemFull<T1 extends Number & Comparable<T1>, T2 extends Number & Comparable<T2>>
extends MtasDataItem<T1, T2> implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The full values. */
public T1[] fullValues;
/** The operations. */
protected MtasDataOperations<T1, T2> operations;
/** The stats. */
<span class="fc" id="L33"> protected DescriptiveStatistics stats = null;</span>
/** The fp stats function items. */
<span class="fc" id="L36"> private Pattern fpStatsFunctionItems = Pattern</span>
<span class="fc" id="L37"> .compile("(([^\\(,]+)(\\(([^\\)]*)\\))?)");</span>
/**
* Instantiates a new mtas data item 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 operations the operations
* @param sourceNumber the source number
*/
public MtasDataItemFull(T1[] value, MtasDataCollector<?, ?> sub,
Set<String> statsItems, String sortType, String sortDirection,
int errorNumber, Map<String, Integer> errorList,
MtasDataOperations<T1, T2> operations, int sourceNumber) {
<span class="fc" id="L56"> super(sub, statsItems, sortType, sortDirection, errorNumber, errorList,</span>
sourceNumber);
<span class="fc" id="L58"> this.fullValues = value;</span>
<span class="fc" id="L59"> this.operations = operations;</span>
<span class="fc" id="L60"> }</span>
/*
* (non-Javadoc)
*
* @see mtas.codec.util.DataCollector.MtasDataItem#add(mtas.codec.util.
* DataCollector.MtasDataItem)
*/
@Override
public void add(MtasDataItem<T1, T2> newItem) throws IOException {
<span class="nc bnc" id="L70" title="All 2 branches missed."> if (newItem instanceof MtasDataItemFull) {</span>
<span class="nc" id="L71"> MtasDataItemFull<T1, T2> newTypedItem = (MtasDataItemFull<T1, T2>) newItem;</span>
<span class="nc" id="L72"> T1[] tmpValue = operations</span>
<span class="nc" id="L73"> .createVector1(fullValues.length + newTypedItem.fullValues.length);</span>
<span class="nc" id="L74"> System.arraycopy(fullValues, 0, tmpValue, 0, fullValues.length);</span>
<span class="nc" id="L75"> System.arraycopy(newTypedItem.fullValues, 0, tmpValue, fullValues.length,</span>
newTypedItem.fullValues.length);
<span class="nc" id="L77"> fullValues = tmpValue;</span>
<span class="nc" id="L78"> recomputeComparableSortValue = true;</span>
<span class="nc" id="L79"> } else {</span>
<span class="nc" id="L80"> throw new IOException("can only add MtasDataItemFull");</span>
}
<span class="nc" id="L82"> }</span>
/**
* Creates the stats.
*/
protected void createStats() {
<span class="pc bpc" id="L88" title="1 of 2 branches missed."> if (stats == null) {</span>
<span class="fc" id="L89"> stats = new DescriptiveStatistics();</span>
<span class="fc bfc" id="L90" title="All 2 branches covered."> for (T1 value : fullValues) {</span>
<span class="fc" id="L91"> stats.addValue(value.doubleValue());</span>
}
}
<span class="fc" id="L94"> }</span>
/**
* Gets the distribution.
*
* @param arguments the arguments
* @return the distribution
*/
abstract protected HashMap<String, Object> getDistribution(String arguments);
/*
* (non-Javadoc)
*
* @see mtas.codec.util.DataCollector.MtasDataItem#rewrite()
*/
@Override
public Map<String, Object> rewrite(boolean showDebugInfo) throws IOException {
<span class="fc" id="L111"> createStats();</span>
<span class="fc" id="L112"> Map<String, Object> response = new HashMap<>();</span>
<span class="fc bfc" id="L113" title="All 2 branches covered."> for (String statsItem : getStatsItems()) {</span>
<span class="fc bfc" id="L114" title="All 2 branches covered."> if (statsItem.equals(CodecUtil.STATS_TYPE_SUM)) {</span>
<span class="fc" id="L115"> response.put(statsItem, stats.getSum());</span>
<span class="fc bfc" id="L116" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_N)) {</span>
<span class="fc" id="L117"> response.put(statsItem, stats.getN());</span>
<span class="fc bfc" id="L118" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_MAX)) {</span>
<span class="fc" id="L119"> response.put(statsItem, stats.getMax());</span>
<span class="fc bfc" id="L120" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_MIN)) {</span>
<span class="fc" id="L121"> response.put(statsItem, stats.getMin());</span>
<span class="fc bfc" id="L122" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_SUMSQ)) {</span>
<span class="fc" id="L123"> response.put(statsItem, stats.getSumsq());</span>
<span class="fc bfc" id="L124" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_SUMOFLOGS)) {</span>
<span class="fc" id="L125"> response.put(statsItem,</span>
<span class="fc" id="L126"> stats.getN() * Math.log(stats.getGeometricMean()));</span>
<span class="fc bfc" id="L127" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_MEAN)) {</span>
<span class="fc" id="L128"> response.put(statsItem, stats.getMean());</span>
<span class="fc bfc" id="L129" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_GEOMETRICMEAN)) {</span>
<span class="fc" id="L130"> response.put(statsItem, stats.getGeometricMean());</span>
<span class="fc bfc" id="L131" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_STANDARDDEVIATION)) {</span>
<span class="fc" id="L132"> response.put(statsItem, stats.getStandardDeviation());</span>
<span class="fc bfc" id="L133" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_VARIANCE)) {</span>
<span class="fc" id="L134"> response.put(statsItem, stats.getVariance());</span>
<span class="fc bfc" id="L135" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_POPULATIONVARIANCE)) {</span>
<span class="fc" id="L136"> response.put(statsItem, stats.getPopulationVariance());</span>
<span class="fc bfc" id="L137" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_QUADRATICMEAN)) {</span>
<span class="fc" id="L138"> response.put(statsItem, Math.sqrt(stats.getSumsq() / stats.getN()));</span>
<span class="fc bfc" id="L139" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_KURTOSIS)) {</span>
<span class="fc" id="L140"> response.put(statsItem, stats.getKurtosis());</span>
<span class="fc bfc" id="L141" title="All 2 branches covered."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_MEDIAN)) {</span>
<span class="fc" id="L142"> response.put(statsItem, stats.getPercentile(50));</span>
<span class="pc bpc" id="L143" title="1 of 2 branches missed."> } else if (statsItem.equals(CodecUtil.STATS_TYPE_SKEWNESS)) {</span>
<span class="fc" id="L144"> response.put(statsItem, stats.getSkewness());</span>
} else {
<span class="nc" id="L146"> Matcher m = fpStatsFunctionItems.matcher(statsItem);</span>
<span class="nc bnc" id="L147" title="All 2 branches missed."> if (m.find()) {</span>
<span class="nc" id="L148"> String function = m.group(2).trim();</span>
<span class="nc bnc" id="L149" title="All 2 branches missed."> if (function.equals(CodecUtil.STATS_FUNCTION_DISTRIBUTION)) {</span>
<span class="nc" id="L150"> response.put(statsItem, getDistribution(m.group(4)));</span>
}
}
}
<span class="fc" id="L154"> }</span>
<span class="pc bpc" id="L155" title="1 of 2 branches missed."> if (errorNumber > 0) {</span>
<span class="nc" id="L156"> Map<String, Object> errorResponse = new HashMap<>();</span>
<span class="nc bnc" id="L157" title="All 2 branches missed."> for (Entry<String, Integer> entry : getErrorList().entrySet()) {</span>
<span class="nc" id="L158"> errorResponse.put(entry.getKey(), entry.getValue());</span>
<span class="nc" id="L159"> }</span>
<span class="nc" id="L160"> response.put("errorNumber", errorNumber);</span>
<span class="nc" id="L161"> response.put("errorList", errorResponse);</span>
}
<span class="pc bpc" id="L163" title="1 of 2 branches missed."> if (showDebugInfo) {</span>
<span class="nc" id="L164"> response.put("sourceNumber", sourceNumber);</span>
<span class="nc" id="L165"> response.put("stats", "full");</span>
}
<span class="fc" id="L167"> return response;</span>
}
/*
* (non-Javadoc)
*
* @see mtas.codec.util.collector.MtasDataItem#getCompareValueType()
*/
@Override
public final int getCompareValueType() throws IOException {
<span class="nc bnc" id="L177" title="All 50 branches missed."> switch (sortType) {</span>
case CodecUtil.STATS_TYPE_N:
<span class="nc" id="L179"> return 0;</span>
case CodecUtil.STATS_TYPE_SUM:
case CodecUtil.STATS_TYPE_MAX:
case CodecUtil.STATS_TYPE_MIN:
case CodecUtil.STATS_TYPE_SUMSQ:
<span class="nc" id="L184"> return 1;</span>
case CodecUtil.STATS_TYPE_SUMOFLOGS:
case CodecUtil.STATS_TYPE_MEAN:
case CodecUtil.STATS_TYPE_GEOMETRICMEAN:
case CodecUtil.STATS_TYPE_STANDARDDEVIATION:
case CodecUtil.STATS_TYPE_VARIANCE:
case CodecUtil.STATS_TYPE_POPULATIONVARIANCE:
case CodecUtil.STATS_TYPE_QUADRATICMEAN:
case CodecUtil.STATS_TYPE_KURTOSIS:
case CodecUtil.STATS_TYPE_MEDIAN:
case CodecUtil.STATS_TYPE_SKEWNESS:
<span class="nc" id="L195"> return 2;</span>
default:
<span class="nc" id="L197"> throw new IOException("sortType " + sortType + " not supported");</span>
}
}
/*
* (non-Javadoc)
*
* @see mtas.codec.util.collector.MtasDataItem#getCompareValue0()
*/
public final MtasDataItemNumberComparator<Long> getCompareValue0() {
<span class="nc" id="L207"> createStats();</span>
<span class="nc bnc" id="L208" title="All 6 branches missed."> switch (sortType) {</span>
case CodecUtil.STATS_TYPE_N:
<span class="nc" id="L210"> return new MtasDataItemNumberComparator<>(stats.getN(), sortDirection);</span>
default:
<span class="nc" id="L212"> 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>