@Test public void testSearch() throws Exception { final Path workdir = new Path("/", EnumSet.of(Path.Type.directory)); final Path f1 = new Path(workdir, "f1", EnumSet.of(Path.Type.file)); final Path f2 = new Path(workdir, "f2", EnumSet.of(Path.Type.file)); final DefaultSearchFeature feature = new DefaultSearchFeature(new NullSession(new Host(new TestProtocol())) { @Override public AttributedList<Path> list(final Path folder, final ListProgressListener listener) throws BackgroundException { if(folder.equals(workdir)) { final AttributedList<Path> list = new AttributedList<>(Arrays.asList(f1, f2)); listener.chunk(folder, list); return list; } return AttributedList.emptyList(); } }); final Filter<Path> filter = new NullFilter<Path>() { @Override public boolean accept(final Path file) { if(file.isDirectory()) { return true; } return file.getName().equals("f1"); } }; final AttributedList<Path> search = feature.search(workdir, filter, new DisabledListProgressListener()); assertTrue(search.contains(f1)); assertFalse(search.contains(f2)); assertEquals(1, search.size()); }
@Override public AttributedList<Path> search(final Path workdir, final Filter<Path> filter, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> list; if(!cache.isCached(workdir)) { list = session.getFeature(ListService.class).list(workdir, new SearchListProgressListener(filter, listener)).filter(filter); } else { list = cache.get(workdir).filter(filter); } listener.chunk(workdir, list); return list; }
DefaultSearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> filter, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> list; if(!cache.isCached(workdir)) { list = session.getFeature(ListService.class).list(workdir, new SearchListProgressListener(filter, listener)).filter(filter); } else { list = cache.get(workdir).filter(filter); } listener.chunk(workdir, list); return list; } }
DefaultSearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> filter, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> list; if(!cache.isCached(workdir)) { list = session.getFeature(ListService.class).list(workdir, new SearchListProgressListener(filter, listener)).filter(filter); } else { list = cache.get(workdir).filter(filter); } listener.chunk(workdir, list); return list; } DefaultSearchFeature(final Session<?> session); }
DefaultSearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> filter, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> list; if(!cache.isCached(workdir)) { list = session.getFeature(ListService.class).list(workdir, new SearchListProgressListener(filter, listener)).filter(filter); } else { list = cache.get(workdir).filter(filter); } listener.chunk(workdir, list); return list; } DefaultSearchFeature(final Session<?> session); @Override AttributedList<Path> search(final Path workdir, final Filter<Path> filter, final ListProgressListener listener); @Override boolean isRecursive(); @Override Search withCache(final Cache<Path> cache); }
DefaultSearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> filter, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> list; if(!cache.isCached(workdir)) { list = session.getFeature(ListService.class).list(workdir, new SearchListProgressListener(filter, listener)).filter(filter); } else { list = cache.get(workdir).filter(filter); } listener.chunk(workdir, list); return list; } DefaultSearchFeature(final Session<?> session); @Override AttributedList<Path> search(final Path workdir, final Filter<Path> filter, final ListProgressListener listener); @Override boolean isRecursive(); @Override Search withCache(final Cache<Path> cache);  }