• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ljacqu / FileDuplicateFinder / 14006930974

22 Mar 2025 08:35AM UTC coverage: 23.055%. Remained the same
14006930974

push

github

ljacqu
Add Nullable annotation next to return value in methods

111 of 610 branches covered (18.2%)

Branch coverage included in aggregate %.

378 of 1511 relevant lines covered (25.02%)

1.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/ch/jalu/fileduplicatefinder/tree/FileTreeGenerator.java
1
package ch.jalu.fileduplicatefinder.tree;
2

3
import ch.jalu.fileduplicatefinder.utils.PathUtils;
4
import org.jetbrains.annotations.Nullable;
5

6
import java.nio.file.Files;
7
import java.nio.file.Path;
8
import java.util.List;
9
import java.util.Objects;
10
import java.util.stream.Collectors;
11

12
/**
13
 * Collects all files and directories and calculates the file size of the directory by summing up all its files.
14
 */
15
public class FileTreeGenerator {
16

17
    private final Path root;
18

19
    public FileTreeGenerator(Path root) {
×
20
        if (!Files.isDirectory(root)) {
×
21
            throw new IllegalArgumentException("Path '" + root + "' is not a directory");
×
22
        }
23
        this.root = root;
×
24
    }
×
25

26
    public FileTreeEntry generateTree(Runnable progressCallback) {
27
        return visit(root, progressCallback);
×
28
    }
29

30
    private @Nullable FileTreeEntry visit(Path path, Runnable progressCallback) {
31
        if (Files.isRegularFile(path)) {
×
32
            progressCallback.run();
×
33
            FileTreeEntry entry = new FileTreeEntry(path);
×
34
            entry.setSize(PathUtils.size(path));
×
35
            return entry;
×
36

37
        } else if (Files.isDirectory(path)) {
×
38
            progressCallback.run();
×
39
            long[] totalSize = { 0 };
×
40

41
            List<FileTreeEntry> childElements = PathUtils.list(path)
×
42
                .map(child -> visit(child, progressCallback))
×
43
                .filter(Objects::nonNull)
×
44
                .peek(entry -> totalSize[0] += entry.getSize())
×
45
                .collect(Collectors.toUnmodifiableList());
×
46

47
            FileTreeEntry entry = new FileTreeEntry(path);
×
48
            entry.setSize(totalSize[0]);
×
49
            entry.setChildren(childElements);
×
50
            return entry;
×
51
        }
52
        return null;
×
53
    }
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc