2020/*
2121 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
2222 * Portions Copyright 2011 Jens Elkner.
23- * Portions Copyright (c) 2018, 2020, Chris Fraire <cfraire@me.com>.
23+ * Portions Copyright (c) 2018- 2020, Chris Fraire <cfraire@me.com>.
2424 */
2525package org .opengrok .indexer .search .context ;
2626
@@ -70,8 +70,7 @@ public class Context {
7070 * whose values tell if the field is case insensitive (true for
7171 * insensitivity, false for sensitivity).
7272 */
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 <>();
7574 static {
7675 TOKEN_FIELDS .put (QueryBuilder .FULL , Boolean .TRUE );
7776 TOKEN_FIELDS .put (QueryBuilder .REFS , Boolean .FALSE );
@@ -188,7 +187,7 @@ public boolean getContext2(RuntimeEnvironment env, IndexSearcher searcher,
188187
189188 ContextArgs args = new ContextArgs (env .getContextSurround (),
190189 env .getContextLimit ());
191- /**
190+ /*
192191 * Lucene adds to the following value in FieldHighlighter, so avoid
193192 * integer overflow by not using Integer.MAX_VALUE -- Short is good
194193 * enough.
@@ -204,7 +203,7 @@ public boolean getContext2(RuntimeEnvironment env, IndexSearcher searcher,
204203
205204 OGKUnifiedHighlighter uhi = new OGKUnifiedHighlighter (env ,
206205 searcher , anz );
207- uhi .setBreakIterator (() -> new StrictLineBreakIterator () );
206+ uhi .setBreakIterator (StrictLineBreakIterator :: new );
208207 uhi .setFormatter (formatter );
209208 uhi .setTabSize (tabSize );
210209
@@ -251,11 +250,15 @@ private String buildQueryAsURI(Map<String, String> subqueries) {
251250
252251 private boolean alt = true ;
253252
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 ,
255257 String morePrefix , String path , Definitions tags ,
256258 boolean limit , boolean isDefSearch , List <Hit > hits ) {
257259 return getContext (in , out , urlPrefix , morePrefix , path , tags , limit , isDefSearch , hits , null );
258260 }
261+
259262 /**
260263 * ???.
261264 * Closes the given <var>in</var> reader on return.
@@ -285,11 +288,11 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
285288 (urlPrefix == null ) ? "" : Util .URIEncodePath (urlPrefix );
286289 String pathE = Util .URIEncodePath (path );
287290 if (tags != null ) {
288- matchingTags = new TreeMap <Integer , String [] >();
291+ matchingTags = new TreeMap <>();
289292 try {
290293 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 ) {
293296 String scope = null ;
294297 String scopeUrl = null ;
295298 if (scopes != null ) {
@@ -359,7 +362,7 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
359362 }
360363 }
361364 }
362- /**
365+ /*
363366 * Just to get the matching tag send a null in
364367 */
365368 if (in == null ) {
@@ -419,8 +422,8 @@ public boolean getContext(Reader in, Writer out, String urlPrefix,
419422 int matchedLines = 0 ;
420423 while ((token = tokens .yylex ()) != null && (!lim ||
421424 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 );
424427 if (matchState == LineMatcher .MATCHED ) {
425428 if (!isDefSearch ) {
426429 tokens .printContext ();
0 commit comments