<?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>MtasDataLongAdvanced.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">MtasDataLongAdvanced.java</span></div><h1>MtasDataLongAdvanced.java</h1><pre class="source lang-java linenums">package mtas.codec.util.collector; import java.io.IOException; import java.util.Collections; import java.util.SortedSet; import org.apache.commons.lang.ArrayUtils; import mtas.codec.util.CodecUtil; /** * The Class MtasDataLongAdvanced. */ public class MtasDataLongAdvanced extends MtasDataAdvanced<Long, Double> { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; /** * Instantiates a new mtas data long advanced. * * @param collectorType the collector type * @param statsItems the stats items * @param sortType the sort type * @param sortDirection the sort direction * @param start the start * @param number the number * @param subCollectorTypes the sub collector types * @param subDataTypes the sub data types * @param subStatsTypes the sub stats types * @param subStatsItems the sub stats items * @param subSortTypes the sub sort types * @param subSortDirections the sub sort directions * @param subStart the sub start * @param subNumber the sub number * @param segmentRegistration the segment registration * @param boundary the boundary * @throws IOException Signals that an I/O exception has occurred. */ public MtasDataLongAdvanced(String collectorType, SortedSet<String> statsItems, String sortType, String sortDirection, Integer start, Integer number, String[] subCollectorTypes, String[] subDataTypes, String[] subStatsTypes, SortedSet<String>[] subStatsItems, String[] subSortTypes, String[] subSortDirections, Integer[] subStart, Integer[] subNumber, String segmentRegistration, String boundary) throws IOException { <span class="fc" id="L46"> super(collectorType, CodecUtil.DATA_TYPE_LONG, statsItems, sortType,</span> sortDirection, start, number, subCollectorTypes, subDataTypes, subStatsTypes, subStatsItems, subSortTypes, subSortDirections, subStart, subNumber, new MtasDataLongOperations(), segmentRegistration, boundary); <span class="fc" id="L50"> }</span> /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#getItem(int) */ @Override protected final MtasDataItemLongAdvanced getItem(int i) { <span class="pc bpc" id="L59" title="2 of 4 branches missed."> if (i >= 0 && i < size) {</span> <span class="fc" id="L60"> return new MtasDataItemLongAdvanced(advancedValueSumList[i],</span> advancedValueSumOfLogsList[i], advancedValueSumOfSquaresList[i], advancedValueMinList[i], advancedValueMaxList[i], <span class="pc bpc" id="L63" title="1 of 2 branches missed."> advancedValueNList[i], hasSub() ? subCollectorListNextLevel[i] : null,</span> <span class="fc" id="L64"> getStatsItems(), sortType, sortDirection, errorNumber[i],</span> errorList[i], sourceNumberList[i]); } else { <span class="nc" id="L67"> return null;</span> } } /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#add(long, long) */ @Override public MtasDataCollector<?, ?> add(long valueSum, long valueN) throws IOException { <span class="nc" id="L79"> throw new IOException("not supported");</span> } /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#add(long[], int) */ @Override public MtasDataCollector<?, ?> add(long[] values, int number) throws IOException { <span class="fc" id="L90"> MtasDataCollector<?, ?> dataCollector = add(false);</span> <span class="fc" id="L91"> setValue(newCurrentPosition, ArrayUtils.toObject(values), number,</span> newCurrentExisting); <span class="fc" id="L93"> return dataCollector;</span> } /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#add(double, long) */ @Override public MtasDataCollector<?, ?> add(double valueSum, long valueN) throws IOException { <span class="nc" id="L104"> throw new IOException("not supported");</span> } /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#add(double[], int) */ @Override public MtasDataCollector<?, ?> add(double[] values, int number) throws IOException { <span class="nc" id="L115"> MtasDataCollector<?, ?> dataCollector = add(false);</span> <span class="nc" id="L116"> Long[] newValues = new Long[number];</span> <span class="nc bnc" id="L117" title="All 2 branches missed."> for (int i = 0; i < values.length; i++)</span> <span class="nc" id="L118"> newValues[i] = Double.valueOf(values[i]).longValue();</span> <span class="nc" id="L119"> setValue(newCurrentPosition, newValues, number, newCurrentExisting);</span> <span class="nc" id="L120"> return dataCollector;</span> } /* * (non-Javadoc) * * @see * mtas.codec.util.DataCollector.MtasDataCollector#add(java.lang.String[], * long, long) */ @Override public MtasDataCollector<?, ?> add(String key, long valueSum, long valueN) throws IOException { <span class="nc" id="L133"> throw new IOException("not supported");</span> } /* * (non-Javadoc) * * @see * mtas.codec.util.DataCollector.MtasDataCollector#add(java.lang.String[], * long[], int) */ @Override public MtasDataCollector<?, ?> add(String key, long[] values, int number) throws IOException { <span class="pc bpc" id="L146" title="1 of 2 branches missed."> if (key != null) {</span> <span class="fc" id="L147"> MtasDataCollector<?, ?> subCollector = add(key, false);</span> <span class="fc" id="L148"> setValue(newCurrentPosition, ArrayUtils.toObject(values), number,</span> newCurrentExisting); <span class="fc" id="L150"> return subCollector;</span> } else { <span class="nc" id="L152"> return null;</span> } } /* * (non-Javadoc) * * @see * mtas.codec.util.DataCollector.MtasDataCollector#add(java.lang.String[], * double, long) */ @Override public MtasDataCollector<?, ?> add(String key, double valueSum, long valueN) throws IOException { <span class="nc" id="L166"> throw new IOException("not supported");</span> } /* * (non-Javadoc) * * @see * mtas.codec.util.DataCollector.MtasDataCollector#add(java.lang.String[], * double[], int) */ @Override public MtasDataCollector<?, ?> add(String key, double[] values, int number) throws IOException { <span class="nc bnc" id="L179" title="All 2 branches missed."> if (key != null) {</span> <span class="nc" id="L180"> Long[] newValues = new Long[number];</span> <span class="nc bnc" id="L181" title="All 2 branches missed."> for (int i = 0; i < values.length; i++)</span> <span class="nc" id="L182"> newValues[i] = Double.valueOf(values[i]).longValue();</span> <span class="nc" id="L183"> MtasDataCollector<?, ?> subCollector = add(key, false);</span> <span class="nc" id="L184"> setValue(newCurrentPosition, newValues, number, newCurrentExisting);</span> <span class="nc" id="L185"> return subCollector;</span> } else { <span class="nc" id="L187"> return null;</span> } } /* * (non-Javadoc) * * @see * mtas.codec.util.DataCollector.MtasDataCollector#compareForComputingSegment( * java.lang.Number, java.lang.Number) */ @Override protected boolean compareWithBoundary(Long value, Long boundary) throws IOException { <span class="fc bfc" id="L201" title="All 2 branches covered."> if (segmentRegistration.equals(SEGMENT_SORT_ASC)</span> <span class="pc bpc" id="L202" title="1 of 2 branches missed."> || segmentRegistration.equals(SEGMENT_BOUNDARY_ASC)) {</span> <span class="fc bfc" id="L203" title="All 2 branches covered."> return value <= boundary;</span> <span class="pc bpc" id="L204" title="1 of 2 branches missed."> } else if (segmentRegistration.equals(SEGMENT_SORT_DESC)</span> <span class="nc bnc" id="L205" title="All 2 branches missed."> || segmentRegistration.equals(SEGMENT_BOUNDARY_DESC)) {</span> <span class="fc bfc" id="L206" title="All 2 branches covered."> return value >= boundary;</span> } else { <span class="nc" id="L208"> throw new IOException(</span> "can't compare for segmentRegistration " + segmentRegistration); } } /* * (non-Javadoc) * * @see * mtas.codec.util.DataCollector.MtasDataCollector#minimumForComputingSegment( * java.lang.Number, java.lang.Number) */ @Override protected Long lastForComputingSegment(Long value, Long boundary) throws IOException { <span class="fc bfc" id="L223" title="All 2 branches covered."> if (segmentRegistration.equals(SEGMENT_SORT_ASC)</span> <span class="pc bpc" id="L224" title="1 of 2 branches missed."> || segmentRegistration.equals(SEGMENT_BOUNDARY_ASC)) {</span> <span class="fc" id="L225"> return Math.max(value, boundary);</span> <span class="pc bpc" id="L226" title="1 of 2 branches missed."> } else if (segmentRegistration.equals(SEGMENT_SORT_DESC)</span> <span class="nc bnc" id="L227" title="All 2 branches missed."> || segmentRegistration.equals(SEGMENT_BOUNDARY_DESC)) {</span> <span class="fc" id="L228"> return Math.min(value, boundary);</span> } else { <span class="nc" id="L230"> throw new IOException(</span> "can't compute last for segmentRegistration " + segmentRegistration); } } /* * (non-Javadoc) * * @see * mtas.codec.util.DataCollector.MtasDataCollector#minimumForComputingSegment( * ) */ @Override protected Long lastForComputingSegment() throws IOException { <span class="fc bfc" id="L244" title="All 2 branches covered."> if (segmentRegistration.equals(SEGMENT_SORT_ASC)</span> <span class="pc bpc" id="L245" title="1 of 2 branches missed."> || segmentRegistration.equals(SEGMENT_BOUNDARY_ASC)) {</span> <span class="fc" id="L246"> return Collections.max(segmentValueTopList);</span> <span class="pc bpc" id="L247" title="1 of 2 branches missed."> } else if (segmentRegistration.equals(SEGMENT_SORT_DESC)</span> <span class="nc bnc" id="L248" title="All 2 branches missed."> || segmentRegistration.equals(SEGMENT_BOUNDARY_DESC)) {</span> <span class="fc" id="L249"> return Collections.min(segmentValueTopList);</span> } else { <span class="nc" id="L251"> throw new IOException(</span> "can't compute last for segmentRegistration " + segmentRegistration); } } /* * (non-Javadoc) * * @see * mtas.codec.util.DataCollector.MtasDataCollector#boundaryForComputingSegment * () */ @Override protected Long boundaryForSegmentComputing(String segmentName) throws IOException { <span class="fc bfc" id="L266" title="All 2 branches covered."> if (segmentRegistration.equals(SEGMENT_SORT_ASC)</span> <span class="pc bpc" id="L267" title="1 of 2 branches missed."> || segmentRegistration.equals(SEGMENT_SORT_DESC)) {</span> <span class="fc" id="L268"> Long boundary = boundaryForSegment(segmentName);</span> <span class="pc bpc" id="L269" title="1 of 2 branches missed."> if (boundary == null) {</span> <span class="nc" id="L270"> return null;</span> } else { <span class="fc bfc" id="L272" title="All 2 branches covered."> if (segmentRegistration.equals(SEGMENT_SORT_DESC)) {</span> <span class="fc" id="L273"> long correctionBoundary = 0;</span> <span class="fc bfc" id="L274" title="All 2 branches covered."> for (String otherSegmentName : segmentValueTopListLast.keySet()) {</span> <span class="fc bfc" id="L275" title="All 2 branches covered."> if (!otherSegmentName.equals(segmentName)) {</span> <span class="fc" id="L276"> Long otherBoundary = segmentValuesBoundary.get(otherSegmentName);</span> <span class="pc bpc" id="L277" title="1 of 2 branches missed."> if (otherBoundary != null) {</span> <span class="fc" id="L278"> correctionBoundary += Math.max(0, otherBoundary - boundary);</span> } } <span class="fc" id="L281"> }</span> <span class="fc" id="L282"> return boundary + correctionBoundary;</span> } else { <span class="fc" id="L284"> return boundary;</span> } } } else { <span class="nc" id="L288"> throw new IOException("can't compute boundary for segmentRegistration "</span> + segmentRegistration); } } /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#boundaryForSegment() */ @Override protected Long boundaryForSegment(String segmentName) throws IOException { <span class="fc bfc" id="L300" title="All 2 branches covered."> if (segmentRegistration.equals(SEGMENT_SORT_ASC)</span> <span class="pc bpc" id="L301" title="1 of 2 branches missed."> || segmentRegistration.equals(SEGMENT_SORT_DESC)) {</span> <span class="fc" id="L302"> Long thisLast = segmentValueTopListLast.get(segmentName);</span> <span class="pc bpc" id="L303" title="1 of 2 branches missed."> if (thisLast == null) {</span> <span class="nc" id="L304"> return null;</span> <span class="fc bfc" id="L305" title="All 2 branches covered."> } else if (segmentRegistration.equals(SEGMENT_SORT_ASC)) {</span> <span class="fc" id="L306"> return thisLast * segmentNumber;</span> } else { <span class="fc" id="L308"> return Math.floorDiv(thisLast, segmentNumber);</span> } } else { <span class="nc" id="L311"> throw new IOException("can't compute boundary for segmentRegistration "</span> + segmentRegistration); } } /* * (non-Javadoc) * * @see * mtas.codec.util.collector.MtasDataCollector#stringToBoundary(java.lang. * String, java.lang.Integer) */ @Override protected Long stringToBoundary(String boundary, Integer segmentNumber) throws IOException { <span class="nc bnc" id="L326" title="All 2 branches missed."> if (segmentRegistration.equals(SEGMENT_BOUNDARY_ASC)</span> <span class="nc bnc" id="L327" title="All 2 branches missed."> || segmentRegistration.equals(SEGMENT_BOUNDARY_DESC)) {</span> <span class="nc bnc" id="L328" title="All 2 branches missed."> if (segmentNumber == null) {</span> <span class="nc" id="L329"> return Long.valueOf(boundary);</span> } else { <span class="nc" id="L331"> return Math.floorDiv(Long.parseLong(boundary), segmentNumber);</span> } } else { <span class="nc" id="L334"> throw new IOException(</span> "not available for segmentRegistration " + segmentRegistration); } } /* * (non-Javadoc) * * @see * mtas.codec.util.collector.MtasDataCollector#validateSegmentBoundary(java. * lang.Object) */ @Override public boolean validateSegmentBoundary(Object o) throws IOException { <span class="pc bpc" id="L348" title="1 of 2 branches missed."> if (o instanceof Long) {</span> <span class="fc" id="L349"> return validateWithSegmentBoundary((Long) o);</span> } else { <span class="nc" id="L351"> throw new IOException("incorrect type");</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>