MtasDataItemLongFull.java.html
14.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
<?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>MtasDataItemLongFull.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">MtasDataItemLongFull.java</span></div><h1>MtasDataItemLongFull.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 MtasDataItemLongFull.
*/
class MtasDataItemLongFull extends MtasDataItemFull<Long, Double> {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The fp argument. */
<span class="fc" id="L21"> private static Pattern fpArgument = Pattern.compile("([^=,]+)=([^,]*)");</span>
/**
* Instantiates a new mtas data item long 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 MtasDataItemLongFull(long[] value, MtasDataCollector<?, ?> sub,
Set<String> statsItems, String sortType, String sortDirection,
int errorNumber, Map<String, Integer> errorList, int sourceNumber) {
<span class="fc" id="L38"> super(ArrayUtils.toObject(value), sub, statsItems, sortType, sortDirection,</span>
errorNumber, errorList, new MtasDataLongOperations(), sourceNumber);
<span class="fc" id="L40"> }</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="L51"> HashMap<String, Object> result = new LinkedHashMap<>();</span>
<span class="nc" id="L52"> Long start = null;</span>
<span class="nc" id="L53"> Long end = null;</span>
<span class="nc" id="L54"> Long step = null;</span>
<span class="nc" id="L55"> Integer number = null;</span>
<span class="nc bnc" id="L56" title="All 2 branches missed."> if (argument != null) {</span>
<span class="nc" id="L57"> Matcher m = fpArgument.matcher(argument);</span>
// get settings
<span class="nc bnc" id="L59" title="All 2 branches missed."> while (m.find()) {</span>
<span class="nc bnc" id="L60" title="All 2 branches missed."> if (m.group(1).trim().equals("start")) {</span>
<span class="nc" id="L61"> start = Long.parseLong(m.group(2));</span>
<span class="nc bnc" id="L62" title="All 2 branches missed."> } else if (m.group(1).trim().equals("end")) {</span>
<span class="nc" id="L63"> end = Long.parseLong(m.group(2));</span>
<span class="nc bnc" id="L64" title="All 2 branches missed."> } else if (m.group(1).trim().equals("step")) {</span>
<span class="nc" id="L65"> step = Long.parseLong(m.group(2));</span>
<span class="nc bnc" id="L66" title="All 2 branches missed."> } else if (m.group(1).trim().equals("number")) {</span>
<span class="nc" id="L67"> number = Integer.parseInt(m.group(2));</span>
}
}
}
// always exactly one of (positive) number and (positive) step, other null
<span class="nc bnc" id="L72" title="All 8 branches missed."> if ((number == null || number < 1) && (step == null || step < 1)) {</span>
<span class="nc" id="L73"> number = 10;</span>
<span class="nc" id="L74"> step = null;</span>
<span class="nc bnc" id="L75" title="All 4 branches missed."> } else if (step != null && step < 1) {</span>
<span class="nc" id="L76"> step = null;</span>
<span class="nc bnc" id="L77" title="All 4 branches missed."> } else if (number != null && number < 1) {</span>
<span class="nc" id="L78"> number = null;</span>
<span class="nc bnc" id="L79" title="All 2 branches missed."> } else if (step != null) {</span>
<span class="nc" id="L80"> number = null;</span>
}
// sanity checks start/end
<span class="nc" id="L83"> createStats();</span>
<span class="nc" id="L84"> long tmpStart = Double.valueOf(Math.floor(stats.getMin())).longValue();</span>
<span class="nc" id="L85"> long tmpEnd = Double.valueOf(Math.ceil(stats.getMax())).longValue();</span>
<span class="nc bnc" id="L86" title="All 6 branches missed."> if (start != null && end != null && start > end) {</span>
<span class="nc" id="L87"> return null;</span>
<span class="nc bnc" id="L88" title="All 4 branches missed."> } else if (start != null && start > tmpEnd) {</span>
<span class="nc" id="L89"> return null;</span>
<span class="nc bnc" id="L90" title="All 4 branches missed."> } else if (end != null && end < tmpStart) {</span>
<span class="nc" id="L91"> return null;</span>
}
// check start and end
<span class="nc bnc" id="L94" title="All 4 branches missed."> if (start == null && end == null) {</span>
<span class="nc bnc" id="L95" title="All 2 branches missed."> if (step == null) {</span>
<span class="nc" id="L96"> step = -Math.floorDiv((tmpStart - tmpEnd - 1), number);</span>
}
<span class="nc" id="L98"> number = Long.valueOf(-Math.floorDiv((tmpStart - tmpEnd - 1), step))</span>
<span class="nc" id="L99"> .intValue();</span>
<span class="nc" id="L100"> start = tmpStart;</span>
<span class="nc" id="L101"> end = start + (number * step);</span>
<span class="nc bnc" id="L102" title="All 2 branches missed."> } else if (start == null) {</span>
<span class="nc bnc" id="L103" title="All 2 branches missed."> if (step == null) {</span>
<span class="nc" id="L104"> step = -Math.floorDiv((tmpStart - end - 1), number);</span>
}
<span class="nc" id="L106"> number = Long.valueOf(-Math.floorDiv((tmpStart - end - 1), step))</span>
<span class="nc" id="L107"> .intValue();</span>
<span class="nc" id="L108"> start = end - (number * step);</span>
<span class="nc bnc" id="L109" title="All 2 branches missed."> } else if (end == null) {</span>
<span class="nc bnc" id="L110" title="All 2 branches missed."> if (step == null) {</span>
<span class="nc" id="L111"> step = -Math.floorDiv((start - tmpEnd - 1), number);</span>
}
<span class="nc" id="L113"> number = Long.valueOf(-Math.floorDiv((start - tmpEnd - 1), step))</span>
<span class="nc" id="L114"> .intValue();</span>
<span class="nc" id="L115"> end = start + (number * step);</span>
} else {
<span class="nc bnc" id="L117" title="All 2 branches missed."> if (step == null) {</span>
<span class="nc" id="L118"> step = -Math.floorDiv((start - end - 1), number);</span>
}
<span class="nc" id="L120"> number = Long.valueOf(-Math.floorDiv((start - end - 1), step)).intValue();</span>
}
<span class="nc" id="L122"> long[] list = new long[number];</span>
<span class="nc bnc" id="L123" title="All 2 branches missed."> for (Long v : fullValues) {</span>
<span class="nc bnc" id="L124" title="All 4 branches missed."> if (v >= start && v <= end) {</span>
<span class="nc" id="L125"> int i = Long.valueOf(Math.floorDiv((v - start), step)).intValue();</span>
<span class="nc" id="L126"> list[i]++;</span>
}
}
<span class="nc bnc" id="L129" title="All 2 branches missed."> for (int i = 0; i < number; i++) {</span>
<span class="nc" id="L130"> Long l = start + i * step;</span>
<span class="nc" id="L131"> Long r = Math.min(end, l + step - 1);</span>
String key;
<span class="nc bnc" id="L133" title="All 4 branches missed."> if (step > 1 && r > l) {</span>
<span class="nc" id="L134"> key = "[" + l + "," + r + "]";</span>
} else {
<span class="nc" id="L136"> key = "[" + l + "]";</span>
}
<span class="nc" id="L138"> result.put(key, list[i]);</span>
}
<span class="nc" id="L140"> return result;</span>
}
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public int compareTo(MtasDataItem<Long, Double> o) {
<span class="nc" id="L150"> int compare = 0;</span>
<span class="nc bnc" id="L151" title="All 2 branches missed."> if (o instanceof MtasDataItemLongFull) {</span>
<span class="nc" id="L152"> MtasDataItemLongFull to = (MtasDataItemLongFull) o;</span>
<span class="nc" id="L153"> MtasDataItemNumberComparator c1 = getComparableValue();</span>
<span class="nc" id="L154"> MtasDataItemNumberComparator c2 = to.getComparableValue();</span>
<span class="nc bnc" id="L155" title="All 4 branches missed."> compare = (c1 != null && c2 != null) ? c1.compareTo(c2.getValue()) : 0;</span>
}
<span class="nc bnc" id="L157" 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<Long> getCompareValue1() {
<span class="nc" id="L167"> createStats();</span>
<span class="nc bnc" id="L168" title="All 18 branches missed."> switch (sortType) {</span>
case CodecUtil.STATS_TYPE_SUM:
<span class="nc" id="L170"> return new MtasDataItemNumberComparator<>(Math.round(stats.getSum()), sortDirection);</span>
case CodecUtil.STATS_TYPE_MAX:
<span class="nc" id="L172"> return new MtasDataItemNumberComparator<>(Math.round(stats.getMax()), sortDirection);</span>
case CodecUtil.STATS_TYPE_MIN:
<span class="nc" id="L174"> return new MtasDataItemNumberComparator<>(Math.round(stats.getMin()), sortDirection);</span>
case CodecUtil.STATS_TYPE_SUMSQ:
<span class="nc" id="L176"> return new MtasDataItemNumberComparator<>(Math.round(stats.getSumsq()), sortDirection);</span>
default:
<span class="nc" id="L178"> return null;</span>
}
}
/*
* (non-Javadoc)
*
* @see mtas.codec.util.collector.MtasDataItem#getCompareValue2()
*/
@Override
public MtasDataItemNumberComparator<Double> getCompareValue2() {
<span class="nc" id="L189"> createStats();</span>
<span class="nc bnc" id="L190" title="All 42 branches missed."> switch (sortType) {</span>
case CodecUtil.STATS_TYPE_SUMOFLOGS:
<span class="nc" id="L192"> return new MtasDataItemNumberComparator<>(</span>
<span class="nc" id="L193"> stats.getN() * Math.log(stats.getGeometricMean()), sortDirection);</span>
case CodecUtil.STATS_TYPE_MEAN:
<span class="nc" id="L195"> return new MtasDataItemNumberComparator<>(stats.getMean(), sortDirection);</span>
case CodecUtil.STATS_TYPE_GEOMETRICMEAN:
<span class="nc" id="L197"> return new MtasDataItemNumberComparator<>(stats.getGeometricMean(), sortDirection);</span>
case CodecUtil.STATS_TYPE_STANDARDDEVIATION:
<span class="nc" id="L199"> return new MtasDataItemNumberComparator<>(stats.getStandardDeviation(), sortDirection);</span>
case CodecUtil.STATS_TYPE_VARIANCE:
<span class="nc" id="L201"> return new MtasDataItemNumberComparator<>(stats.getVariance(), sortDirection);</span>
case CodecUtil.STATS_TYPE_POPULATIONVARIANCE:
<span class="nc" id="L203"> return new MtasDataItemNumberComparator<>(stats.getPopulationVariance(), sortDirection);</span>
case CodecUtil.STATS_TYPE_QUADRATICMEAN:
<span class="nc" id="L205"> return new MtasDataItemNumberComparator<>(stats.getQuadraticMean(), sortDirection);</span>
case CodecUtil.STATS_TYPE_KURTOSIS:
<span class="nc" id="L207"> return new MtasDataItemNumberComparator<>(stats.getKurtosis(), sortDirection);</span>
case CodecUtil.STATS_TYPE_MEDIAN:
<span class="nc" id="L209"> return new MtasDataItemNumberComparator<>(stats.getPercentile(50), sortDirection);</span>
case CodecUtil.STATS_TYPE_SKEWNESS:
<span class="nc" id="L211"> return new MtasDataItemNumberComparator<>(stats.getSkewness(), sortDirection);</span>
default:
<span class="nc" id="L213"> return null;</span>
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
<span class="nc" id="L223"> 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="L231" title="All 2 branches missed."> if (this == obj)</span>
<span class="nc" id="L232"> return true;</span>
<span class="nc bnc" id="L233" title="All 2 branches missed."> if (obj == null)</span>
<span class="nc" id="L234"> return false;</span>
<span class="nc bnc" id="L235" title="All 2 branches missed."> if (getClass() != obj.getClass())</span>
<span class="nc" id="L236"> return false;</span>
<span class="nc" id="L237"> MtasDataItemLongFull that = (MtasDataItemLongFull) obj;</span>
<span class="nc" id="L238"> MtasDataItemNumberComparator<?> c1 = getComparableValue();</span>
<span class="nc" id="L239"> MtasDataItemNumberComparator<?> c2 = that.getComparableValue();</span>
<span class="nc bnc" id="L240" 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="L248"> int h = this.getClass().getSimpleName().hashCode();</span>
<span class="nc" id="L249"> h = (h * 7) ^ getComparableValue().hashCode();</span>
<span class="nc" id="L250"> 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>