MtasDataItemDoubleFull.java.html
16.9 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?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>MtasDataItemDoubleFull.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">MtasDataItemDoubleFull.java</span></div><h1>MtasDataItemDoubleFull.java</h1><pre class="source lang-java linenums">package mtas.codec.util.collector;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.ArrayUtils;
import mtas.codec.util.CodecUtil;
/**
* The Class MtasDataItemDoubleFull.
*/
public class MtasDataItemDoubleFull extends MtasDataItemFull<Double, Double> {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The fp argument. */
<span class="nc" id="L21"> private static Pattern fpArgument = Pattern.compile("([^=,]+)=([^,]*)");</span>
/**
* Instantiates a new mtas data item double full.
*
* @param value the value
* @param sub the sub
* @param statsItems the stats items
* @param sortType the sort type
* @param sortDirection the sort direction
* @param errorNumber the error number
* @param errorList the error list
* @param sourceNumber the source number
*/
public MtasDataItemDoubleFull(double[] value, MtasDataCollector<?, ?> sub,
Set<String> statsItems, String sortType, String sortDirection,
int errorNumber, Map<String, Integer> errorList, int sourceNumber) {
<span class="nc" id="L38"> super(ArrayUtils.toObject(value), sub, statsItems, sortType, sortDirection,</span>
errorNumber, errorList, new MtasDataDoubleOperations(), sourceNumber);
<span class="nc" id="L40"> }</span>
/**
* Gets the number of decimals.
*
* @param ds the ds
* @return the number of decimals
*/
private int getNumberOfDecimals(String ds) {
<span class="nc bnc" id="L49" title="All 2 branches missed."> if (!ds.contains(".")) {</span>
<span class="nc" id="L50"> return 0;</span>
} else {
<span class="nc" id="L52"> return (ds.length() - ds.indexOf(".") - 1);</span>
}
}
/*
* (non-Javadoc)
*
* @see
* mtas.codec.util.DataCollector.MtasDataItemFull#getDistribution(java.lang.
* String)
*/
@Override
protected HashMap<String, Object> getDistribution(String argument) {
<span class="nc" id="L65"> HashMap<String, Object> result = new LinkedHashMap<>();</span>
<span class="nc" id="L66"> Double start = null;</span>
<span class="nc" id="L67"> Double end = null;</span>
<span class="nc" id="L68"> Double step = null;</span>
<span class="nc" id="L69"> Integer d = null;</span>
<span class="nc" id="L70"> Integer number = null;</span>
<span class="nc bnc" id="L71" title="All 2 branches missed."> if (argument != null) {</span>
<span class="nc" id="L72"> Matcher m = fpArgument.matcher(argument);</span>
// get settings
<span class="nc bnc" id="L74" title="All 2 branches missed."> while (m.find()) {</span>
<span class="nc bnc" id="L75" title="All 2 branches missed."> if (m.group(1).trim().equals("start")) {</span>
<span class="nc" id="L76"> start = Double.parseDouble(m.group(2));</span>
<span class="nc bnc" id="L77" title="All 2 branches missed."> d = (d == null) ? getNumberOfDecimals(m.group(2))</span>
<span class="nc" id="L78"> : Math.max(d, getNumberOfDecimals(m.group(2)));</span>
<span class="nc bnc" id="L79" title="All 2 branches missed."> } else if (m.group(1).trim().equals("end")) {</span>
<span class="nc" id="L80"> end = Double.parseDouble(m.group(2));</span>
<span class="nc bnc" id="L81" title="All 2 branches missed."> d = (d == null) ? getNumberOfDecimals(m.group(2))</span>
<span class="nc" id="L82"> : Math.max(d, getNumberOfDecimals(m.group(2)));</span>
<span class="nc bnc" id="L83" title="All 2 branches missed."> } else if (m.group(1).trim().equals("step")) {</span>
<span class="nc" id="L84"> step = Double.parseDouble(m.group(2));</span>
<span class="nc bnc" id="L85" title="All 2 branches missed."> d = (d == null) ? getNumberOfDecimals(m.group(2))</span>
<span class="nc" id="L86"> : Math.max(d, getNumberOfDecimals(m.group(2)));</span>
<span class="nc bnc" id="L87" title="All 2 branches missed."> } else if (m.group(1).trim().equals("number")) {</span>
<span class="nc" id="L88"> number = Integer.parseInt(m.group(2));</span>
}
}
}
// always exactly one of (positive) number and (positive) step, other null
<span class="nc bnc" id="L93" title="All 8 branches missed."> if ((number == null || number < 1) && (step == null || step <= 0)) {</span>
<span class="nc" id="L94"> number = 10;</span>
<span class="nc" id="L95"> step = null;</span>
<span class="nc bnc" id="L96" title="All 4 branches missed."> } else if (step != null && step <= 0) {</span>
<span class="nc" id="L97"> step = null;</span>
<span class="nc bnc" id="L98" title="All 4 branches missed."> } else if (number != null && number < 1) {</span>
<span class="nc" id="L99"> number = null;</span>
<span class="nc bnc" id="L100" title="All 2 branches missed."> } else if (step != null) {</span>
<span class="nc" id="L101"> number = null;</span>
}
// sanity checks start/end
<span class="nc" id="L104"> createStats();</span>
<span class="nc" id="L105"> double tmpStart = stats.getMin();</span>
<span class="nc" id="L106"> double tmpEnd = stats.getMax();</span>
<span class="nc bnc" id="L107" title="All 6 branches missed."> if (start != null && end != null && start > end) {</span>
<span class="nc" id="L108"> return null;</span>
<span class="nc bnc" id="L109" title="All 4 branches missed."> } else if (start != null && start > tmpEnd) {</span>
<span class="nc" id="L110"> return null;</span>
<span class="nc bnc" id="L111" title="All 4 branches missed."> } else if (end != null && end < tmpStart) {</span>
<span class="nc" id="L112"> return null;</span>
}
// check start and end
<span class="nc bnc" id="L115" title="All 4 branches missed."> if (start == null && end == null) {</span>
<span class="nc bnc" id="L116" title="All 2 branches missed."> if (step == null) {</span>
<span class="nc" id="L117"> step = (tmpEnd - tmpStart) / number;</span>
}
<span class="nc" id="L119"> number = Double.valueOf(Math.ceil((tmpEnd - tmpStart) / step)).intValue();</span>
<span class="nc" id="L120"> start = tmpStart;</span>
<span class="nc" id="L121"> end = start + (number * step);</span>
<span class="nc bnc" id="L122" title="All 2 branches missed."> } else if (start == null) {</span>
<span class="nc bnc" id="L123" title="All 2 branches missed."> if (step == null) {</span>
<span class="nc" id="L124"> step = (end - tmpStart) / number;</span>
}
<span class="nc" id="L126"> number = Double.valueOf(Math.ceil((end - tmpStart) / step)).intValue();</span>
<span class="nc" id="L127"> start = end - (number * step);</span>
<span class="nc bnc" id="L128" title="All 2 branches missed."> } else if (end == null) {</span>
<span class="nc bnc" id="L129" title="All 2 branches missed."> if (step == null) {</span>
<span class="nc" id="L130"> step = (tmpEnd - start) / number;</span>
}
<span class="nc" id="L132"> number = Double.valueOf(Math.ceil((tmpEnd - start) / step)).intValue();</span>
<span class="nc" id="L133"> end = start + (number * step);</span>
} else {
<span class="nc bnc" id="L135" title="All 2 branches missed."> if (step == null) {</span>
<span class="nc" id="L136"> step = (end - start) / number;</span>
}
<span class="nc" id="L138"> number = Double.valueOf(Math.ceil((end - start) / step)).intValue();</span>
}
// round step to agreeable format and recompute number
<span class="nc" id="L141"> int tmpD = Double.valueOf(Math.max(0, 1 + Math.ceil(-1 * Math.log10(step))))</span>
<span class="nc" id="L142"> .intValue();</span>
<span class="nc bnc" id="L143" title="All 2 branches missed."> d = (d == null) ? tmpD : Math.max(d, tmpD);</span>
<span class="nc" id="L144"> double tmp = Math.pow(10.0, d);</span>
<span class="nc" id="L145"> step = Math.round(step * tmp) / tmp;</span>
<span class="nc" id="L146"> number = Double.valueOf(Math.ceil((end - start) / step)).intValue();</span>
// compute distribution
<span class="nc" id="L149"> long[] list = new long[number];</span>
<span class="nc bnc" id="L150" title="All 2 branches missed."> for (Double v : fullValues) {</span>
<span class="nc bnc" id="L151" title="All 4 branches missed."> if (v >= start && v <= end) {</span>
<span class="nc" id="L152"> int i = Math.min(</span>
<span class="nc" id="L153"> Double.valueOf(Math.floor((v - start) / step)).intValue(),</span>
<span class="nc" id="L154"> (number - 1));</span>
<span class="nc" id="L155"> list[i]++;</span>
}
}
Double l;
Double r;
String ls;
String lsFormat;
String rs;
String rsFormat;
<span class="nc bnc" id="L164" title="All 2 branches missed."> for (int i = 0; i < number; i++) {</span>
<span class="nc" id="L165"> l = start + i * step;</span>
<span class="nc" id="L166"> r = Math.min(end, l + step);</span>
<span class="nc" id="L167"> lsFormat = "%." + d + "f";</span>
<span class="nc" id="L168"> ls = String.format(lsFormat, l);</span>
<span class="nc" id="L169"> rsFormat = "%." + d + "f";</span>
<span class="nc" id="L170"> rs = String.format(rsFormat, r);</span>
<span class="nc" id="L171"> String key = "[" + ls + "," + rs</span>
<span class="nc bnc" id="L172" title="All 6 branches missed."> + ((i == (number - 1) && r >= tmpEnd && l <= tmpEnd) ? "]" : ")");</span>
<span class="nc" id="L173"> result.put(key, list[i]);</span>
}
<span class="nc" id="L175"> return result;</span>
}
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public int compareTo(MtasDataItem<Double, Double> o) {
<span class="nc" id="L185"> int compare = 0;</span>
<span class="nc bnc" id="L186" title="All 2 branches missed."> if (o instanceof MtasDataItemDoubleFull) {</span>
<span class="nc" id="L187"> MtasDataItemDoubleFull to = (MtasDataItemDoubleFull) o;</span>
<span class="nc" id="L188"> MtasDataItemNumberComparator c1 = getComparableValue();</span>
<span class="nc" id="L189"> MtasDataItemNumberComparator c2 = to.getComparableValue();</span>
<span class="nc bnc" id="L190" title="All 4 branches missed."> compare = (c1 != null && c2 != null) ? c1.compareTo(c2.getValue()) : 0;</span>
}
<span class="nc bnc" id="L192" title="All 2 branches missed."> return sortDirection.equals(CodecUtil.SORT_DESC) ? -1 * compare : compare;</span>
}
/*
* (non-Javadoc)
*
* @see mtas.codec.util.collector.MtasDataItem#getCompareValue1()
*/
@Override
public MtasDataItemNumberComparator<Double> getCompareValue1() {
<span class="nc" id="L202"> createStats();</span>
<span class="nc bnc" id="L203" title="All 18 branches missed."> switch (sortType) {</span>
case CodecUtil.STATS_TYPE_SUM:
<span class="nc" id="L205"> return new MtasDataItemNumberComparator<>(stats.getSum(), sortDirection);</span>
case CodecUtil.STATS_TYPE_MAX:
<span class="nc" id="L207"> return new MtasDataItemNumberComparator<>(stats.getMax(), sortDirection);</span>
case CodecUtil.STATS_TYPE_MIN:
<span class="nc" id="L209"> return new MtasDataItemNumberComparator<>(stats.getMin(), sortDirection);</span>
case CodecUtil.STATS_TYPE_SUMSQ:
<span class="nc" id="L211"> return new MtasDataItemNumberComparator<>(stats.getSumsq(),</span>
sortDirection);
default:
<span class="nc" id="L214"> return null;</span>
}
}
/*
* (non-Javadoc)
*
* @see mtas.codec.util.collector.MtasDataItem#getCompareValue2()
*/
@Override
public MtasDataItemNumberComparator<Double> getCompareValue2() {
<span class="nc" id="L225"> createStats();</span>
<span class="nc bnc" id="L226" title="All 42 branches missed."> switch (sortType) {</span>
case CodecUtil.STATS_TYPE_SUMOFLOGS:
<span class="nc" id="L228"> return new MtasDataItemNumberComparator<>(</span>
<span class="nc" id="L229"> stats.getN() * Math.log(stats.getGeometricMean()), sortDirection);</span>
case CodecUtil.STATS_TYPE_MEAN:
<span class="nc" id="L231"> return new MtasDataItemNumberComparator<>(stats.getMean(), sortDirection);</span>
case CodecUtil.STATS_TYPE_GEOMETRICMEAN:
<span class="nc" id="L233"> return new MtasDataItemNumberComparator<>(stats.getGeometricMean(),</span>
sortDirection);
case CodecUtil.STATS_TYPE_STANDARDDEVIATION:
<span class="nc" id="L236"> return new MtasDataItemNumberComparator<>(stats.getStandardDeviation(),</span>
sortDirection);
case CodecUtil.STATS_TYPE_VARIANCE:
<span class="nc" id="L239"> return new MtasDataItemNumberComparator<>(stats.getVariance(),</span>
sortDirection);
case CodecUtil.STATS_TYPE_POPULATIONVARIANCE:
<span class="nc" id="L242"> return new MtasDataItemNumberComparator<>(stats.getPopulationVariance(),</span>
sortDirection);
case CodecUtil.STATS_TYPE_QUADRATICMEAN:
<span class="nc" id="L245"> return new MtasDataItemNumberComparator<>(</span>
<span class="nc" id="L246"> Math.sqrt(stats.getSumsq() / stats.getN()), sortDirection);</span>
case CodecUtil.STATS_TYPE_KURTOSIS:
<span class="nc" id="L248"> return new MtasDataItemNumberComparator<>(stats.getKurtosis(),</span>
sortDirection);
case CodecUtil.STATS_TYPE_MEDIAN:
<span class="nc" id="L251"> return new MtasDataItemNumberComparator<>(stats.getPercentile(50),</span>
sortDirection);
case CodecUtil.STATS_TYPE_SKEWNESS:
<span class="nc" id="L254"> return new MtasDataItemNumberComparator<>(stats.getSkewness(),</span>
sortDirection);
default:
<span class="nc" id="L257"> return null;</span>
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
<span class="nc" id="L267"> return this.getClass().getSimpleName() + "[" + fullValues.length + "]";</span>
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
<span class="nc bnc" id="L277" title="All 2 branches missed."> if (this == obj)</span>
<span class="nc" id="L278"> return true;</span>
<span class="nc bnc" id="L279" title="All 2 branches missed."> if (obj == null)</span>
<span class="nc" id="L280"> return false;</span>
<span class="nc bnc" id="L281" title="All 2 branches missed."> if (getClass() != obj.getClass())</span>
<span class="nc" id="L282"> return false;</span>
<span class="nc" id="L283"> MtasDataItemDoubleFull that = (MtasDataItemDoubleFull) obj;</span>
<span class="nc" id="L284"> MtasDataItemNumberComparator<?> c1 = getComparableValue();</span>
<span class="nc" id="L285"> MtasDataItemNumberComparator<?> c2 = that.getComparableValue();</span>
<span class="nc bnc" id="L286" title="All 6 branches missed."> return (c1 != null && c2 != null && c1.equals(c2));</span>
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
<span class="nc" id="L296"> int h = this.getClass().getSimpleName().hashCode();</span>
<span class="nc" id="L297"> h = (h * 7) ^ getComparableValue().hashCode();</span>
<span class="nc" id="L298"> 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>