@Test public void testEmpty() throws Exception { final List<Path> files = new ArrayList<Path>(); ReadMetadataWorker worker = new ReadMetadataWorker(files) { @Override public void cleanup(final Map<String, String> result) { fail(); } }; assertTrue(worker.run(new NullSession(new Host(new TestProtocol())) { @Override @SuppressWarnings("unchecked") public <T> T _getFeature(final Class<T> type) { if(type == Metadata.class) { return (T) new Metadata() { @Override public Map<String, String> getDefault(final Local local) { return Collections.emptyMap(); } @Override public Map<String, String> getMetadata(final Path file) { throw new UnsupportedOperationException(); } @Override public void setMetadata(final Path file, final TransferStatus status) { throw new UnsupportedOperationException(); } }; } return super._getFeature(type); } }).isEmpty()); }
@Override public Map<String, String> run(final Session<?> session) throws BackgroundException { final Metadata feature = session.getFeature(Metadata.class); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", feature)); } final Map<String, Map<Path, String>> graphMetadata = new HashMap<>(); for(Path next : files) { if(Collections.<String, String>emptyMap() == next.attributes().getMetadata()) { final Map<String, String> metadata = feature.getMetadata(next); next.attributes().setMetadata(metadata); } for(Map.Entry<String, String> entry : next.attributes().getMetadata().entrySet()) { if(graphMetadata.containsKey(entry.getKey())) { graphMetadata.get(entry.getKey()).put(next, entry.getValue()); } else { Map<Path, String> map = new HashMap<>(); graphMetadata.put(entry.getKey(), map); map.put(next, entry.getValue()); } } } Map<String, String> metadata = new HashMap<>(); for(Map.Entry<String, Map<Path, String>> entry : graphMetadata.entrySet()) { if(entry.getValue().size() != files.size()) { metadata.put(entry.getKey(), null); } else { Supplier<Stream<String>> valueSupplier = () -> entry.getValue().values().stream().distinct(); String value = valueSupplier.get().count() == 1 ? valueSupplier.get().findAny().get() : null; metadata.put(entry.getKey(), value); } } return metadata; }
ReadMetadataWorker extends Worker<Map<String, String>> { @Override public Map<String, String> run(final Session<?> session) throws BackgroundException { final Metadata feature = session.getFeature(Metadata.class); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", feature)); } final Map<String, Map<Path, String>> graphMetadata = new HashMap<>(); for(Path next : files) { if(Collections.<String, String>emptyMap() == next.attributes().getMetadata()) { final Map<String, String> metadata = feature.getMetadata(next); next.attributes().setMetadata(metadata); } for(Map.Entry<String, String> entry : next.attributes().getMetadata().entrySet()) { if(graphMetadata.containsKey(entry.getKey())) { graphMetadata.get(entry.getKey()).put(next, entry.getValue()); } else { Map<Path, String> map = new HashMap<>(); graphMetadata.put(entry.getKey(), map); map.put(next, entry.getValue()); } } } Map<String, String> metadata = new HashMap<>(); for(Map.Entry<String, Map<Path, String>> entry : graphMetadata.entrySet()) { if(entry.getValue().size() != files.size()) { metadata.put(entry.getKey(), null); } else { Supplier<Stream<String>> valueSupplier = () -> entry.getValue().values().stream().distinct(); String value = valueSupplier.get().count() == 1 ? valueSupplier.get().findAny().get() : null; metadata.put(entry.getKey(), value); } } return metadata; } }
ReadMetadataWorker extends Worker<Map<String, String>> { @Override public Map<String, String> run(final Session<?> session) throws BackgroundException { final Metadata feature = session.getFeature(Metadata.class); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", feature)); } final Map<String, Map<Path, String>> graphMetadata = new HashMap<>(); for(Path next : files) { if(Collections.<String, String>emptyMap() == next.attributes().getMetadata()) { final Map<String, String> metadata = feature.getMetadata(next); next.attributes().setMetadata(metadata); } for(Map.Entry<String, String> entry : next.attributes().getMetadata().entrySet()) { if(graphMetadata.containsKey(entry.getKey())) { graphMetadata.get(entry.getKey()).put(next, entry.getValue()); } else { Map<Path, String> map = new HashMap<>(); graphMetadata.put(entry.getKey(), map); map.put(next, entry.getValue()); } } } Map<String, String> metadata = new HashMap<>(); for(Map.Entry<String, Map<Path, String>> entry : graphMetadata.entrySet()) { if(entry.getValue().size() != files.size()) { metadata.put(entry.getKey(), null); } else { Supplier<Stream<String>> valueSupplier = () -> entry.getValue().values().stream().distinct(); String value = valueSupplier.get().count() == 1 ? valueSupplier.get().findAny().get() : null; metadata.put(entry.getKey(), value); } } return metadata; } ReadMetadataWorker(final List<Path> files); }
ReadMetadataWorker extends Worker<Map<String, String>> { @Override public Map<String, String> run(final Session<?> session) throws BackgroundException { final Metadata feature = session.getFeature(Metadata.class); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", feature)); } final Map<String, Map<Path, String>> graphMetadata = new HashMap<>(); for(Path next : files) { if(Collections.<String, String>emptyMap() == next.attributes().getMetadata()) { final Map<String, String> metadata = feature.getMetadata(next); next.attributes().setMetadata(metadata); } for(Map.Entry<String, String> entry : next.attributes().getMetadata().entrySet()) { if(graphMetadata.containsKey(entry.getKey())) { graphMetadata.get(entry.getKey()).put(next, entry.getValue()); } else { Map<Path, String> map = new HashMap<>(); graphMetadata.put(entry.getKey(), map); map.put(next, entry.getValue()); } } } Map<String, String> metadata = new HashMap<>(); for(Map.Entry<String, Map<Path, String>> entry : graphMetadata.entrySet()) { if(entry.getValue().size() != files.size()) { metadata.put(entry.getKey(), null); } else { Supplier<Stream<String>> valueSupplier = () -> entry.getValue().values().stream().distinct(); String value = valueSupplier.get().count() == 1 ? valueSupplier.get().findAny().get() : null; metadata.put(entry.getKey(), value); } } return metadata; } ReadMetadataWorker(final List<Path> files); @Override Map<String, String> run(final Session<?> session); @Override String getActivity(); @Override Map<String, String> initialize(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); }
ReadMetadataWorker extends Worker<Map<String, String>> { @Override public Map<String, String> run(final Session<?> session) throws BackgroundException { final Metadata feature = session.getFeature(Metadata.class); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", feature)); } final Map<String, Map<Path, String>> graphMetadata = new HashMap<>(); for(Path next : files) { if(Collections.<String, String>emptyMap() == next.attributes().getMetadata()) { final Map<String, String> metadata = feature.getMetadata(next); next.attributes().setMetadata(metadata); } for(Map.Entry<String, String> entry : next.attributes().getMetadata().entrySet()) { if(graphMetadata.containsKey(entry.getKey())) { graphMetadata.get(entry.getKey()).put(next, entry.getValue()); } else { Map<Path, String> map = new HashMap<>(); graphMetadata.put(entry.getKey(), map); map.put(next, entry.getValue()); } } } Map<String, String> metadata = new HashMap<>(); for(Map.Entry<String, Map<Path, String>> entry : graphMetadata.entrySet()) { if(entry.getValue().size() != files.size()) { metadata.put(entry.getKey(), null); } else { Supplier<Stream<String>> valueSupplier = () -> entry.getValue().values().stream().distinct(); String value = valueSupplier.get().count() == 1 ? valueSupplier.get().findAny().get() : null; metadata.put(entry.getKey(), value); } } return metadata; } ReadMetadataWorker(final List<Path> files); @Override Map<String, String> run(final Session<?> session); @Override String getActivity(); @Override Map<String, String> initialize(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }