IntervalTree.java.html 4.57 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>IntervalTree.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.tree</a> &gt; <span class="el_source">IntervalTree.java</span></div><h1>IntervalTree.java</h1><pre class="source lang-java linenums">package mtas.codec.tree;

import java.util.ArrayList;
import mtas.codec.util.CodecSearchTree.MtasTreeHit;

/**
 * The Class IntervalTree.
 *
 * @param &lt;T&gt; the generic type
 * @param &lt;N&gt; the number type
 */
abstract public class IntervalTree&lt;T, N extends IntervalTreeNode&lt;T, N&gt;&gt; {

  /** The root. */
  protected N root;

  /** The current. */
  protected N current;

  /**
   * Instantiates a new interval tree.
   */
<span class="fc" id="L23">  public IntervalTree() {</span>
<span class="fc" id="L24">    root = null;</span>
<span class="fc" id="L25">  }</span>

  /**
   * Close.
   *
   * @return the n
   */
  final public N close() {
<span class="pc bpc" id="L33" title="1 of 2 branches missed.">    if (root == null) {</span>
<span class="nc" id="L34">      addRangeEmpty(0, 0);</span>
    }
<span class="fc" id="L36">    return root;</span>
  }

  /**
   * Adds the single point.
   *
   * @param position the position
   * @param list the list
   */
  abstract protected void addSinglePoint(int position,
      ArrayList&lt;MtasTreeHit&lt;T&gt;&gt; list);

  /**
   * Adds the range.
   *
   * @param left the left
   * @param right the right
   * @param list the list
   */
  abstract protected void addRange(int left, int right,
      ArrayList&lt;MtasTreeHit&lt;T&gt;&gt; list);

  /**
   * Adds the range empty.
   *
   * @param left the left
   * @param right the right
   */
  abstract protected void addRangeEmpty(int left, int right);

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString() {
<span class="nc" id="L73">    return printBalance(1, root);</span>
  }

  /**
   * Prints the balance.
   *
   * @param p the p
   * @param n the n
   * @return the string
   */
  final private String printBalance(Integer p, N n) {
<span class="nc" id="L84">    StringBuilder text = new StringBuilder();</span>
<span class="nc bnc" id="L85" title="All 2 branches missed.">    if (n != null) {</span>
<span class="nc" id="L86">      text.append(printBalance((p + 1), n.leftChild));</span>
<span class="nc" id="L87">      String format = &quot;%&quot; + (3 * p) + &quot;s&quot;;</span>
<span class="nc" id="L88">      text.append(String.format(format, &quot;&quot;));</span>
<span class="nc bnc" id="L89" title="All 2 branches missed.">      if (n.left == n.right) {</span>
<span class="nc" id="L90">        text.append(&quot;[&quot; + n.left + &quot;] (&quot; + n.max + &quot;) : &quot; + n.lists.size()</span>
            + &quot; lists\n&quot;);
      } else {
<span class="nc" id="L93">        text.append(&quot;[&quot; + n.left + &quot;-&quot; + n.right + &quot;] (&quot; + n.max + &quot;) : &quot;</span>
<span class="nc" id="L94">            + n.lists.size() + &quot; lists\n&quot;);</span>
      }
<span class="nc" id="L96">      text.append(printBalance((p + 1), n.rightChild));</span>
    }
<span class="nc" id="L98">    return text.toString();</span>
  }

  /**
   * Gets the root.
   *
   * @return the root
   */
  final public N getRoot() {
<span class="fc" id="L107">    return root;</span>
  }

  /**
   * Gets the current.
   *
   * @return the current
   */
  final public N getCurrent() {
<span class="nc" id="L116">    return current;</span>
  }

  /**
   * Sets the current.
   *
   * @param node the new current
   */
  final public void setCurrent(N node) {
<span class="nc" id="L125">    current = node;</span>
<span class="nc" id="L126">  }</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>