Skip to content

Package: FileSystemMediaFolderFinder

FileSystemMediaFolderFinder

nameinstructionbranchcomplexitylinemethod
FileSystemMediaFolderFinder(FileSystemMediaFolder, Path)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
FileSystemMediaFolderFinder(FileSystemMediaFolderFinder, Object)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
computeResults()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
count()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
evaluateDirectoryStream(Function)
M: 16 C: 21
57%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 4 C: 3
43%
M: 0 C: 1
100%
lambda$computeResults$2(Path)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
lambda$computeResults$3(Stream)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
lambda$count$1(Stream)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$new$0(Path)
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
withPath(Path)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.model.impl;
28:
29: import javax.annotation.Nonnegative;
30: import javax.annotation.Nonnull;
31: import java.util.List;
32: import java.util.function.Function;
33: import java.util.function.Predicate;
34: import java.util.stream.Stream;
35: import java.util.stream.StreamSupport;
36: import java.io.IOException;
37: import java.nio.file.DirectoryStream;
38: import java.nio.file.Files;
39: import java.nio.file.Path;
40: import it.tidalwave.util.spi.FinderSupport;
41: import it.tidalwave.bluemarine2.model.spi.PathAwareEntity;
42: import it.tidalwave.bluemarine2.model.spi.PathAwareFinder;
43: import lombok.RequiredArgsConstructor;
44: import lombok.extern.slf4j.Slf4j;
45: import static java.util.stream.Collectors.*;
46:
47: /***********************************************************************************************************************
48: *
49: * An {@link PathAwareFinder} for retrieving children of a {@link FileSystemMediaFolder}.
50: *
51: * @stereotype Finder
52: *
53: * @author Fabrizio Giudici
54: *
55: **********************************************************************************************************************/
56: @RequiredArgsConstructor @Slf4j
57: public class FileSystemMediaFolderFinder extends FinderSupport<PathAwareEntity, PathAwareFinder> implements PathAwareFinder
58: {
59: private static final long serialVersionUID = 7656309392185783930L;
60:
61: @Nonnull
62: private final FileSystemMediaFolder mediaFolder;
63:
64: @Nonnull
65: private final Path basePath;
66:
67: // FIXME: implement a better filter looking at the file name suffix
68:• private final Predicate<? super Path> fileFilter = path -> !path.toFile().getName().equals(".DS_Store");
69:
70: public FileSystemMediaFolderFinder (@Nonnull final FileSystemMediaFolderFinder other, @Nonnull final Object override)
71: {
72: super(other, override);
73: final FileSystemMediaFolderFinder source = getSource(FileSystemMediaFolderFinder.class, other, override);
74: this.mediaFolder = source.mediaFolder;
75: this.basePath = source.basePath;
76: }
77:
78: @Override @Nonnegative
79: public int count()
80: {
81: return evaluateDirectoryStream(stream -> stream.filter(fileFilter).count()).intValue();
82: }
83:
84: @Override @Nonnull
85: public PathAwareFinder withPath (@Nonnull final Path path)
86: {
87: throw new UnsupportedOperationException("Not supported yet."); // TODO
88: }
89:
90: @Override @Nonnull
91: protected List<? extends PathAwareEntity> computeResults()
92: {
93: return evaluateDirectoryStream(stream -> stream
94: .filter(fileFilter)
95:• .map(child -> Files.isDirectory(child)
96: ? new FileSystemMediaFolder(child, mediaFolder, basePath)
97: : new FileSystemAudioFile(child, mediaFolder, basePath))
98: .collect(toList()));
99: }
100:
101: private <T> T evaluateDirectoryStream (@Nonnull final Function<Stream<Path>, T> function)
102: {
103:• if (!Files.exists(mediaFolder.getPath()))
104: {
105: return function.apply(Stream.of());
106: }
107:
108: try (final DirectoryStream<Path> stream = Files.newDirectoryStream(mediaFolder.getPath()))
109: {
110: return function.apply(StreamSupport.stream(stream.spliterator(), false));
111: }
112: catch (IOException e)
113: {
114: log.error("", e);
115: throw new RuntimeException(e);
116: }
117: }
118: }