24
24
package org .opengrok .indexer .history ;
25
25
26
26
import java .util .ArrayList ;
27
+ import java .util .Collections ;
28
+ import java .util .HashSet ;
27
29
import java .util .List ;
30
+ import java .util .Objects ;
31
+ import java .util .Set ;
28
32
29
33
/**
30
34
* Class representing the history of a file.
@@ -37,19 +41,19 @@ public class History {
37
41
* SCMs) during cache creation.
38
42
* These are relative to repository root.
39
43
*/
40
- private List <String > renamedFiles = new ArrayList <>() ;
44
+ private final Set <String > renamedFiles ;
41
45
42
46
public History () {
43
47
this (new ArrayList <>());
44
48
}
45
49
46
50
History (List <HistoryEntry > entries ) {
47
- this . entries = entries ;
51
+ this ( entries , Collections . emptyList ()) ;
48
52
}
49
53
50
54
History (List <HistoryEntry > entries , List <String > renamed ) {
51
55
this .entries = entries ;
52
- this .renamedFiles = renamed ;
56
+ this .renamedFiles = new HashSet <>( renamed ) ;
53
57
}
54
58
55
59
/**
@@ -83,21 +87,18 @@ public List<HistoryEntry> getHistoryEntries(int limit, int offset) {
83
87
offset = Math .max (offset , 0 );
84
88
limit = offset + limit > entries .size () ? entries .size () - offset : limit ;
85
89
return entries .subList (offset , offset + limit );
86
- }
87
-
90
+ }
91
+
88
92
/**
89
93
* Check if at least one history entry has a file list.
90
94
*
91
95
* @return {@code true} if at least one of the entries has a non-empty
92
96
* file list, {@code false} otherwise
93
97
*/
94
98
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 ());
101
102
}
102
103
103
104
/**
@@ -107,24 +108,19 @@ public boolean hasFileList() {
107
108
* tag list, {@code false} otherwise
108
109
*/
109
110
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 );
117
114
}
118
115
119
116
/**
120
117
* Gets a value indicating if {@code file} is in the list of renamed files.
121
- * TODO: Warning -- this does a slow {@link List} search.
122
118
*/
123
119
public boolean isRenamed (String file ) {
124
120
return renamedFiles .contains (file );
125
121
}
126
122
127
- public List <String > getRenamedFiles () {
123
+ public Set <String > getRenamedFiles () {
128
124
return renamedFiles ;
129
125
}
130
126
}
0 commit comments