<?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>MtasDataBasic.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">MtasDataBasic.java</span></div><h1>MtasDataBasic.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.Set; import java.util.SortedSet; import mtas.codec.util.CodecUtil; import mtas.codec.util.DataCollector; /** * The Class MtasDataBasic. * * @param <T1> the generic type * @param <T2> the generic type */ abstract class MtasDataBasic<T1 extends Number & Comparable<T1>, T2 extends Number & Comparable<T2>> extends MtasDataCollector<T1, T2> implements Serializable { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; /** The basic value sum list. */ <span class="fc" id="L26"> protected T1[] basicValueSumList = null;</span> /** The basic value N list. */ <span class="fc" id="L29"> protected long[] basicValueNList = null;</span> /** The new basic value sum list. */ <span class="fc" id="L32"> protected transient T1[] newBasicValueSumList = null;</span> /** The new basic value N list. */ <span class="fc" id="L35"> protected transient long[] newBasicValueNList = null;</span> /** The operations. */ protected MtasDataOperations<T1, T2> operations; /** * Instantiates a new mtas data basic. * * @param collectorType the collector type * @param dataType the data 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 operations the operations * @param segmentRegistration the segment registration * @param boundary the boundary * @throws IOException Signals that an I/O exception has occurred. */ public MtasDataBasic(String collectorType, String dataType, 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, MtasDataOperations<T1, T2> operations, String segmentRegistration, String boundary) throws IOException { <span class="fc" id="L71"> super(collectorType, dataType, CodecUtil.STATS_BASIC, statsItems, sortType,</span> sortDirection, start, number, subCollectorTypes, subDataTypes, subStatsTypes, subStatsItems, subSortTypes, subSortDirections, subStart, subNumber, segmentRegistration, boundary); <span class="fc" id="L75"> this.operations = operations;</span> <span class="fc" id="L76"> }</span> /* * (non-Javadoc) * * @see * mtas.codec.util.DataCollector.MtasDataCollector#error(java.lang.String) */ @Override public final void error(String error) throws IOException { <span class="nc" id="L86"> add(false);</span> <span class="nc" id="L87"> setError(newCurrentPosition, error, newCurrentExisting);</span> <span class="nc" id="L88"> }</span> /* * (non-Javadoc) * * @see * mtas.codec.util.DataCollector.MtasDataCollector#error(java.lang.String[], * java.lang.String) */ @Override public final void error(String key, String error) throws IOException { <span class="nc bnc" id="L99" title="All 2 branches missed."> if (key != null) {</span> <span class="nc" id="L100"> add(key, false);</span> <span class="nc" id="L101"> setError(newCurrentPosition, error, newCurrentExisting);</span> } <span class="nc" id="L103"> }</span> /** * Sets the error. * * @param newPosition the new position * @param error the error * @param currentExisting the current existing */ protected void setError(int newPosition, String error, boolean currentExisting) { <span class="nc bnc" id="L114" title="All 2 branches missed."> if (!currentExisting) {</span> <span class="nc" id="L115"> newBasicValueSumList[newPosition] = operations.getZero1();</span> <span class="nc" id="L116"> newBasicValueNList[newPosition] = 0;</span> } <span class="nc" id="L118"> newErrorNumber[newPosition]++;</span> <span class="nc bnc" id="L119" title="All 2 branches missed."> if (newErrorList[newPosition].containsKey(error)) {</span> <span class="nc" id="L120"> newErrorList[newPosition].put(error,</span> <span class="nc" id="L121"> newErrorList[newPosition].get(error) + 1);</span> } else { <span class="nc" id="L123"> newErrorList[newPosition].put(error, 1);</span> } <span class="nc" id="L125"> }</span> /** * Sets the value. * * @param newPosition the new position * @param valueSum the value sum * @param valueN the value N * @param currentExisting the current existing */ protected void setValue(int newPosition, T1 valueSum, long valueN, boolean currentExisting) { <span class="pc bpc" id="L137" title="1 of 2 branches missed."> if (valueN > 0) {</span> <span class="fc bfc" id="L138" title="All 2 branches covered."> if (currentExisting) {</span> <span class="fc" id="L139"> newBasicValueSumList[newPosition] = operations</span> <span class="fc" id="L140"> .add11(newBasicValueSumList[newPosition], valueSum);</span> <span class="fc" id="L141"> newBasicValueNList[newPosition] += valueN;</span> } else { <span class="fc" id="L143"> newBasicValueSumList[newPosition] = valueSum;</span> <span class="fc" id="L144"> newBasicValueNList[newPosition] = valueN;</span> } } <span class="fc" id="L147"> }</span> /** * Sets the value. * * @param newPosition the new position * @param values the values * @param number the number * @param currentExisting the current existing */ protected void setValue(int newPosition, T1[] values, int number, boolean currentExisting) { <span class="pc bpc" id="L159" title="1 of 2 branches missed."> if (number > 0) {</span> <span class="fc" id="L160"> T1 valueSum = null;</span> <span class="fc bfc" id="L161" title="All 2 branches covered."> for (int i = 0; i < number; i++) {</span> <span class="fc bfc" id="L162" title="All 2 branches covered."> valueSum = (i == 0) ? values[i] : operations.add11(valueSum, values[i]);</span> } <span class="fc bfc" id="L164" title="All 2 branches covered."> if (currentExisting) {</span> <span class="fc" id="L165"> newBasicValueSumList[newPosition] = operations</span> <span class="fc" id="L166"> .add11(newBasicValueSumList[newPosition], valueSum);</span> <span class="fc" id="L167"> newBasicValueNList[newPosition] += number;</span> } else { <span class="fc" id="L169"> newBasicValueSumList[newPosition] = valueSum;</span> <span class="fc" id="L170"> newBasicValueNList[newPosition] = number;</span> } } <span class="fc" id="L173"> }</span> /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#increaseNewListSize() */ @Override protected final void increaseNewListSize() throws IOException { // register old situation <span class="fc" id="L183"> int tmpOldSize = newKeyList.length;</span> <span class="fc" id="L184"> int tmpNewPosition = newPosition;</span> // increase <span class="fc" id="L186"> super.increaseNewListSize();</span> // reconstruct <span class="fc" id="L188"> T1[] tmpNewBasicValueList = newBasicValueSumList;</span> <span class="fc" id="L189"> long[] tmpNewBasicValueNList = newBasicValueNList;</span> <span class="fc" id="L190"> newBasicValueSumList = operations.createVector1(newSize);</span> <span class="fc" id="L191"> newBasicValueNList = new long[newSize];</span> <span class="fc" id="L192"> newPosition = tmpNewPosition;</span> <span class="fc" id="L193"> System.arraycopy(tmpNewBasicValueList, 0, newBasicValueSumList, 0,</span> tmpOldSize); <span class="fc" id="L195"> System.arraycopy(tmpNewBasicValueNList, 0, newBasicValueNList, 0,</span> tmpOldSize); <span class="fc" id="L197"> }</span> /* * (non-Javadoc) * * @see mtas.codec.util.collector.MtasDataCollector#reduceToSegmentKeys() */ @Override public void reduceToSegmentKeys() { <span class="pc bpc" id="L206" title="2 of 4 branches missed."> if (segmentRegistration != null && size > 0) {</span> <span class="fc" id="L207"> int sizeCopy = size;</span> <span class="fc" id="L208"> String[] keyListCopy = keyList.clone();</span> <span class="fc" id="L209"> T1[] basicValueSumListCopy = basicValueSumList.clone();</span> <span class="fc" id="L210"> long[] basicValueNListCopy = basicValueNList.clone();</span> <span class="fc" id="L211"> size = 0;</span> <span class="fc bfc" id="L212" title="All 2 branches covered."> for (int i = 0; i < sizeCopy; i++) {</span> <span class="fc bfc" id="L213" title="All 2 branches covered."> if (segmentKeys.contains(keyListCopy[i])) {</span> <span class="fc" id="L214"> keyList[size] = keyListCopy[i];</span> <span class="fc" id="L215"> basicValueSumList[size] = basicValueSumListCopy[i];</span> <span class="fc" id="L216"> basicValueNList[size] = basicValueNListCopy[i];</span> <span class="fc" id="L217"> size++;</span> } } } <span class="fc" id="L221"> }</span> /* * (non-Javadoc) * * @see * mtas.codec.util.collector.MtasDataCollector#reduceToKeys(java.util.Set) */ @SuppressWarnings("unchecked") public void reduceToKeys(Set<String> keys) { <span class="pc bpc" id="L231" title="1 of 2 branches missed."> if (size > 0) {</span> <span class="fc" id="L232"> int sizeCopy = size;</span> <span class="fc" id="L233"> String[] keyListCopy = keyList.clone();</span> <span class="fc" id="L234"> int[] errorNumberCopy = errorNumber.clone();</span> <span class="fc" id="L235"> HashMap<String, Integer>[] errorListCopy = errorList.clone();</span> <span class="fc" id="L236"> int[] sourceNumberListCopy = sourceNumberList.clone();</span> <span class="fc" id="L237"> T1[] basicValueSumListCopy = basicValueSumList.clone();</span> <span class="fc" id="L238"> long[] basicValueNListCopy = basicValueNList.clone();</span> <span class="fc" id="L239"> keyList = new String[keys.size()];</span> <span class="fc" id="L240"> errorNumber = new int[keys.size()];</span> <span class="fc" id="L241"> errorList = new HashMap[keys.size()];</span> <span class="fc" id="L242"> sourceNumberList = new int[keys.size()];</span> <span class="fc" id="L243"> basicValueSumList = operations.createVector1(keys.size());</span> <span class="fc" id="L244"> basicValueNList = new long[keys.size()];</span> <span class="fc" id="L245"> size = 0;</span> <span class="fc bfc" id="L246" title="All 2 branches covered."> for (int i = 0; i < sizeCopy; i++) {</span> <span class="fc bfc" id="L247" title="All 2 branches covered."> if (keys.contains(keyListCopy[i])) {</span> <span class="fc" id="L248"> keyList[size] = keyListCopy[i];</span> <span class="fc" id="L249"> errorNumber[size] = errorNumberCopy[i];</span> <span class="fc" id="L250"> errorList[size] = errorListCopy[i];</span> <span class="fc" id="L251"> sourceNumberList[size] = sourceNumberListCopy[i];</span> <span class="fc" id="L252"> basicValueSumList[size] = basicValueSumListCopy[i];</span> <span class="fc" id="L253"> basicValueNList[size] = basicValueNListCopy[i];</span> <span class="fc" id="L254"> size++;</span> } } } <span class="fc" id="L258"> }</span> /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#copyToNew(int, int) */ @Override protected void copyToNew(int position, int newPosition) { <span class="fc" id="L267"> newBasicValueSumList[newPosition] = basicValueSumList[position];</span> <span class="fc" id="L268"> newBasicValueNList[newPosition] = basicValueNList[position];</span> <span class="fc" id="L269"> }</span> /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#copyFromNew() */ @Override protected void copyFromNew() { <span class="fc" id="L278"> basicValueSumList = newBasicValueSumList;</span> <span class="fc" id="L279"> basicValueNList = newBasicValueNList;</span> <span class="fc" id="L280"> }</span> /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#remapData(int[][]) */ @Override protected void remapData(int[][] mapping) throws IOException { <span class="fc" id="L289"> super.remapData(mapping);</span> <span class="fc" id="L290"> T1[] originalBasicValueSumList = basicValueSumList.clone();</span> <span class="fc" id="L291"> long[] originalBasicValueNList = basicValueNList.clone();</span> <span class="fc" id="L292"> basicValueSumList = operations.createVector1(mapping.length);</span> <span class="fc" id="L293"> basicValueNList = new long[mapping.length];</span> <span class="fc bfc" id="L294" title="All 2 branches covered."> for (int i = 0; i < mapping.length; i++) {</span> <span class="fc bfc" id="L295" title="All 2 branches covered."> for (int j = 0; j < mapping[i].length; j++) {</span> <span class="fc bfc" id="L296" title="All 2 branches covered."> if (j == 0) {</span> <span class="fc" id="L297"> setValue(i, originalBasicValueSumList[mapping[i][j]],</span> originalBasicValueNList[mapping[i][j]], false); } else { <span class="fc" id="L300"> setValue(i, originalBasicValueSumList[mapping[i][j]],</span> originalBasicValueNList[mapping[i][j]], true); } } } <span class="fc" id="L305"> basicValueSumList = newBasicValueSumList;</span> <span class="fc" id="L306"> basicValueNList = newBasicValueNList;</span> <span class="fc" id="L307"> }</span> /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#merge(mtas.codec.util. * DataCollector.MtasDataCollector) */ @Override public void merge(MtasDataCollector<?, ?> newDataCollector, Map<MtasDataCollector<?, ?>, MtasDataCollector<?, ?>> map, boolean increaseSourceNumber) throws IOException { <span class="nc" id="L319"> closeNewList();</span> <span class="nc bnc" id="L320" title="All 2 branches missed."> if (!collectorType.equals(newDataCollector.getCollectorType())</span> <span class="nc bnc" id="L321" title="All 2 branches missed."> || !dataType.equals(newDataCollector.getDataType())</span> <span class="nc bnc" id="L322" title="All 4 branches missed."> || !statsType.equals(newDataCollector.getStatsType())</span> || !(newDataCollector instanceof MtasDataBasic)) { <span class="nc" id="L324"> throw new IOException("cannot merge different dataCollectors");</span> } else { <span class="nc" id="L326"> segmentRegistration = null;</span> @SuppressWarnings("unchecked") <span class="nc" id="L328"> MtasDataBasic<T1, T2> newMtasDataBasic = (MtasDataBasic<T1, T2>) newDataCollector;</span> <span class="nc" id="L329"> newMtasDataBasic.closeNewList();</span> <span class="nc" id="L330"> initNewList(newMtasDataBasic.getSize());</span> <span class="nc bnc" id="L331" title="All 2 branches missed."> if (collectorType.equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span> <span class="nc" id="L332"> map.put(newDataCollector, this);</span> <span class="nc bnc" id="L333" title="All 2 branches missed."> for (int i = 0; i < newMtasDataBasic.getSize(); i++) {</span> <span class="nc" id="L334"> MtasDataCollector<?, ?>[] subCollectors = new MtasDataCollector[1];</span> <span class="nc" id="L335"> subCollectors[0] = add(newMtasDataBasic.keyList[i],</span> increaseSourceNumber); <span class="nc" id="L337"> setError(newCurrentPosition, newMtasDataBasic.errorNumber[i],</span> newMtasDataBasic.errorList[i], newCurrentExisting); <span class="nc" id="L339"> setValue(newCurrentPosition, newMtasDataBasic.basicValueSumList[i],</span> newMtasDataBasic.basicValueNList[i], newCurrentExisting); <span class="nc bnc" id="L341" title="All 4 branches missed."> if (hasSub() && newMtasDataBasic.hasSub()) {</span> // single key implies exactly one subCollector if hasSub <span class="nc" id="L343"> subCollectors[0].merge(</span> newMtasDataBasic.subCollectorListNextLevel[i], map, increaseSourceNumber); } } <span class="nc" id="L348"> closeNewList();</span> <span class="nc bnc" id="L349" title="All 2 branches missed."> } else if (collectorType.equals(DataCollector.COLLECTOR_TYPE_DATA)) {</span> <span class="nc" id="L350"> map.put(newDataCollector, this);</span> <span class="nc bnc" id="L351" title="All 2 branches missed."> if (newMtasDataBasic.getSize() > 0) {</span> <span class="nc" id="L352"> MtasDataCollector<?, ?> subCollector = add(increaseSourceNumber);</span> <span class="nc" id="L353"> setError(newCurrentPosition, newMtasDataBasic.errorNumber[0],</span> newMtasDataBasic.errorList[0], newCurrentExisting); <span class="nc" id="L355"> setValue(newCurrentPosition, newMtasDataBasic.basicValueSumList[0],</span> newMtasDataBasic.basicValueNList[0], newCurrentExisting); <span class="nc bnc" id="L357" title="All 4 branches missed."> if (hasSub() && newMtasDataBasic.hasSub()) {</span> <span class="nc" id="L358"> subCollector.merge(newMtasDataBasic.subCollectorNextLevel, map,</span> increaseSourceNumber); } } <span class="nc" id="L362"> closeNewList();</span> } else { <span class="nc" id="L364"> throw new IOException("cannot merge " + collectorType);</span> } } <span class="nc" id="L367"> }</span> /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#initNewList(int) */ @Override public final void initNewList(int maxNumberOfTerms) throws IOException { <span class="fc" id="L376"> super.initNewList(maxNumberOfTerms);</span> <span class="fc" id="L377"> initNewListBasic(maxNumberOfTerms);</span> <span class="fc" id="L378"> }</span> /* * (non-Javadoc) * * @see mtas.codec.util.DataCollector.MtasDataCollector#initNewList(int, * java.lang.String) */ @Override public final void initNewList(int maxNumberOfTerms, String segmentName, int segmentNumber, String boundary) throws IOException { <span class="fc" id="L389"> super.initNewList(maxNumberOfTerms, segmentName, segmentNumber, boundary);</span> <span class="fc" id="L390"> initNewListBasic(maxNumberOfTerms);</span> <span class="fc" id="L391"> }</span> /** * Inits the new list basic. * * @param maxNumberOfTerms the max number of terms */ private void initNewListBasic(int maxNumberOfTerms) { <span class="fc" id="L399"> newBasicValueSumList = operations.createVector1(newSize);</span> <span class="fc" id="L400"> newBasicValueNList = new long[newSize];</span> <span class="fc" id="L401"> }</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>