Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
IteratorSearchResponse |
|
| 1.0833333333333333;1,083 | ||||
IteratorSearchResponse$1 |
|
| 1.0833333333333333;1,083 |
1 | package org.apache.maven.index; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.Closeable; | |
23 | import java.io.IOException; | |
24 | import java.util.Iterator; | |
25 | ||
26 | import org.apache.lucene.search.Query; | |
27 | ||
28 | /** | |
29 | * A Search Response for the "iterator-like" search request. The totalHitsCount reports <em>total</em> hits found on | |
30 | * index, even if the set of ArtifactInfos are usually limited! On the flipside, the hitsCount is actually unknown, | |
31 | * since this instance performs filtering on the fly, hence it does not know how many hits it will return ahead of time. | |
32 | * | |
33 | * @author cstamas | |
34 | */ | |
35 | 85 | public class IteratorSearchResponse |
36 | extends AbstractSearchResponse | |
37 | implements Iterable<ArtifactInfo>, Closeable | |
38 | { | |
39 | private final IteratorResultSet results; | |
40 | ||
41 | public IteratorSearchResponse( Query query, int totalHits, IteratorResultSet results ) | |
42 | { | |
43 | 135 | super( query, totalHits, -1 ); |
44 | ||
45 | 135 | this.results = results; |
46 | 135 | } |
47 | ||
48 | public IteratorResultSet getResults() | |
49 | { | |
50 | 203 | return results; |
51 | } | |
52 | ||
53 | public IteratorResultSet iterator() | |
54 | { | |
55 | 85 | return getResults(); |
56 | } | |
57 | ||
58 | @Override | |
59 | public void close() | |
60 | throws IOException | |
61 | { | |
62 | 111 | getResults().close(); |
63 | 111 | } |
64 | ||
65 | /** | |
66 | * A helper method delegating the call to the IteratorResultSet. | |
67 | * | |
68 | * @return | |
69 | */ | |
70 | public int getTotalProcessedArtifactInfoCount() | |
71 | { | |
72 | 0 | return getResults().getTotalProcessedArtifactInfoCount(); |
73 | } | |
74 | ||
75 | // == | |
76 | ||
77 | 1 | public static final IteratorResultSet EMPTY_ITERATOR_RESULT_SET = new IteratorResultSet() |
78 | 1 | { |
79 | public boolean hasNext() | |
80 | { | |
81 | 18 | return false; |
82 | } | |
83 | ||
84 | public ArtifactInfo next() | |
85 | { | |
86 | 0 | return null; |
87 | } | |
88 | ||
89 | public void remove() | |
90 | { | |
91 | 0 | throw new UnsupportedOperationException( "Method not supported on " + getClass().getName() ); |
92 | } | |
93 | ||
94 | public Iterator<ArtifactInfo> iterator() | |
95 | { | |
96 | 0 | return this; |
97 | } | |
98 | ||
99 | public int getTotalProcessedArtifactInfoCount() | |
100 | { | |
101 | 0 | return 0; |
102 | } | |
103 | ||
104 | public void close() | |
105 | throws IOException | |
106 | { | |
107 | 18 | } |
108 | }; | |
109 | ||
110 | public static final IteratorSearchResponse empty( final Query q ) | |
111 | { | |
112 | 19 | return new IteratorSearchResponse( q, 0, EMPTY_ITERATOR_RESULT_SET ); |
113 | } | |
114 | ||
115 | /** | |
116 | * Empty search response. | |
117 | * | |
118 | * @deprecated Use {@link #empty(Query)} instead. | |
119 | */ | |
120 | 1 | public static final IteratorSearchResponse EMPTY_ITERATOR_SEARCH_RESPONSE = empty( null ); |
121 | ||
122 | /** | |
123 | * Too many search response. | |
124 | * | |
125 | * @deprecated Left here for backward compatibility, but since version 4.1.0 (see MINDEXER-14) there is NO notion of "hit limit" anymore. | |
126 | */ | |
127 | 1 | public static final IteratorSearchResponse TOO_MANY_HITS_ITERATOR_SEARCH_RESPONSE = new IteratorSearchResponse( null, -1, EMPTY_ITERATOR_RESULT_SET ); |
128 | } |