2424package org .opengrok .indexer .history ;
2525
2626import java .util .ArrayList ;
27+ import java .util .Collections ;
28+ import java .util .HashSet ;
2729import java .util .List ;
30+ import java .util .Objects ;
31+ import java .util .Set ;
2832
2933/**
3034 * Class representing the history of a file.
@@ -37,19 +41,19 @@ public class History {
3741 * SCMs) during cache creation.
3842 * These are relative to repository root.
3943 */
40- private List <String > renamedFiles = new ArrayList <>() ;
44+ private final Set <String > renamedFiles ;
4145
4246 public History () {
4347 this (new ArrayList <>());
4448 }
4549
4650 History (List <HistoryEntry > entries ) {
47- this . entries = entries ;
51+ this ( entries , Collections . emptyList ()) ;
4852 }
4953
5054 History (List <HistoryEntry > entries , List <String > renamed ) {
5155 this .entries = entries ;
52- this .renamedFiles = renamed ;
56+ this .renamedFiles = new HashSet <>( renamed ) ;
5357 }
5458
5559 /**
@@ -83,21 +87,18 @@ public List<HistoryEntry> getHistoryEntries(int limit, int offset) {
8387 offset = Math .max (offset , 0 );
8488 limit = offset + limit > entries .size () ? entries .size () - offset : limit ;
8589 return entries .subList (offset , offset + limit );
86- }
87-
90+ }
91+
8892 /**
8993 * Check if at least one history entry has a file list.
9094 *
9195 * @return {@code true} if at least one of the entries has a non-empty
9296 * file list, {@code false} otherwise
9397 */
9498 public boolean hasFileList () {
95- for (HistoryEntry entry : entries ) {
96- if (!entry .getFiles ().isEmpty ()) {
97- return true ;
98- }
99- }
100- return false ;
99+ return entries .stream ()
100+ .map (HistoryEntry ::getFiles )
101+ .anyMatch (files -> !files .isEmpty ());
101102 }
102103
103104 /**
@@ -107,24 +108,19 @@ public boolean hasFileList() {
107108 * tag list, {@code false} otherwise
108109 */
109110 public boolean hasTags () {
110- // TODO Use a private variable instead of for loop?
111- for (HistoryEntry entry : entries ) {
112- if (entry .getTags () != null ) {
113- return true ;
114- }
115- }
116- return false ;
111+ return entries .stream ()
112+ .map (HistoryEntry ::getTags )
113+ .anyMatch (Objects ::nonNull );
117114 }
118115
119116 /**
120117 * Gets a value indicating if {@code file} is in the list of renamed files.
121- * TODO: Warning -- this does a slow {@link List} search.
122118 */
123119 public boolean isRenamed (String file ) {
124120 return renamedFiles .contains (file );
125121 }
126122
127- public List <String > getRenamedFiles () {
123+ public Set <String > getRenamedFiles () {
128124 return renamedFiles ;
129125 }
130126}
0 commit comments