MtasDataItemNumberComparator.java.html
8.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?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="L153" title="All 2 branches missed."> if (this == obj)</span>
<span class="nc" id="L154"> return true;</span>
<span class="nc bnc" id="L155" title="All 2 branches missed."> if (obj == null)</span>
<span class="nc" id="L156"> return false;</span>
<span class="nc bnc" id="L157" title="All 2 branches missed."> if (getClass() != obj.getClass())</span>
<span class="nc" id="L158"> return false;</span>
<span class="nc" id="L159"> MtasDataItemNumberComparator<?> that = (MtasDataItemNumberComparator<?>) obj;</span>
<span class="nc" id="L160"> return value.equals(that.value);</span>
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
<span class="nc" id="L168"> int h = this.getClass().getSimpleName().hashCode();</span>
<span class="nc" id="L169"> h = (h * 7) ^ value.hashCode();</span>
<span class="nc" id="L170"> 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>