Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
OrQuery |
|
| 4.0;4 |
1 | /** | |
2 | * Distribution License: | |
3 | * JSword is free software; you can redistribute it and/or modify it under | |
4 | * the terms of the GNU Lesser General Public License, version 2.1 or later | |
5 | * as published by the Free Software Foundation. This program is distributed | |
6 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
7 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
8 | * See the GNU Lesser General Public License for more details. | |
9 | * | |
10 | * The License is available on the internet at: | |
11 | * http://www.gnu.org/copyleft/lgpl.html | |
12 | * or by writing to: | |
13 | * Free Software Foundation, Inc. | |
14 | * 59 Temple Place - Suite 330 | |
15 | * Boston, MA 02111-1307, USA | |
16 | * | |
17 | * © CrossWire Bible Society, 2005 - 2016 | |
18 | */ | |
19 | package org.crosswire.jsword.index.query; | |
20 | ||
21 | import org.crosswire.jsword.book.BookException; | |
22 | import org.crosswire.jsword.index.Index; | |
23 | import org.crosswire.jsword.passage.Key; | |
24 | import org.crosswire.jsword.passage.PassageTally; | |
25 | ||
26 | /** | |
27 | * An OR query specifies that a result is the union of the left and the right | |
28 | * query results. | |
29 | * | |
30 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
31 | * @author DM Smith | |
32 | */ | |
33 | public class OrQuery extends AbstractBinaryQuery { | |
34 | ||
35 | /** | |
36 | * @param theLeftQuery | |
37 | * @param theRightQuery | |
38 | */ | |
39 | public OrQuery(Query theLeftQuery, Query theRightQuery) { | |
40 | 0 | super(theLeftQuery, theRightQuery); |
41 | 0 | } |
42 | ||
43 | /* (non-Javadoc) | |
44 | * @see org.crosswire.jsword.index.query.Query#find(org.crosswire.jsword.index.Index) | |
45 | */ | |
46 | public Key find(Index index) throws BookException { | |
47 | 0 | Key left = getLeftQuery().find(index); |
48 | 0 | Key right = getRightQuery().find(index); |
49 | ||
50 | 0 | if (left.isEmpty()) { |
51 | 0 | return right; |
52 | } | |
53 | ||
54 | 0 | if (right.isEmpty()) { |
55 | 0 | return left; |
56 | } | |
57 | ||
58 | // If ranking was requested then prioritize it. | |
59 | 0 | if (right instanceof PassageTally) { |
60 | 0 | right.addAll(left); |
61 | 0 | return right; |
62 | } | |
63 | ||
64 | 0 | left.addAll(right); |
65 | ||
66 | 0 | return left; |
67 | } | |
68 | } |