16
16
17
17
package nextflow.lineage
18
18
19
- import java.nio.file.FileVisitResult
20
- import java.nio.file.FileVisitor
21
19
import java.nio.file.Files
22
20
import java.nio.file.Path
23
- import java.nio.file.attribute.BasicFileAttributes
21
+ import java.util.stream.Stream
24
22
25
23
import groovy.transform.CompileStatic
26
24
import groovy.util.logging.Slf4j
@@ -93,70 +91,32 @@ class DefaultLinStore implements LinStore {
93
91
void close () throws IOException {}
94
92
95
93
@Override
96
- Map<String , LinSerializable > search (Map<String , List<String > > params ) {
97
- final results = new HashMap<String , LinSerializable > ()
98
-
99
- Files . walkFileTree(location, new FileVisitor<Path > () {
100
-
101
- @Override
102
- FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs ) throws IOException {
103
- FileVisitResult . CONTINUE
104
- }
105
-
106
- @Override
107
- FileVisitResult visitFile (Path file , BasicFileAttributes attrs ) throws IOException {
108
- if ( file. name. startsWith(' .data.json' ) ) {
109
- final lidObject = encoder. decode(file. text)
110
- if ( LinUtils . checkParams(lidObject, params) ) {
111
- results. put(location. relativize(file. getParent()). toString(), lidObject as LinSerializable )
112
- }
113
- }
114
- FileVisitResult . CONTINUE
94
+ Stream<String > search (Map<String , List<String > > params ) {
95
+ return Files . walk(location)
96
+ .filter { Path path ->
97
+ Files . isRegularFile(path) && path. fileName. toString(). startsWith(' .data.json' )
115
98
}
116
-
117
- @Override
118
- FileVisitResult visitFileFailed ( Path file , IOException exc ) throws IOException {
119
- FileVisitResult . CONTINUE
99
+ .map { Path path ->
100
+ final obj = encoder . decode(path . text)
101
+ final key = location . relativize(path . parent) . toString()
102
+ return new AbstractMap.SimpleEntry < String , LinSerializable >(key, obj)
120
103
}
121
-
122
- @Override
123
- FileVisitResult postVisitDirectory (Path dir , IOException exc ) throws IOException {
124
- FileVisitResult . CONTINUE
104
+ .filter { entry ->
105
+ LinUtils . checkParams(entry. value, params)
125
106
}
126
- })
127
-
128
- return results
107
+ .map {it -> it. key }
129
108
}
130
109
131
110
@Override
132
- List<String > getSubKeys (String parentKey ) {
133
- final results = new LinkedList<String > ()
111
+ Stream<String > getSubKeys (String parentKey ) {
134
112
final startPath = location. resolve(parentKey)
135
- Files . walkFileTree(startPath, new FileVisitor<Path > () {
136
-
137
- @Override
138
- FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs ) throws IOException {
139
- FileVisitResult . CONTINUE
140
- }
141
113
142
- @Override
143
- FileVisitResult visitFile (Path file , BasicFileAttributes attrs ) throws IOException {
144
- if ( file. name. startsWith(' .data.json' ) && file. parent != startPath ) {
145
- results << location. relativize(file. parent). toString()
146
- }
147
- FileVisitResult . CONTINUE
114
+ return Files . walk(startPath)
115
+ .filter { Path path ->
116
+ Files . isRegularFile(path) && path. fileName. toString(). startsWith(' .data.json' ) && path. parent != startPath
148
117
}
149
-
150
- @Override
151
- FileVisitResult visitFileFailed (Path file , IOException exc ) throws IOException {
152
- FileVisitResult . CONTINUE
153
- }
154
-
155
- @Override
156
- FileVisitResult postVisitDirectory (Path dir , IOException exc ) throws IOException {
157
- FileVisitResult . CONTINUE
118
+ .map { Path path ->
119
+ location. relativize(path. parent). toString()
158
120
}
159
- })
160
- return results
161
121
}
162
- }
122
+ }
0 commit comments