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

ljacqu / FileDuplicateFinder / 13977395174

20 Mar 2025 07:07PM UTC coverage: 23.055% (-0.7%) from 23.77%
13977395174

push

github

ljacqu
Merge remote-tracking branch 'origin/master' into dependencies

# Conflicts:
#	pom.xml

111 of 610 branches covered (18.2%)

Branch coverage included in aggregate %.

22 of 225 new or added lines in 15 files covered. (9.78%)

13 existing lines in 7 files now uncovered.

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

94.44
/src/main/java/ch/jalu/fileduplicatefinder/duplicatefinder/output/ConsoleResultOutputter.java
1
package ch.jalu.fileduplicatefinder.duplicatefinder.output;
2

3
import ch.jalu.fileduplicatefinder.config.FileUtilConfiguration;
4
import ch.jalu.fileduplicatefinder.duplicatefinder.DuplicateEntry;
5
import ch.jalu.fileduplicatefinder.duplicatefinder.FolderPair;
6
import ch.jalu.fileduplicatefinder.output.WriterReader;
7

8
import java.nio.file.Path;
9
import java.util.List;
10
import java.util.Map;
11
import java.util.stream.Collectors;
12

13
import static ch.jalu.fileduplicatefinder.config.FileUtilSettings.DUPLICATE_FOLDER;
14
import static ch.jalu.fileduplicatefinder.config.FileUtilSettings.DUPLICATE_OUTPUT_DUPLICATES;
15
import static ch.jalu.fileduplicatefinder.utils.FileSizeUtils.formatToHumanReadableSize;
16

17
/**
18
 * Outputs results to the console.
19
 */
20
public class ConsoleResultOutputter implements DuplicateEntryOutputter {
21

22
    private final FileUtilConfiguration configuration;
23
    private final WriterReader logger;
24

25
    public ConsoleResultOutputter(FileUtilConfiguration configuration,
26
                                  WriterReader logger) {
2✔
27
        this.configuration = configuration;
3✔
28
        this.logger = logger;
3✔
29
    }
1✔
30

31
    @Override
32
    public void outputResult(List<DuplicateEntry> duplicates) {
33
        logger.printNewLine();
3✔
34
        if (duplicates.isEmpty()) {
3✔
35
            output("No duplicates found.");
4✔
36
        } else if (configuration.getValue(DUPLICATE_OUTPUT_DUPLICATES)) {
7✔
37
            long sum = 0;
2✔
38
            for (DuplicateEntry entry : duplicates) {
10✔
39
                output(formatEntry(entry));
5✔
40
                sum += entry.getSize() * (entry.getPaths().size() - 1);
12✔
41
            }
1✔
42

43
            output("Total duplicated data: " + formatToHumanReadableSize(sum));
5✔
44
            output("Total: " + duplicates.size() + " duplicates");
5✔
45
        }
46
    }
1✔
47

48
    @Override
49
    public void outputDirectoryPairs(Map<FolderPair, Long> totalDuplicatesByFolderPair) {
50
        Path rootFolder = configuration.getValueOrPrompt(DUPLICATE_FOLDER);
6✔
51
        totalDuplicatesByFolderPair.entrySet().stream()
3✔
52
            .sorted(Map.Entry.<FolderPair, Long>comparingByValue().reversed())
5✔
53
            .map(cell -> cell.getValue() + ": " + cell.getKey().createTextOutput(rootFolder))
12✔
54
            .forEach(this::output);
1✔
55
    }
1✔
56

57
    private String formatEntry(DuplicateEntry entry) {
58
        String files = entry.getPaths().stream()
5✔
59
            .map(path -> configuration.getValueOrPrompt(DUPLICATE_FOLDER).relativize(path).toString())
10✔
60
            .sorted()
2✔
61
            .collect(Collectors.joining(", "));
4✔
62
        String size = formatToHumanReadableSize(entry.getSize());
4✔
63
        return String.format("[%s][%d] %s: %s", size, entry.getPaths().size(), entry.getHash(), files);
25✔
64
    }
65

66
    protected void output(String str) {
NEW
67
        logger.printLn(str);
×
68
    }
×
69
}
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

© 2026 Coveralls, Inc