MtasSpanSequenceItem.java.html
16.5 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
<?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="L26"> public MtasSpanSequenceItem(MtasSpanQuery spanQuery, boolean optional) {</span>
<span class="fc" id="L27"> this.spanQuery = spanQuery;</span>
<span class="fc" id="L28"> this.optional = optional;</span>
<span class="fc" id="L29"> }</span>
/**
* Gets the query.
*
* @return the query
*/
public MtasSpanQuery getQuery() {
<span class="fc" id="L37"> return spanQuery;</span>
}
/**
* Sets the query.
*
* @param spanQuery the new query
*/
public void setQuery(MtasSpanQuery spanQuery) {
<span class="nc" id="L46"> this.spanQuery = spanQuery;</span>
<span class="nc" id="L47"> }</span>
/**
* Checks if is optional.
*
* @return true, if is optional
*/
public boolean isOptional() {
<span class="fc" id="L55"> return optional;</span>
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
<span class="pc bpc" id="L65" title="1 of 2 branches missed."> if (o instanceof MtasSpanSequenceItem) {</span>
<span class="fc" id="L66"> MtasSpanSequenceItem that = (MtasSpanSequenceItem) o;</span>
<span class="fc bfc" id="L67" title="All 2 branches covered."> return spanQuery.equals(that.getQuery())</span>
<span class="pc bpc" id="L68" title="1 of 2 branches missed."> && (optional == that.isOptional());</span>
} else {
<span class="nc" id="L70"> return false;</span>
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
<span class="fc" id="L81"> int h = this.getClass().getSimpleName().hashCode();</span>
<span class="fc" id="L82"> h = (h * 3) ^ spanQuery.hashCode();</span>
<span class="pc bpc" id="L83" title="1 of 2 branches missed."> h += (optional ? 1 : 0);</span>
<span class="fc" id="L84"> 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="L95"> MtasSpanQuery newSpanQuery = spanQuery.rewrite(reader);</span>
<span class="fc bfc" id="L96" title="All 2 branches covered."> if (!newSpanQuery.equals(spanQuery)) {</span>
<span class="fc" id="L97"> return new MtasSpanSequenceItem(newSpanQuery, optional);</span>
} else {
<span class="fc" id="L99"> return this;</span>
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
<span class="nc bnc" id="L110" 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="L126" title="1 of 4 branches missed."> if (item1 == null || item2 == null) {</span>
<span class="fc" id="L127"> return null;</span>
} else {
<span class="fc" id="L129"> MtasSpanQuery q1 = item1.getQuery();</span>
<span class="fc" id="L130"> MtasSpanQuery q2 = item2.getQuery();</span>
<span class="pc bpc" id="L131" title="1 of 4 branches missed."> boolean optional = item1.optional && item2.optional;</span>
// first spanRecurrenceQuery
<span class="fc bfc" id="L133" title="All 2 branches covered."> if (q1 instanceof MtasSpanRecurrenceQuery) {</span>
<span class="fc" id="L134"> MtasSpanRecurrenceQuery rq1 = (MtasSpanRecurrenceQuery) q1;</span>
// both spanRecurrenceQuery
<span class="pc bpc" id="L136" title="1 of 2 branches missed."> if (q2 instanceof MtasSpanRecurrenceQuery) {</span>
<span class="nc" id="L137"> MtasSpanRecurrenceQuery rq2 = (MtasSpanRecurrenceQuery) q2;</span>
// equal query
<span class="nc bnc" id="L139" title="All 2 branches missed."> if (rq1.getQuery().equals(rq2.getQuery())) {</span>
// equal ignoreQuery settings
boolean checkCondition;
<span class="nc bnc" id="L142" title="All 2 branches missed."> checkCondition = ignoreQuery != null</span>
<span class="nc bnc" id="L143" title="All 2 branches missed."> && rq1.getIgnoreQuery() != null;</span>
<span class="nc bnc" id="L144" title="All 2 branches missed."> checkCondition = checkCondition</span>
<span class="nc" id="L145"> ? ignoreQuery.equals(rq1.getIgnoreQuery()) : false;</span>
<span class="nc bnc" id="L146" title="All 2 branches missed."> checkCondition = checkCondition</span>
<span class="nc" id="L147"> ? maximumIgnoreLength.equals(rq1.getMaximumIgnoreLength())</span>
: false;
<span class="nc bnc" id="L149" title="All 4 branches missed."> checkCondition = checkCondition ? rq2.getIgnoreQuery() != null</span>
: false;
<span class="nc bnc" id="L151" title="All 2 branches missed."> checkCondition = checkCondition</span>
<span class="nc" id="L152"> ? ignoreQuery.equals(rq2.getIgnoreQuery()) : false;</span>
<span class="nc bnc" id="L153" title="All 2 branches missed."> checkCondition = checkCondition</span>
<span class="nc" id="L154"> ? maximumIgnoreLength.equals(rq2.getMaximumIgnoreLength())</span>
: false;
<span class="nc bnc" id="L156" title="All 2 branches missed."> if (checkCondition) {</span>
// at least one optional
<span class="nc bnc" id="L158" title="All 4 branches missed."> if (item1.optional || item2.optional) {</span>
<span class="nc" id="L159"> int minimum = Math.min(rq1.getMinimumRecurrence(),</span>
<span class="nc" id="L160"> rq2.getMinimumRecurrence());</span>
<span class="nc" id="L161"> int maximum = rq1.getMaximumRecurrence()</span>
<span class="nc" id="L162"> + rq2.getMaximumRecurrence();</span>
// only if ranges match
<span class="nc" id="L164"> if ((rq1.getMaximumRecurrence() + 1) >= rq2</span>
<span class="nc bnc" id="L165" title="All 2 branches missed."> .getMinimumRecurrence()</span>
<span class="nc" id="L166"> && (rq2.getMaximumRecurrence() + 1) >= rq1</span>
<span class="nc bnc" id="L167" title="All 2 branches missed."> .getMinimumRecurrence()) {</span>
<span class="nc" id="L168"> return new MtasSpanSequenceItem(</span>
<span class="nc" id="L169"> new MtasSpanRecurrenceQuery(rq1.getQuery(), minimum,</span>
maximum, ignoreQuery, maximumIgnoreLength),
optional);
}
// not optional
<span class="nc" id="L174"> } else {</span>
<span class="nc" id="L175"> int minimum = rq1.getMinimumRecurrence()</span>
<span class="nc" id="L176"> + rq2.getMinimumRecurrence();</span>
<span class="nc" id="L177"> int maximum = rq1.getMaximumRecurrence()</span>
<span class="nc" id="L178"> + rq2.getMaximumRecurrence();</span>
// only if ranges match
<span class="nc" id="L180"> if ((rq1.getMaximumRecurrence() + 1) >= rq2</span>
<span class="nc bnc" id="L181" title="All 2 branches missed."> .getMinimumRecurrence()</span>
<span class="nc" id="L182"> && (rq2.getMaximumRecurrence() + 1) >= rq1</span>
<span class="nc bnc" id="L183" title="All 2 branches missed."> .getMinimumRecurrence()) {</span>
<span class="nc" id="L184"> return new MtasSpanSequenceItem(</span>
<span class="nc" id="L185"> new MtasSpanRecurrenceQuery(rq1.getQuery(), minimum,</span>
maximum, ignoreQuery, maximumIgnoreLength),
optional);
}
}
}
}
<span class="nc" id="L192"> } else {</span>
<span class="pc bpc" id="L193" title="1 of 2 branches missed."> if (rq1.getQuery().equals(q2)) {</span>
boolean checkCondition;
<span class="nc bnc" id="L195" title="All 2 branches missed."> checkCondition = ignoreQuery != null;</span>
<span class="nc bnc" id="L196" title="All 2 branches missed."> checkCondition &= rq1.getIgnoreQuery() != null;</span>
<span class="nc" id="L197"> checkCondition &= ignoreQuery.equals(rq1.getIgnoreQuery());</span>
<span class="nc bnc" id="L198" title="All 2 branches missed."> checkCondition &= rq1.getMaximumIgnoreLength() != null;</span>
<span class="nc" id="L199"> checkCondition &= maximumIgnoreLength</span>
<span class="nc" id="L200"> .equals(rq1.getMaximumIgnoreLength());</span>
<span class="nc bnc" id="L201" title="All 2 branches missed."> if (checkCondition) {</span>
<span class="nc bnc" id="L202" title="All 2 branches missed."> if (!optional) {</span>
<span class="nc bnc" id="L203" title="All 2 branches missed."> if (item1.optional) {</span>
<span class="nc bnc" id="L204" title="All 2 branches missed."> if (rq1.getMinimumRecurrence() == 1) {</span>
<span class="nc" id="L205"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(</span>
<span class="nc" id="L206"> q2, 1, rq1.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), false);
}
<span class="nc bnc" id="L209" title="All 2 branches missed."> } else if (item2.optional) {</span>
<span class="nc" id="L210"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(</span>
<span class="nc" id="L211"> q2, rq1.getMinimumRecurrence(),</span>
<span class="nc" id="L212"> rq1.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), false);
} else {
<span class="nc" id="L215"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(</span>
<span class="nc" id="L216"> q2, rq1.getMinimumRecurrence() + 1,</span>
<span class="nc" id="L217"> rq1.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), false);
}
} else {
<span class="nc bnc" id="L221" title="All 2 branches missed."> if (rq1.getMinimumRecurrence() == 1) {</span>
<span class="nc" id="L222"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(</span>
<span class="nc" id="L223"> q2, 1, rq1.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), true);
}
}
}
}
}
// second spanRecurrenceQuery
<span class="fc bfc" id="L231" title="All 2 branches covered."> } else if (q2 instanceof MtasSpanRecurrenceQuery) {</span>
<span class="fc" id="L232"> MtasSpanRecurrenceQuery rq2 = (MtasSpanRecurrenceQuery) q2;</span>
<span class="pc bpc" id="L233" title="1 of 2 branches missed."> if (rq2.getQuery().equals(q1)) {</span>
boolean checkCondition;
<span class="nc bnc" id="L235" title="All 2 branches missed."> checkCondition = ignoreQuery != null;</span>
<span class="nc bnc" id="L236" title="All 2 branches missed."> checkCondition &= rq2.getIgnoreQuery() != null;</span>
<span class="nc" id="L237"> checkCondition &= ignoreQuery.equals(rq2.getIgnoreQuery());</span>
<span class="nc" id="L238"> checkCondition &= maximumIgnoreLength</span>
<span class="nc" id="L239"> .equals(rq2.getMaximumIgnoreLength());</span>
<span class="nc bnc" id="L240" title="All 2 branches missed."> if (checkCondition) {</span>
<span class="nc bnc" id="L241" title="All 2 branches missed."> if (!optional) {</span>
<span class="nc bnc" id="L242" title="All 2 branches missed."> if (item1.optional) {</span>
<span class="nc" id="L243"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1,</span>
<span class="nc" id="L244"> rq2.getMinimumRecurrence(), rq2.getMaximumRecurrence() + 1,</span>
ignoreQuery, maximumIgnoreLength), false);
<span class="nc bnc" id="L246" title="All 2 branches missed."> } else if (item2.optional) {</span>
<span class="nc bnc" id="L247" title="All 2 branches missed."> if (rq2.getMinimumRecurrence() == 1) {</span>
<span class="nc" id="L248"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(</span>
<span class="nc" id="L249"> q1, 1, rq2.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), false);
}
} else {
<span class="nc" id="L253"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1,</span>
<span class="nc" id="L254"> rq2.getMinimumRecurrence() + 1,</span>
<span class="nc" id="L255"> rq2.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), false);
}
} else {
<span class="nc bnc" id="L259" title="All 2 branches missed."> if (rq2.getMinimumRecurrence() == 1) {</span>
<span class="nc" id="L260"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1,</span>
<span class="nc" id="L261"> 1, rq2.getMaximumRecurrence() + 1, ignoreQuery,</span>
maximumIgnoreLength), true);
}
}
}
}
// both no spanRecurrenceQuery
<span class="pc bpc" id="L268" title="1 of 2 branches missed."> } else if (q1.equals(q2)) {</span>
// at least one optional
<span class="nc bnc" id="L270" title="All 4 branches missed."> if (item1.optional || item2.optional) {</span>
<span class="nc" id="L271"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1, 1, 2,</span>
ignoreQuery, maximumIgnoreLength), optional);
} else {
<span class="nc" id="L274"> return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1, 2, 2,</span>
ignoreQuery, maximumIgnoreLength), optional);
}
}
<span class="fc" id="L278"> 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>