@Test public void testListSelectedVersions() throws Exception { List<FileSystemDatasetVersion> versionList = new ArrayList<>(); Set<String> pathSet = new HashSet<>(); Path path1 = new Path("/data/dataset/versions/version1"); pathSet.add(path1.toString()); Path path2 = new Path("/data/dataset/versions/version2"); pathSet.add(path2.toString()); Path path3 = new Path("/data/dataset/.temp/tmpPath"); Path path4 = new Path("/data/dataset/_temp/tmpPath"); versionList.add(new TimestampedDatasetVersion(new DateTime(), path1)); versionList.add(new TimestampedDatasetVersion(new DateTime(), path2)); versionList.add(new TimestampedDatasetVersion(new DateTime(), path3)); versionList.add(new TimestampedDatasetVersion(new DateTime(), path4)); List<String> hiddenFilePrefixes = Arrays.asList("_", "."); List<Config> configList = new ArrayList<>(); Config config1 = ConfigFactory.parseMap( ImmutableMap.of(HiddenFilterSelectionPolicy.HIDDEN_FILTER_HIDDEN_FILE_PREFIX_KEY, hiddenFilePrefixes)); configList.add(config1); Config config2 = ConfigFactory.parseMap( ImmutableMap.of(HiddenFilterSelectionPolicy.HIDDEN_FILTER_HIDDEN_FILE_PREFIX_KEY, "_,.")); configList.add(config2); for (Config config : configList) { HiddenFilterSelectionPolicy policy = new HiddenFilterSelectionPolicy(config); Collection<FileSystemDatasetVersion> selectedVersions = policy.listSelectedVersions(versionList); Assert.assertEquals(selectedVersions.size(), 2); for (FileSystemDatasetVersion version : selectedVersions) { Set<Path> paths = version.getPaths(); for (Path path : paths) { Assert.assertTrue(pathSet.contains(path.toString())); } } } }
@Override public Collection<FileSystemDatasetVersion> listSelectedVersions(List<FileSystemDatasetVersion> allVersions) { return Lists.newArrayList(Collections2.filter(allVersions, getSelectionPredicate())); }
HiddenFilterSelectionPolicy implements VersionSelectionPolicy<FileSystemDatasetVersion> { @Override public Collection<FileSystemDatasetVersion> listSelectedVersions(List<FileSystemDatasetVersion> allVersions) { return Lists.newArrayList(Collections2.filter(allVersions, getSelectionPredicate())); } }
HiddenFilterSelectionPolicy implements VersionSelectionPolicy<FileSystemDatasetVersion> { @Override public Collection<FileSystemDatasetVersion> listSelectedVersions(List<FileSystemDatasetVersion> allVersions) { return Lists.newArrayList(Collections2.filter(allVersions, getSelectionPredicate())); } HiddenFilterSelectionPolicy(Config config); }
HiddenFilterSelectionPolicy implements VersionSelectionPolicy<FileSystemDatasetVersion> { @Override public Collection<FileSystemDatasetVersion> listSelectedVersions(List<FileSystemDatasetVersion> allVersions) { return Lists.newArrayList(Collections2.filter(allVersions, getSelectionPredicate())); } HiddenFilterSelectionPolicy(Config config); @Override Class<? extends FileSystemDatasetVersion> versionClass(); @Override Collection<FileSystemDatasetVersion> listSelectedVersions(List<FileSystemDatasetVersion> allVersions); }
HiddenFilterSelectionPolicy implements VersionSelectionPolicy<FileSystemDatasetVersion> { @Override public Collection<FileSystemDatasetVersion> listSelectedVersions(List<FileSystemDatasetVersion> allVersions) { return Lists.newArrayList(Collections2.filter(allVersions, getSelectionPredicate())); } HiddenFilterSelectionPolicy(Config config); @Override Class<? extends FileSystemDatasetVersion> versionClass(); @Override Collection<FileSystemDatasetVersion> listSelectedVersions(List<FileSystemDatasetVersion> allVersions); static final String HIDDEN_FILTER_HIDDEN_FILE_PREFIX_KEY; }