On May 18, 2015, at 7:07 PM, Paul Sandoz <[email protected]> wrote: > jdk.internal.jimage.ImageFileCreator > -- > > 108 private void readAllEntries(Map<String, Set<String>> > modulePackagesMap, > 109 Set<Archive> archives) { > 110 archives.stream().forEach((archive) -> { > 111 List<Entry> archiveResources = new ArrayList<>(); > 112 archive.visitEntries(x-> archiveResources.add(x)); > 113 String mn = archive.moduleName(); > 114 entriesForModule.put(mn, archiveResources); > 115 // Extract package names > 116 List<Entry> classes = archiveResources.stream() > 117 .filter(n -> n.type() == EntryType.CLASS_OR_RESOURCE) > 118 .collect(Collectors.toList()); > 119 Set<String> pkgs = classes.stream().map(Entry::name) > 120 .filter(n -> isResourcePackage(n)) > 121 .map(ImageFileCreator::toPackage) > 122 .collect(Collectors.toSet()); > 123 modulePackagesMap.put(mn, pkgs); > 124 }); > 125 } > > Do not need to create the intermediate List<Entry>. > > If archive.vistEntries was changed instead to: > > Stream<Entry> entries(); > > The code above might flow better and, off the top of my head, you could do > something like: > > archives.stream().forEach((archive) -> { > Map<Boolean, List<Entry>> es = archive.entries() > .collect(Collectors.partitioningBy(n -> n.type() == > EntryType.CLASS_OR_RESOURCE)); >
I am talking nonsense here, Collectors.partitioningBy cannot be used, but i think the general approach of a stream returning method is still valid. Paul. > String mn = archive.moduleName(); > entriesForModule.put(mn, es.get(false)); > > // Extract package names > Set<String> pkgs = es.get(true).stream().map(Entry::name) > .filter(n -> isResourcePackage(n)) > .map(ImageFileCreator::toPackage) > .collect(Collectors.toSet()); > modulePackagesMap.put(mn, pkgs); > }); > > For recreateJimage i think you can then do: > > Map<String, List<Entry>> entriesForModule = > archives.stream().collect(Collectors.toMap( > Archive::moduleName, > a -> a.entries().collect(Collectors.toList()) > )); > > Or derive from Map<String, Archive> > > entriesForModule = nameToArchive.entrySet() > .stream() > .collect(Collectors.toMap(e -> e.getKey(), > e -> > e.getValue().entries().collect(Collectors.toList()))); > >
