|
1
|
<?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;
|
|
2
3
4
5
6
7
|
import java.io.IOException;
import java.io.Serializable;
import mtas.codec.util.CodecUtil;
|
|
8
9
10
11
12
|
/**
* The Class MtasDataItemNumberComparator.
*
* @param <T> the generic type
*/
|
|
13
14
15
16
17
18
19
20
21
|
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;
|
|
22
|
/** The sort direction. */
|
|
23
24
25
|
String sortDirection;
/**
|
|
26
|
* Instantiates a new mtas data item number comparator.
|
|
27
|
*
|
|
28
29
|
* @param value the value
* @param sortDirection the sort direction
|
|
30
|
*/
|
|
31
32
33
34
|
<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>
|
|
35
36
37
38
39
40
41
42
|
/*
* (non-Javadoc)
*
* @see java.lang.Object#clone()
*/
@Override
public MtasDataItemNumberComparator<T> clone() {
|
|
43
|
<span class="fc" id="L43"> return new MtasDataItemNumberComparator<>(this.value, this.sortDirection);</span>
|
|
44
45
46
47
48
49
50
51
52
|
}
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(T compareValue) {
|
|
53
|
<span class="fc" id="L53"> return value.compareTo(compareValue);</span>
|
|
54
55
56
57
58
59
60
61
|
}
/**
* Gets the value.
*
* @return the value
*/
public T getValue() {
|
|
62
|
<span class="fc" id="L62"> return value;</span>
|
|
63
64
65
66
67
68
69
70
|
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
|
|
71
|
<span class="nc" id="L71"> return value.toString();</span>
|
|
72
73
74
75
76
|
}
/**
* Adds the.
*
|
|
77
78
|
* @param newValue the new value
* @throws IOException Signals that an I/O exception has occurred.
|
|
79
80
81
|
*/
@SuppressWarnings("unchecked")
public void add(T newValue) throws IOException {
|
|
82
83
84
85
86
87
88
89
|
<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>
|
|
90
|
} else {
|
|
91
|
<span class="nc" id="L91"> throw new IOException("incompatible NumberComparators");</span>
|
|
92
|
}
|
|
93
|
<span class="fc" id="L93"> }</span>
|
|
94
95
96
97
|
/**
* Subtract.
*
|
|
98
99
|
* @param newValue the new value
* @throws IOException Signals that an I/O exception has occurred.
|
|
100
101
102
|
*/
@SuppressWarnings("unchecked")
public void subtract(T newValue) throws IOException {
|
|
103
104
105
106
107
108
109
110
|
<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>
|
|
111
|
} else {
|
|
112
|
<span class="nc" id="L112"> throw new IOException("incompatible NumberComparators");</span>
|
|
113
|
}
|
|
114
|
<span class="nc" id="L114"> }</span>
|
|
115
116
117
118
|
/**
* Recompute boundary.
*
|
|
119
120
121
|
* @param n the n
* @return the mtas data item number comparator
* @throws IOException Signals that an I/O exception has occurred.
|
|
122
123
124
|
*/
public MtasDataItemNumberComparator<T> recomputeBoundary(int n)
throws IOException {
|
|
125
126
|
<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>
|
|
127
128
|
<span class="nc" id="L127"> return new MtasDataItemNumberComparator(</span>
<span class="nc" id="L128"> Math.floorDiv((Integer) value, n), sortDirection);</span>
|
|
129
130
|
<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>
|
|
131
132
133
134
135
136
137
138
139
140
|
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>
}
|
|
141
142
|
<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>
|
|
143
144
145
146
|
} else {
<span class="nc" id="L144"> throw new IOException("unknown sortDirection " + sortDirection);</span>
}
}
|
|
147
148
149
150
|
/*
* (non-Javadoc)
*
|
|
151
152
|
* @see java.lang.Object#equals(java.lang.Object)
*/
|
|
153
154
|
@Override
public boolean equals(Object obj) {
|
|
155
156
157
|
<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>
|
|
158
|
<span class="nc" id="L158"> return false;</span>
|
|
159
160
161
162
|
<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>
|
|
163
|
}
|
|
164
165
166
167
|
/*
* (non-Javadoc)
*
|
|
168
169
|
* @see java.lang.Object#hashCode()
*/
|
|
170
171
|
@Override
public int hashCode() {
|
|
172
173
174
|
<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>
|
|
175
176
177
|
}
}
|
|
178
|
</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>
|