<?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>MtasDataItemNumberComparator.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">MtasDataItemNumberComparator.java</span></div><h1>MtasDataItemNumberComparator.java</h1><pre class="source lang-java linenums">package mtas.codec.util.collector; import java.io.IOException; import java.io.Serializable; import mtas.codec.util.CodecUtil; /** * The Class MtasDataItemNumberComparator. * * @param <T> the generic type */ public final class MtasDataItemNumberComparator<T extends Number & Comparable<T>> implements Comparable<T>, Serializable, Cloneable { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; /** The value. */ T value; /** The sort direction. */ String sortDirection; /** * Instantiates a new mtas data item number comparator. * * @param value the value * @param sortDirection the sort direction */ <span class="fc" id="L31"> public MtasDataItemNumberComparator(T value, String sortDirection) {</span> <span class="fc" id="L32"> this.value = value;</span> <span class="fc" id="L33"> this.sortDirection = sortDirection;</span> <span class="fc" id="L34"> }</span> /* * (non-Javadoc) * * @see java.lang.Object#clone() */ @Override public MtasDataItemNumberComparator<T> clone() { <span class="fc" id="L43"> return new MtasDataItemNumberComparator<>(this.value, this.sortDirection);</span> } /* * (non-Javadoc) * * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override public int compareTo(T compareValue) { <span class="fc" id="L53"> return value.compareTo(compareValue);</span> } /** * Gets the value. * * @return the value */ public T getValue() { <span class="fc" id="L62"> return value;</span> } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ public String toString() { <span class="nc" id="L71"> return value.toString();</span> } /** * Adds the. * * @param newValue the new value * @throws IOException Signals that an I/O exception has occurred. */ @SuppressWarnings("unchecked") public void add(T newValue) throws IOException { <span class="pc bpc" id="L82" title="3 of 4 branches missed."> if (value instanceof Integer && newValue instanceof Integer) {</span> <span class="nc" id="L83"> value = (T) Integer.valueOf(value.intValue() + newValue.intValue());</span> <span class="pc bpc" id="L84" title="2 of 4 branches missed."> } else if (value instanceof Long && newValue instanceof Long) {</span> <span class="fc" id="L85"> value = (T) Long.valueOf(value.longValue() + newValue.longValue());</span> <span class="nc bnc" id="L86" title="All 4 branches missed."> } else if (value instanceof Float && newValue instanceof Float) {</span> <span class="nc" id="L87"> value = (T) Float.valueOf(value.floatValue() + newValue.floatValue());</span> <span class="nc bnc" id="L88" title="All 4 branches missed."> } else if (value instanceof Double && newValue instanceof Double) {</span> <span class="nc" id="L89"> value = (T) Double.valueOf(value.doubleValue() + newValue.longValue());</span> } else { <span class="nc" id="L91"> throw new IOException("incompatible NumberComparators");</span> } <span class="fc" id="L93"> }</span> /** * Subtract. * * @param newValue the new value * @throws IOException Signals that an I/O exception has occurred. */ @SuppressWarnings("unchecked") public void subtract(T newValue) throws IOException { <span class="nc bnc" id="L103" title="All 4 branches missed."> if (value instanceof Integer && newValue instanceof Integer) {</span> <span class="nc" id="L104"> value = (T) Integer.valueOf(value.intValue() - newValue.intValue());</span> <span class="nc bnc" id="L105" title="All 4 branches missed."> } else if (value instanceof Long && newValue instanceof Long) {</span> <span class="nc" id="L106"> value = (T) Long.valueOf(value.longValue() - newValue.longValue());</span> <span class="nc bnc" id="L107" title="All 4 branches missed."> } else if (value instanceof Float && newValue instanceof Float) {</span> <span class="nc" id="L108"> value = (T) Float.valueOf(value.floatValue() - newValue.floatValue());</span> <span class="nc bnc" id="L109" title="All 4 branches missed."> } else if (value instanceof Double && newValue instanceof Double) {</span> <span class="nc" id="L110"> value = (T) Double.valueOf(value.doubleValue() - newValue.longValue());</span> } else { <span class="nc" id="L112"> throw new IOException("incompatible NumberComparators");</span> } <span class="nc" id="L114"> }</span> /** * Recompute boundary. * * @param n the n * @return the mtas data item number comparator * @throws IOException Signals that an I/O exception has occurred. */ public MtasDataItemNumberComparator<T> recomputeBoundary(int n) throws IOException { <span class="fc bfc" id="L125" title="All 2 branches covered."> if (sortDirection.equals(CodecUtil.SORT_DESC)) {</span> <span class="pc bpc" id="L126" title="1 of 2 branches missed."> if (value instanceof Integer) {</span> <span class="nc" id="L127"> return new MtasDataItemNumberComparator(</span> <span class="nc" id="L128"> Math.floorDiv((Integer) value, n), sortDirection);</span> <span class="pc bpc" id="L129" title="1 of 2 branches missed."> } else if (value instanceof Long) {</span> <span class="fc" id="L130"> return new MtasDataItemNumberComparator(Math.floorDiv((Long) value, n),</span> sortDirection); <span class="nc bnc" id="L132" title="All 2 branches missed."> } else if (value instanceof Float) {</span> <span class="nc" id="L133"> return new MtasDataItemNumberComparator(((Float) value) / n,</span> sortDirection); <span class="nc bnc" id="L135" title="All 2 branches missed."> } else if (value instanceof Double) {</span> <span class="nc" id="L136"> return new MtasDataItemNumberComparator(((Double) value) / n,</span> sortDirection); } else { <span class="nc" id="L139"> throw new IOException("unknown NumberComparator");</span> } <span class="pc bpc" id="L141" title="1 of 2 branches missed."> } else if (sortDirection.equals(CodecUtil.SORT_ASC)) {</span> <span class="fc" id="L142"> return new MtasDataItemNumberComparator(getValue(), sortDirection);</span> } else { <span class="nc" id="L144"> throw new IOException("unknown sortDirection " + sortDirection);</span> } } /* * (non-Javadoc) * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { <span class="nc bnc" id="L155" title="All 2 branches missed."> if (this == obj)</span> <span class="nc" id="L156"> return true;</span> <span class="nc bnc" id="L157" title="All 2 branches missed."> if (obj == null)</span> <span class="nc" id="L158"> return false;</span> <span class="nc bnc" id="L159" title="All 2 branches missed."> if (getClass() != obj.getClass())</span> <span class="nc" id="L160"> return false;</span> <span class="nc" id="L161"> MtasDataItemNumberComparator<?> that = (MtasDataItemNumberComparator<?>) obj;</span> <span class="nc" id="L162"> return value.equals(that.value);</span> } /* * (non-Javadoc) * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { <span class="nc" id="L172"> int h = this.getClass().getSimpleName().hashCode();</span> <span class="nc" id="L173"> h = (h * 7) ^ value.hashCode();</span> <span class="nc" id="L174"> return h;</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>