MtasDataFull.java.html 18.8 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>MtasDataFull.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">MtasDataFull.java</span></div><h1>MtasDataFull.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 MtasDataFull.
 *
 * @param &lt;T1&gt; the generic type
 * @param &lt;T2&gt; the generic type
 */
abstract class MtasDataFull&lt;T1 extends Number &amp; Comparable&lt;T1&gt;, T2 extends Number &amp; Comparable&lt;T2&gt;&gt;
    extends MtasDataCollector&lt;T1, T2&gt; implements Serializable {

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

  /** The full value list. */
<span class="fc" id="L26">  protected T1[][] fullValueList = null;</span>
  
  /** The new full value list. */
<span class="fc" id="L29">  protected T1[][] newFullValueList = null;</span>

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

  /**
   * Instantiates a new mtas data full.
   *
   * @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 MtasDataFull(String collectorType, String dataType,
      SortedSet&lt;String&gt; statsItems, String sortType, String sortDirection,
      Integer start, Integer number, String[] subCollectorTypes,
      String[] subDataTypes, String[] subStatsTypes,
      SortedSet&lt;String&gt;[] subStatsItems, String[] subSortTypes,
      String[] subSortDirections, Integer[] subStart, Integer[] subNumber,
      MtasDataOperations&lt;T1, T2&gt; operations, String segmentRegistration,
      String boundary) throws IOException {
<span class="fc" id="L65">    super(collectorType, dataType, CodecUtil.STATS_FULL, statsItems, sortType,</span>
        sortDirection, start, number, subCollectorTypes, subDataTypes,
        subStatsTypes, subStatsItems, subSortTypes, subSortDirections, subStart,
        subNumber, segmentRegistration, boundary);
<span class="fc" id="L69">    this.operations = operations;</span>
<span class="fc" id="L70">  }</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="L80">    add(false);</span>
<span class="nc" id="L81">    setError(newCurrentPosition, error, newCurrentExisting);</span>
<span class="nc" id="L82">  }</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="L93" title="All 2 branches missed.">    if (key != null) {</span>
<span class="nc" id="L94">      add(key, false);</span>
<span class="nc" id="L95">      setError(newCurrentPosition, error, newCurrentExisting);      </span>
    }
<span class="nc" id="L97">  }</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="L108" title="All 2 branches missed.">    if (!currentExisting) {</span>
<span class="nc" id="L109">      newFullValueList[newPosition] = operations.createVector1(0);</span>
    }
<span class="nc" id="L111">    newErrorNumber[newPosition]++;</span>
<span class="nc bnc" id="L112" title="All 2 branches missed.">    if (newErrorList[newPosition].containsKey(error)) {</span>
<span class="nc" id="L113">      newErrorList[newPosition].put(error,</span>
<span class="nc" id="L114">          newErrorList[newPosition].get(error) + 1);</span>
    } else {
<span class="nc" id="L116">      newErrorList[newPosition].put(error, 1);</span>
    }
<span class="nc" id="L118">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.DataCollector.MtasDataCollector#increaseNewListSize()
   */
  @Override
  protected final void increaseNewListSize() throws IOException {
    // register old situation
<span class="nc" id="L128">    int tmpOldSize = newKeyList.length;</span>
<span class="nc" id="L129">    int tmpNewPosition = newPosition;</span>
    // increase
<span class="nc" id="L131">    super.increaseNewListSize();</span>
    // reconstruct
<span class="nc" id="L133">    T1[][] tmpNewFullValueList = newFullValueList;</span>
<span class="nc" id="L134">    newFullValueList = operations.createMatrix1(newSize);</span>
<span class="nc" id="L135">    newPosition = tmpNewPosition;</span>
<span class="nc" id="L136">    System.arraycopy(tmpNewFullValueList, 0, newFullValueList, 0, tmpOldSize);</span>
<span class="nc" id="L137">  }</span>

  /* (non-Javadoc)
   * @see mtas.codec.util.collector.MtasDataCollector#reduceToSegmentKeys()
   */
  @Override
  public void reduceToSegmentKeys() {
<span class="nc bnc" id="L144" title="All 4 branches missed.">    if (segmentRegistration != null &amp;&amp; size &gt; 0) {</span>
<span class="nc" id="L145">      int sizeCopy = size;</span>
<span class="nc" id="L146">      String[] keyListCopy = keyList.clone();</span>
<span class="nc" id="L147">      T1[][] fullValueListCopy = fullValueList.clone();</span>
<span class="nc" id="L148">      size = 0;</span>
<span class="nc bnc" id="L149" title="All 2 branches missed.">      for (int i = 0; i &lt; sizeCopy; i++) {</span>
<span class="nc bnc" id="L150" title="All 2 branches missed.">        if (segmentKeys.contains(keyListCopy[i])) {</span>
<span class="nc" id="L151">          keyList[size] = keyListCopy[i];</span>
<span class="nc" id="L152">          fullValueList[size] = fullValueListCopy[i];</span>
<span class="nc" id="L153">          size++;</span>
        }
      }
    }
<span class="nc" id="L157">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.codec.util.collector.MtasDataCollector#reduceToKeys(java.util.Set)
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  public void reduceToKeys(Set&lt;String&gt; keys) {
<span class="nc bnc" id="L167" title="All 2 branches missed.">    if (size &gt; 0) {</span>
<span class="nc" id="L168">      int sizeCopy = size;</span>
<span class="nc" id="L169">      String[] keyListCopy = keyList.clone();</span>
<span class="nc" id="L170">      int[] errorNumberCopy = errorNumber.clone();</span>
<span class="nc" id="L171">      HashMap&lt;String, Integer&gt;[] errorListCopy = errorList.clone();</span>
<span class="nc" id="L172">      int[] sourceNumberListCopy = sourceNumberList.clone();</span>
<span class="nc" id="L173">      T1[][] fullValueListCopy = fullValueList.clone();</span>
<span class="nc bnc" id="L174" title="All 2 branches missed.">      for (int i = 0; i &lt; fullValueListCopy.length; i++) {</span>
<span class="nc bnc" id="L175" title="All 2 branches missed.">        if (fullValueListCopy[i] != null) {</span>
<span class="nc" id="L176">          fullValueListCopy[i] = fullValueListCopy[i].clone();</span>
        }
      }
<span class="nc" id="L179">      keyList = new String[keys.size()];</span>
<span class="nc" id="L180">      errorNumber = new int[keys.size()];</span>
<span class="nc" id="L181">      errorList = new HashMap[keys.size()];</span>
<span class="nc" id="L182">      sourceNumberList = new int[keys.size()];</span>
<span class="nc" id="L183">      fullValueList = operations.createMatrix1(keys.size());</span>
<span class="nc" id="L184">      size = 0;</span>
<span class="nc bnc" id="L185" title="All 2 branches missed.">      for (int i = 0; i &lt; sizeCopy; i++) {</span>
<span class="nc bnc" id="L186" title="All 2 branches missed.">        if (keys.contains(keyListCopy[i])) {</span>
<span class="nc" id="L187">          keyList[size] = keyListCopy[i];</span>
<span class="nc" id="L188">          errorNumber[size] = errorNumberCopy[i];</span>
<span class="nc" id="L189">          errorList[size] = errorListCopy[i];</span>
<span class="nc" id="L190">          sourceNumberList[size] = sourceNumberListCopy[i];</span>
<span class="nc" id="L191">          fullValueList[size] = fullValueListCopy[i];</span>
<span class="nc" id="L192">          size++;</span>
        }
      }
    }
<span class="nc" id="L196">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.DataCollector.MtasDataCollector#copyToNew(int, int)
   */
  @Override
  protected void copyToNew(int position, int newPosition) {
<span class="fc" id="L205">    newFullValueList[newPosition] = fullValueList[position];</span>
<span class="fc" id="L206">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.DataCollector.MtasDataCollector#copyFromNew()
   */
  @Override
  protected void copyFromNew() {
<span class="fc" id="L215">    fullValueList = newFullValueList;</span>
<span class="fc" id="L216">  }</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="L228" title="1 of 2 branches missed.">    if (number &gt; 0) {</span>
<span class="fc bfc" id="L229" title="All 2 branches covered.">      if (currentExisting) {</span>
<span class="fc" id="L230">        T1[] tmpList = operations</span>
<span class="fc" id="L231">            .createVector1(newFullValueList[newPosition].length + number);</span>
<span class="fc" id="L232">        System.arraycopy(newFullValueList[newPosition], 0, tmpList, 0,</span>
            newFullValueList[newPosition].length);
<span class="fc" id="L234">        System.arraycopy(values, 0, tmpList,</span>
            newFullValueList[newPosition].length, number);
<span class="fc" id="L236">        newFullValueList[newPosition] = tmpList;</span>
<span class="fc" id="L237">      } else {</span>
<span class="pc bpc" id="L238" title="1 of 2 branches missed.">        if (number &lt; values.length) {</span>
<span class="nc" id="L239">          T1[] tmpList = operations.createVector1(number);</span>
<span class="nc" id="L240">          System.arraycopy(values, 0, tmpList, 0, number);</span>
<span class="nc" id="L241">          newFullValueList[newPosition] = tmpList;</span>
<span class="nc" id="L242">        } else {</span>
<span class="fc" id="L243">          newFullValueList[newPosition] = values;</span>
        }
      }
    }
<span class="fc" id="L247">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.DataCollector.MtasDataCollector#remapData(int[][])
   */
  @Override
  protected void remapData(int[][] mapping) throws IOException {
<span class="nc" id="L256">    super.remapData(mapping);</span>
<span class="nc" id="L257">    T1[][] originalFullValueList = fullValueList.clone();</span>
<span class="nc" id="L258">    fullValueList = operations.createMatrix1(mapping.length);</span>
<span class="nc bnc" id="L259" title="All 2 branches missed.">    for (int i = 0; i &lt; mapping.length; i++) {</span>
<span class="nc bnc" id="L260" title="All 2 branches missed.">      for (int j = 0; j &lt; mapping[i].length; j++) {</span>
<span class="nc bnc" id="L261" title="All 2 branches missed.">        if (j == 0) {</span>
<span class="nc" id="L262">          setValue(i, originalFullValueList[mapping[i][j]],</span>
              originalFullValueList[mapping[i][j]].length, false);
        } else {
<span class="nc" id="L265">          setValue(i, originalFullValueList[mapping[i][j]],</span>
              originalFullValueList[mapping[i][j]].length, true);
        }
      }
    }
<span class="nc" id="L270">    fullValueList = newFullValueList;</span>
<span class="nc" id="L271">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.DataCollector.MtasDataCollector#merge(mtas.codec.util.
   * DataCollector.MtasDataCollector)
   */
  @Override
  public void merge(MtasDataCollector&lt;?, ?&gt; newDataCollector,
      Map&lt;MtasDataCollector&lt;?, ?&gt;, MtasDataCollector&lt;?, ?&gt;&gt; map,
      boolean increaseSourceNumber) throws IOException {
<span class="nc" id="L283">    closeNewList();</span>
<span class="nc bnc" id="L284" title="All 2 branches missed.">    if (!collectorType.equals(newDataCollector.getCollectorType())</span>
<span class="nc bnc" id="L285" title="All 2 branches missed.">        || !dataType.equals(newDataCollector.getDataType())</span>
<span class="nc bnc" id="L286" title="All 4 branches missed.">        || !statsType.equals(newDataCollector.getStatsType())</span>
        || !(newDataCollector instanceof MtasDataFull)) {
<span class="nc" id="L288">      throw new IOException(&quot;cannot merge different dataCollectors&quot;);</span>
    } else {
<span class="nc" id="L290">      segmentRegistration = null;</span>
      @SuppressWarnings(&quot;unchecked&quot;)
<span class="nc" id="L292">      MtasDataFull&lt;T1, T2&gt; newMtasDataFull = (MtasDataFull&lt;T1, T2&gt;) newDataCollector;</span>
<span class="nc" id="L293">      closeNewList();</span>
<span class="nc" id="L294">      initNewList(newMtasDataFull.getSize());</span>
<span class="nc bnc" id="L295" title="All 2 branches missed.">      if (collectorType.equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span>
<span class="nc" id="L296">        map.put(newDataCollector, this);</span>
<span class="nc bnc" id="L297" title="All 2 branches missed.">        for (int i = 0; i &lt; newMtasDataFull.getSize(); i++) {</span>
<span class="nc bnc" id="L298" title="All 2 branches missed.">          if (newMtasDataFull.fullValueList[i].length &gt; 0) {</span>
<span class="nc" id="L299">            MtasDataCollector&lt;?, ?&gt;[] subCollectors = new MtasDataCollector&lt;?, ?&gt;[1];</span>
<span class="nc" id="L300">            subCollectors[0] = add(newMtasDataFull.keyList[i],</span>
                increaseSourceNumber);
<span class="nc" id="L302">            setError(newCurrentPosition, newMtasDataFull.errorNumber[i],</span>
                newMtasDataFull.errorList[i], newCurrentExisting);
<span class="nc" id="L304">            setValue(newCurrentPosition, newMtasDataFull.fullValueList[i],</span>
                newMtasDataFull.fullValueList[i].length, newCurrentExisting);
<span class="nc bnc" id="L306" title="All 4 branches missed.">            if (hasSub() &amp;&amp; newMtasDataFull.hasSub()) {</span>
              // single key implies exactly one subCollector if hasSub
<span class="nc" id="L308">              subCollectors[0].merge(</span>
                  newMtasDataFull.subCollectorListNextLevel[i], map,
                  increaseSourceNumber);
            }
          }
        }
<span class="nc bnc" id="L314" title="All 2 branches missed.">      } else if (collectorType.equals(DataCollector.COLLECTOR_TYPE_DATA)) {</span>
<span class="nc" id="L315">        map.put(newDataCollector, this);</span>
<span class="nc bnc" id="L316" title="All 2 branches missed.">        if (newMtasDataFull.getSize() &gt; 0) {</span>
<span class="nc" id="L317">          MtasDataCollector&lt;?, ?&gt; subCollector = add(increaseSourceNumber);</span>
<span class="nc" id="L318">          setError(newCurrentPosition, newMtasDataFull.errorNumber[0],</span>
              newMtasDataFull.errorList[0], newCurrentExisting);
<span class="nc" id="L320">          setValue(newCurrentPosition, newMtasDataFull.fullValueList[0],</span>
              newMtasDataFull.fullValueList[0].length, newCurrentExisting);
<span class="nc bnc" id="L322" title="All 4 branches missed.">          if (hasSub() &amp;&amp; newMtasDataFull.hasSub()) {</span>
<span class="nc" id="L323">            subCollector.merge(newMtasDataFull.subCollectorNextLevel, map,</span>
                increaseSourceNumber);
          }
<span class="nc" id="L326">        }</span>
      } else {
<span class="nc" id="L328">        throw new IOException(&quot;cannot merge &quot; + collectorType);</span>
      }
<span class="nc" id="L330">      closeNewList();</span>
    }
<span class="nc" id="L332">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.codec.util.DataCollector.MtasDataCollector#initNewList(int)
   */
  @Override
  public final void initNewList(int maxNumberOfTerms) throws IOException {
<span class="fc" id="L341">    super.initNewList(maxNumberOfTerms);</span>
<span class="fc" id="L342">    initNewListBasic(maxNumberOfTerms);</span>
<span class="fc" id="L343">  }</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="nc" id="L354">    super.initNewList(maxNumberOfTerms, segmentName, segmentNumber, boundary);</span>
<span class="nc" id="L355">    initNewListBasic(maxNumberOfTerms);</span>
<span class="nc" id="L356">  }</span>

  /**
   * Inits the new list basic.
   *
   * @param maxNumberOfTerms the max number of terms
   */
  private void initNewListBasic(int maxNumberOfTerms) {
<span class="fc" id="L364">    newFullValueList = operations.createMatrix1(newSize);</span>
<span class="fc" id="L365">  }</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>