Skip to content

Commit

Permalink
Extract methods in FileReferencePrinter
Browse files Browse the repository at this point in the history
  • Loading branch information
patchwork01 committed Mar 11, 2024
1 parent bfe2c51 commit 54f9c3c
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import static java.util.Comparator.comparing;
import static java.util.function.Predicate.not;
import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toUnmodifiableList;

public class FileReferencePrinter {
Expand Down Expand Up @@ -60,17 +61,9 @@ public static String printFiles(PartitionTree tree, AllReferencesToAllFiles file
}

private static void printFiles(PartitionTree partitionTree, AllReferencesToAllFiles files, PrintWriter out) {
List<FileReference> references = files.getFilesWithReferences().stream()
.flatMap(file -> file.getInternalReferences().stream())
.sorted(comparing(FileReference::getNumberOfRecords).reversed())
.collect(toUnmodifiableList());
List<FileReference> references = sortFileReferences(files);
out.println("File references: " + references.size());
AtomicInteger partialCount = new AtomicInteger();
Map<String, Integer> numberByPartialFilename = references.stream()
.filter(not(FileReference::onlyContainsDataForThisPartition))
.map(FileReference::getFilename).distinct()
.map(filename -> Map.entry(filename, partialCount.incrementAndGet()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Map<String, Integer> numberByPartialFilename = numberPartialFiles(references);
Map<String, List<FileReference>> filesByPartition = references.stream()
.collect(Collectors.groupingBy(FileReference::getPartitionId));
partitionTree.traverseLeavesFirst().forEach(partition -> {
Expand Down Expand Up @@ -99,4 +92,20 @@ private static void printFiles(PartitionTree partitionTree, AllReferencesToAllFi
});
}

private static List<FileReference> sortFileReferences(AllReferencesToAllFiles files) {
return files.getFilesWithReferences().stream()
.flatMap(file -> file.getInternalReferences().stream())
.sorted(comparing(FileReference::getNumberOfRecords).reversed())
.collect(toUnmodifiableList());
}

private static Map<String, Integer> numberPartialFiles(List<FileReference> references) {
AtomicInteger partialCount = new AtomicInteger();
return references.stream()
.filter(not(FileReference::onlyContainsDataForThisPartition))
.map(FileReference::getFilename).distinct()
.map(filename -> Map.entry(filename, partialCount.incrementAndGet()))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}

}

0 comments on commit 54f9c3c

Please sign in to comment.