MtasSpanSequenceItem.java.html
16.6 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
<?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>MtasSpanSequenceItem.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.search.spans</a> > <span class="el_source">MtasSpanSequenceItem.java</span></div><h1>MtasSpanSequenceItem.java</h1><pre class="source lang-java linenums">package mtas.search.spans;
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import mtas.search.spans.util.MtasSpanQuery;
/**
* The Class MtasSpanSequenceItem.
*/
public class MtasSpanSequenceItem {
/** The span query. */
private MtasSpanQuery spanQuery;
/** The optional. */
private boolean optional;
/**
* Instantiates a new mtas span sequence item.
*
* @param spanQuery
* the span query
* @param optional
* the optional
*/
<span class="fc" id="L28"> public MtasSpanSequenceItem(MtasSpanQuery spanQuery, boolean optional) {</span>
<span class="fc" id="L29"> this.spanQuery = spanQuery;</span>
<span class="fc" id="L30"> this.optional = optional;</span>
<span class="fc" id="L31"> }</span>
/**
* Gets the query.
*
* @return the query
*/
public MtasSpanQuery getQuery() {
<span class="fc" id="L39"> return spanQuery;</span>
}
/**
* Sets the query.
*
* @param spanQuery
* the new query
*/
public void setQuery(MtasSpanQuery spanQuery) {
<span class="nc" id="L49"> this.spanQuery = spanQuery;</span>
<span class="nc" id="L50"> }</span>
/**
* Checks if is optional.
*
* @return true, if is optional
*/
public boolean isOptional() {
<span class="fc" id="L58"> return optional;</span>
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
<span class="pc bpc" id="L68" title="1 of 2 branches missed."> if (o instanceof MtasSpanSequenceItem) {</span>
<span class="fc" id="L69"> MtasSpanSequenceItem that = (MtasSpanSequenceItem) o;</span>
<span class="fc bfc" id="L70" title="All 2 branches covered."> return spanQuery.equals(that.getQuery())</span>
<span class="pc bpc" id="L71" title="1 of 2 branches missed."> && (optional == that.isOptional());</span>
} else {
<span class="nc" id="L73"> return false;</span>
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
<span class="fc" id="L84"> int h = this.getClass().getSimpleName().hashCode();</span>
<span class="fc" id="L85"> h = (h * 3) ^ spanQuery.hashCode();</span>
<span class="pc bpc" id="L86" title="1 of 2 branches missed."> h += (optional ? 1 : 0);</span>
<span class="fc" id="L87"> return h;</span>
}
/**
* Rewrite.
*
* @param reader
* the reader
* @return the mtas span sequence item
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public MtasSpanSequenceItem rewrite(IndexReader reader) throws IOException {
<span class="fc" id="L100"> MtasSpanQuery newSpanQuery = spanQuery.rewrite(reader);</span>
<span class="fc bfc" id="L101" title="All 2 branches covered."> if (!newSpanQuery.equals(spanQuery)) {</span>
<span class="fc" id="L102"> return new MtasSpanSequenceItem(newSpanQuery, optional);</span>
} else {
<span class="fc" id="L104"> return this;</span>
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
<span class="nc bnc" id="L115" title="All 2 branches missed."> return "[" + spanQuery.toString() + " - "</span>
+ (optional ? "OPTIONAL" : "NOT OPTIONAL") + "]";
}
/**
* Merge.
*
* @param item1
* the item 1
* @param item2
* the item 2
* @param ignoreQuery
* the ignore query
* @param maximumIgnoreLength
* the maximum ignore length
* @return the mtas span sequence item
*/
public static MtasSpanSequenceItem merge(MtasSpanSequenceItem item1,
MtasSpanSequenceItem item2, MtasSpanQuery ignoreQuery,
Integer maximumIgnoreLength) {
<span class="pc bpc" id="L135" title="1 of 4 branches missed."> if (item1 == null || item2 == null) {</span>
<span class="fc" id="L136"> return null;</span>
} else {
<span class="fc" id="L138"> MtasSpanQuery q1 = item1.getQuery();</span>
<span class="fc" id="L139"> MtasSpanQuery q2 = item2.getQuery();</span>
<span class="pc bpc" id="L140" title="1 of 4 branches missed."> boolean optional = item1.optional && item2.optional;</span>
// first spanRecurrenceQuery
<span class="fc bfc" id="L142" title="All 2 branches covered."> if (q1 instanceof MtasSpanRecurrenceQuery) {</span>
<span class="fc" id="L143"> MtasSpanRecurrenceQuery rq1 = (MtasSpanRecurrenceQuery) q1;</span>
// both spanRecurrenceQuery
<span class="pc bpc" id="L145" title="1 of 2 branches missed."> if (q2 instanceof MtasSpanRecurrenceQuery) {</span>
<span class="nc" id="L146"> MtasSpanRecurrenceQuery rq2 = (MtasSpanRecurrenceQuery) q2;</span>
// equal query
<span class="nc bnc" id="L148" title="All 2 branches missed."> if (rq1.getQuery().equals(rq2.getQuery())) {</span>
// equal ignoreQuery settings
boolean checkCondition;
<span class="nc bnc" id="L151" title="All 2 branches missed."> checkCondition = ignoreQuery != null</span>
<span class="nc bnc" id="L152" title="All 2 branches missed."> && rq1.getIgnoreQuery() != null;</span>
<span class="nc bnc" id="L153" title="All 2 branches missed."> checkCondition = checkCondition</span>
<span class="nc" id="L154"> ? ignoreQuery.equals(rq1.getIgnoreQuery()) : false;</span>
<span class="nc bnc" id="L155" title="All 2 branches missed."> checkCondition = checkCondition</span>
<span class="nc" id="L156"> ? maximumIgnoreLength.equals(rq1.getMaximumIgnoreLength())</span>
: false;
<span class="nc bnc" id="L158" title="All 4 branches missed."> checkCondition = checkCondition ? rq2.getIgnoreQuery() != null</span>
: false;
<span class="nc bnc" id="L160" title="All 2 branches missed."> checkCondition = checkCondition</span>
<span class="nc" id="L161"> ? ignoreQuery.equals(rq2.getIgnoreQuery()) : false;</span>
<span class="nc bnc" id="L162" title="All 2 branches missed."> checkCondition = checkCondition</span>
<span class="nc" id="L163"> ? maximumIgnoreLength.equals(rq2.getMaximumIgnoreLength())</span>
: false;
<span class="nc bnc" id="L165" title="All 2 branches missed."> if (checkCondition) {</span>
// at least one optional
<span class="nc bnc" id="L167" title="All 4 branches missed."> if (item1.optional || item2.optional) {</span>
<span class="nc" id="L168"> int minimum = Math.min(rq1.getMinimumRecurrence(),</span>
<span class="nc" id="L169"> rq2.getMinimumRecurrence());</span>
<span class="nc" id="L170"> int maximum = rq1.getMaximumRecurrence()</span>
<span class="nc" id="L171"> + rq2.getMaximumRecurrence();</span>
// only if ranges match
<span class="nc" id="L173"> if ((rq1.getMaximumRecurrence() + 1) >= rq2</span>
<span class="nc bnc" id="L174" title="All 2 branches missed."> .getMinimumRecurrence()</span>
<span class="nc" id="L175"> && (rq2.getMaximumRecurrence() + 1) >= rq1</span>
<span class="nc bnc" id="L176" title="All 2 branches missed."> .getMinimumRecurrence()) {</span>
<span class="nc" id="L177"> return new MtasSpanSequenceItem(</span>
<span class="nc" id="L178"> new MtasSpanRecurrenceQuery(rq1.getQuery(), minimum,</span>
maximum, ignoreQuery, maximumIgnoreLength),
optional);
}
// not optional
<span class="nc" id="L183"> } else {</span>
<span class="nc" id="L184"> int minimum = rq1.getMinimumRecurrence()</span>
<span class="nc" id="L185"> + rq2.getMinimumRecurrence();</span>
<span class="nc" id="L186"> int maximum = rq1.getMaximumRecurrence()</span>
<span class="nc" id="L187"> + rq2.getMaximumRecurrence();</span>
// only if ranges match
<span class="nc" id="L189"> if ((rq1.getMaximumRecurrence() + 1) >= rq2</span>
<span class="nc bnc" id="L190" title="All 2 branches missed."> .getMinimumRecurrence()</span>
<span class="nc" id="L191"> && (rq2.getMaximumRecurrence() + 1) >= rq1</span>
<span class="nc bnc" id="L192" title="All 2 branches missed."> .getMinimumRecurrence()) {</span>
<span class="nc" id="L193"> return new MtasSpanSequenceItem(</span>
<span class="nc" id="L194"> new MtasSpanRecurrenceQuery(rq1.getQuery(), minimum,</span>
maximum, ignoreQuery, maximumIgnoreLength),
optional);
}
}
}
}
<span class="nc" id="L201"> } else {</span>
<span class="pc bpc" id="L202" title="1 of 2 branches missed."> if (rq1.getQuery().equals(q2)) {</span>
boolean checkCondition;
<span class="nc bnc" id="L204" title="All 2 branches missed."> checkCondition = ignoreQuery != null;</span>
<span class="nc bnc" id="L205" title="All 2 branches missed."> checkCondition &= rq1.getIgnoreQuery() != null;</span>
<span class="nc" id="L206"> checkCondition &= ignoreQuery.equals(rq1.getIgnoreQuery());</span>
<span class="nc bnc" id="L207" title="All 2 branches missed."> checkCondition &= rq1.getMaximumIgnoreLength() != null;</span>
<span class="nc" id="L208"> checkCondition &= maximumIgnoreLength</span>
<span class="nc" id="L209"> .equals(rq1.getMaximumIgnoreLength());</span>
<span class="nc bnc" id="L210" title="All 2 branches missed."> if (checkCondition) {</span>
<span class="nc bnc" id="L211" title="All 2 branches missed."> if (!optional) {</span>
<span class="nc bnc" id="L212" title="All 2 branches missed."> if (item1.optional) {</span>
<span class="nc bnc" id="L213" title="All 2 branches missed."> if (rq1.getMinimumRecurrence() == 1) {</span>
<span class="nc" id="L214"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(</span>
<span class="nc" id="L215"> q2, 1, rq1.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), false);
}
<span class="nc bnc" id="L218" title="All 2 branches missed."> } else if (item2.optional) {</span>
<span class="nc" id="L219"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(</span>
<span class="nc" id="L220"> q2, rq1.getMinimumRecurrence(),</span>
<span class="nc" id="L221"> rq1.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), false);
} else {
<span class="nc" id="L224"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(</span>
<span class="nc" id="L225"> q2, rq1.getMinimumRecurrence() + 1,</span>
<span class="nc" id="L226"> rq1.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), false);
}
} else {
<span class="nc bnc" id="L230" title="All 2 branches missed."> if (rq1.getMinimumRecurrence() == 1) {</span>
<span class="nc" id="L231"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(</span>
<span class="nc" id="L232"> q2, 1, rq1.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), true);
}
}
}
}
}
// second spanRecurrenceQuery
<span class="fc bfc" id="L240" title="All 2 branches covered."> } else if (q2 instanceof MtasSpanRecurrenceQuery) {</span>
<span class="fc" id="L241"> MtasSpanRecurrenceQuery rq2 = (MtasSpanRecurrenceQuery) q2;</span>
<span class="pc bpc" id="L242" title="1 of 2 branches missed."> if (rq2.getQuery().equals(q1)) {</span>
boolean checkCondition;
<span class="nc bnc" id="L244" title="All 2 branches missed."> checkCondition = ignoreQuery != null;</span>
<span class="nc bnc" id="L245" title="All 2 branches missed."> checkCondition &= rq2.getIgnoreQuery() != null;</span>
<span class="nc" id="L246"> checkCondition &= ignoreQuery.equals(rq2.getIgnoreQuery());</span>
<span class="nc" id="L247"> checkCondition &= maximumIgnoreLength</span>
<span class="nc" id="L248"> .equals(rq2.getMaximumIgnoreLength());</span>
<span class="nc bnc" id="L249" title="All 2 branches missed."> if (checkCondition) {</span>
<span class="nc bnc" id="L250" title="All 2 branches missed."> if (!optional) {</span>
<span class="nc bnc" id="L251" title="All 2 branches missed."> if (item1.optional) {</span>
<span class="nc" id="L252"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1,</span>
<span class="nc" id="L253"> rq2.getMinimumRecurrence(), rq2.getMaximumRecurrence() + 1,</span>
ignoreQuery, maximumIgnoreLength), false);
<span class="nc bnc" id="L255" title="All 2 branches missed."> } else if (item2.optional) {</span>
<span class="nc bnc" id="L256" title="All 2 branches missed."> if (rq2.getMinimumRecurrence() == 1) {</span>
<span class="nc" id="L257"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(</span>
<span class="nc" id="L258"> q1, 1, rq2.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), false);
}
} else {
<span class="nc" id="L262"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1,</span>
<span class="nc" id="L263"> rq2.getMinimumRecurrence() + 1,</span>
<span class="nc" id="L264"> rq2.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), false);
}
} else {
<span class="nc bnc" id="L268" title="All 2 branches missed."> if (rq2.getMinimumRecurrence() == 1) {</span>
<span class="nc" id="L269"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1,</span>
<span class="nc" id="L270"> 1, rq2.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), true);
}
}
}
}
// both no spanRecurrenceQuery
<span class="pc bpc" id="L277" title="1 of 2 branches missed."> } else if (q1.equals(q2)) {</span>
// at least one optional
<span class="nc bnc" id="L279" title="All 4 branches missed."> if (item1.optional || item2.optional) {</span>
<span class="nc" id="L280"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1, 1, 2,</span>
ignoreQuery, maximumIgnoreLength), optional);
} else {
<span class="nc" id="L283"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1, 2, 2,</span>
ignoreQuery, maximumIgnoreLength), optional);
}
}
<span class="fc" id="L287"> return null;</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>