20
20
/*
21
21
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
22
22
* Portions Copyright 2011 Jens Elkner.
23
- * Portions Copyright (c) 2018, 2020, Chris Fraire <[email protected] >.
23
+ * Portions Copyright (c) 2018- 2020, Chris Fraire <[email protected] >.
24
24
*/
25
25
package org .opengrok .indexer .search .context ;
26
26
@@ -70,8 +70,7 @@ public class Context {
70
70
* whose values tell if the field is case insensitive (true for
71
71
* insensitivity, false for sensitivity).
72
72
*/
73
- private static final Map <String , Boolean > TOKEN_FIELDS =
74
- new HashMap <String , Boolean >();
73
+ private static final Map <String , Boolean > TOKEN_FIELDS = new HashMap <>();
75
74
static {
76
75
TOKEN_FIELDS .put (QueryBuilder .FULL , Boolean .TRUE );
77
76
TOKEN_FIELDS .put (QueryBuilder .REFS , Boolean .FALSE );
@@ -188,7 +187,7 @@ public boolean getContext2(RuntimeEnvironment env, IndexSearcher searcher,
188
187
189
188
ContextArgs args = new ContextArgs (env .getContextSurround (),
190
189
env .getContextLimit ());
191
- /**
190
+ /*
192
191
* Lucene adds to the following value in FieldHighlighter, so avoid
193
192
* integer overflow by not using Integer.MAX_VALUE -- Short is good
194
193
* enough.
@@ -204,7 +203,7 @@ public boolean getContext2(RuntimeEnvironment env, IndexSearcher searcher,
204
203
205
204
OGKUnifiedHighlighter uhi = new OGKUnifiedHighlighter (env ,
206
205
searcher , anz );
207
- uhi .setBreakIterator (() -> new StrictLineBreakIterator () );
206
+ uhi .setBreakIterator (StrictLineBreakIterator :: new );
208
207
uhi .setFormatter (formatter );
209
208
uhi .setTabSize (tabSize );
210
209
@@ -251,11 +250,15 @@ private String buildQueryAsURI(Map<String, String> subqueries) {
251
250
252
251
private boolean alt = true ;
253
252
254
- public boolean getContext (Reader in , Writer out , String urlPrefix ,
253
+ /**
254
+ * This method exists only for testing.
255
+ */
256
+ boolean getContext (Reader in , Writer out , String urlPrefix ,
255
257
String morePrefix , String path , Definitions tags ,
256
258
boolean limit , boolean isDefSearch , List <Hit > hits ) {
257
259
return getContext (in , out , urlPrefix , morePrefix , path , tags , limit , isDefSearch , hits , null );
258
260
}
261
+
259
262
/**
260
263
* ???.
261
264
* Closes the given <var>in</var> reader on return.
@@ -285,11 +288,11 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
285
288
(urlPrefix == null ) ? "" : Util .URIEncodePath (urlPrefix );
286
289
String pathE = Util .URIEncodePath (path );
287
290
if (tags != null ) {
288
- matchingTags = new TreeMap <Integer , String [] >();
291
+ matchingTags = new TreeMap <>();
289
292
try {
290
293
for (Definitions .Tag tag : tags .getTags ()) {
291
- for (int i = 0 ; i < m . length ; i ++ ) {
292
- if (m [ i ] .match (tag .symbol ) == LineMatcher .MATCHED ) {
294
+ for (LineMatcher lineMatcher : m ) {
295
+ if (lineMatcher .match (tag .symbol ) == LineMatcher .MATCHED ) {
293
296
String scope = null ;
294
297
String scopeUrl = null ;
295
298
if (scopes != null ) {
@@ -359,7 +362,7 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
359
362
}
360
363
}
361
364
}
362
- /**
365
+ /*
363
366
* Just to get the matching tag send a null in
364
367
*/
365
368
if (in == null ) {
@@ -419,8 +422,8 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
419
422
int matchedLines = 0 ;
420
423
while ((token = tokens .yylex ()) != null && (!lim ||
421
424
matchedLines < limit_max_lines )) {
422
- for (int i = 0 ; i < m . length ; i ++ ) {
423
- matchState = m [ i ] .match (token );
425
+ for (LineMatcher lineMatcher : m ) {
426
+ matchState = lineMatcher .match (token );
424
427
if (matchState == LineMatcher .MATCHED ) {
425
428
if (!isDefSearch ) {
426
429
tokens .printContext ();
0 commit comments