當前位置: 首頁>>代碼示例>>Java>>正文


Java Filter類代碼示例

本文整理匯總了Java中java.nio.file.DirectoryStream.Filter的典型用法代碼示例。如果您正苦於以下問題:Java Filter類的具體用法?Java Filter怎麽用?Java Filter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Filter類屬於java.nio.file.DirectoryStream包,在下文中一共展示了Filter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testAndFilterLogicallyAndsAllFiltersAndDoesNotAcceptIfOneOfTheFiltersIsFalse

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
@Test
public void testAndFilterLogicallyAndsAllFiltersAndDoesNotAcceptIfOneOfTheFiltersIsFalse() throws IOException {
	Filter<Path> filter1 = context.mock(Filter.class, "filter1");
	Filter<Path> filter2 = context.mock(Filter.class, "filter2");
	Filter<Path> filter3 = context.mock(Filter.class, "filter3");
	Path mockPath = context.mock(Path.class);

	context.checking(new Expectations() {{
		atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(true));
		atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(true));
		atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(false));
	}});

	AggregateAndFilter andFilter = new AggregateAndFilter(Sets.newHashSet(filter1, filter2, filter3));
	Assert.assertFalse(andFilter.accept(mockPath));
}
 
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:17,代碼來源:PathFiltersTest.java

示例2: testAndFilterLogicallyAndsAllFiltersAndAcceptsIfAllOfTheFiltersAreTrue

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
@Test
public void testAndFilterLogicallyAndsAllFiltersAndAcceptsIfAllOfTheFiltersAreTrue() throws IOException {
	Filter<Path> filter1 = context.mock(Filter.class, "filter1");
	Filter<Path> filter2 = context.mock(Filter.class, "filter2");
	Filter<Path> filter3 = context.mock(Filter.class, "filter3");
	Path mockPath = context.mock(Path.class);

	context.checking(new Expectations() {{
		atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(true));
		atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(true));
		atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(true));
	}});

	AggregateAndFilter andFilter = new AggregateAndFilter(Sets.newHashSet(filter1, filter2, filter3));
	Assert.assertTrue(andFilter.accept(mockPath));
}
 
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:17,代碼來源:PathFiltersTest.java

示例3: testOrFilterLogicallyOrsAllFiltersAndDoesNotAcceptIfAllOfTheFiltersAreFalse

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
@Test
public void testOrFilterLogicallyOrsAllFiltersAndDoesNotAcceptIfAllOfTheFiltersAreFalse() throws IOException {
	Filter<Path> filter1 = context.mock(Filter.class, "filter1");
	Filter<Path> filter2 = context.mock(Filter.class, "filter2");
	Filter<Path> filter3 = context.mock(Filter.class, "filter3");
	Path mockPath = context.mock(Path.class);

	context.checking(new Expectations() {{
		atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(false));
		atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(false));
		atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(false));
	}});

	AggregateOrFilter orFilter = new AggregateOrFilter(Sets.newHashSet(filter1, filter2, filter3));
	Assert.assertFalse(orFilter.accept(mockPath));
}
 
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:17,代碼來源:PathFiltersTest.java

示例4: testOrFilterLogicallyOrsAllFiltersAndAcceptsIfAnyOfTheFiltersAreTrue

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
@Test
public void testOrFilterLogicallyOrsAllFiltersAndAcceptsIfAnyOfTheFiltersAreTrue() throws IOException {
	Filter<Path> filter1 = context.mock(Filter.class, "filter1");
	Filter<Path> filter2 = context.mock(Filter.class, "filter2");
	Filter<Path> filter3 = context.mock(Filter.class, "filter3");
	Path mockPath = context.mock(Path.class);

	context.checking(new Expectations() {{
		atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(false));
		atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(false));
		atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(true));
	}});

	AggregateOrFilter orFilter = new AggregateOrFilter(Sets.newHashSet(filter1, filter2, filter3));
	Assert.assertTrue(orFilter.accept(mockPath));
}
 
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:17,代碼來源:PathFiltersTest.java

示例5: newDirectoryStream

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
		final Filter<? super Path> filter) throws IOException {
	final BundleFileSystem fs = (BundleFileSystem) dir.getFileSystem();
	final DirectoryStream<Path> stream = origProvider(dir)
			.newDirectoryStream(fs.unwrap(dir), new Filter<Path>() {
				@Override
				public boolean accept(Path entry) throws IOException {
					return filter.accept(fs.wrap(entry));
				}
			});
	return new DirectoryStream<Path>() {
		@Override
		public void close() throws IOException {
			stream.close();
		}

		@Override
		public Iterator<Path> iterator() {
			return fs.wrapIterator(stream.iterator());
		}
	};
}
 
開發者ID:apache,項目名稱:incubator-taverna-language,代碼行數:24,代碼來源:BundleFileSystemProvider.java

示例6: parsePathFilter

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
/**
 * Constructs a filter according to the {@link PathMatcher} rules implemented by
 * {@link DefaultPathMatcher}.
 * 
 * @param	pathFilterString
 * @return	A filter for the pattern
 * @see		FileSystem#getPathMatcher(String)
 * @throws	IllegalArgumentException
 * 				If the syntax and pattern cannot be parsed
 */
public Filter<Path> parsePathFilter(String syntaxAndPattern, String fileSystemPathSeparator) throws IllegalArgumentException {
	final DefaultPathMatcher matcher = new DefaultPathMatcher(syntaxAndPattern, fileSystemPathSeparator);

	return new Filter<Path>() {

		@Override
		public boolean accept(Path path) throws IOException {
			return matcher.matches(path);
		}
		
	};
}
 
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:23,代碼來源:AbstractCliCommand.java

示例7: createPathFilters

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
/**
 * Creates an {@link AggregateOrFilter} from all of the filters, so that if any of them match
 * then the path is accepted. Filters are created using {@link #parsePathFilter(String)}.
 * 
 * @param commandOptions
 * @return null if there are no filters created or the {@link AggregateOrFilter}
 * 
 * @see #parsePathFilter(String)
 */
public Filter<Path> createPathFilters(List<UserCommandOption> commandOptions, String fileSystemPathSeparator) {
	if (commandOptions == null || commandOptions.isEmpty()) {
		return null;
	}

	AggregateOrFilter orFilter = new AggregateOrFilter();

	for (UserCommandOption opt : commandOptions) {
		Filter<Path> filter = parsePathFilter(opt.getValue(), fileSystemPathSeparator);
		orFilter.addAggregateFilter(filter);
	}

	return orFilter;
}
 
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:24,代碼來源:AbstractCliCommand.java

示例8: listDirectoryContents

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
protected int listDirectoryContents(FileSystemProvider provider, FileSystem fileSystem,
		Filter<Path> pathFilters, Path path, boolean recursive) {
	AtomicInteger pathsCounter = new AtomicInteger(0);

	FileSystemProviderHelper.iterateOverDirectoryContents(fileSystem, Optional.ofNullable(path),
			PathFilters.ACCEPT_ALL_FILTER, recursive,
				subPath -> {
					pathsCounter.addAndGet(printCloudPathAttributes(fileSystem, pathFilters, subPath.getResultPath()));
					return true;
				});

	return pathsCounter.get();
}
 
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:14,代碼來源:ListCommand.java

示例9: newDirectoryStream

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
/**
 * Directory access is checked using {@link #checkAccess(BlobStoreContext, CloudPath, Set)}
 * with {@link AclEntryPermission#LIST_DIRECTORY}.
 */
@Override
public CloudDirectoryStream newDirectoryStream(BlobStoreContext context, CloudPath dir,
		Filter<CloudPath> filter, boolean isRecursive) throws IOException {
	checkAccess(context, dir, NEW_DIRECTORY_STREAM_PERMS);
	CloudPath dirPath = dir;
	boolean isContainer = dirPath.getRoot() == null;
	
	// Search in a container if root is null, otherwise check to find a directory
	if (!isContainer) {

		// Attempt to read attributes
		try {
			CloudBasicFileAttributes attributes = readAttributes(context, CloudBasicFileAttributes.class, dir);
			
			// Look at the parent if this is a file
			if (!attributes.isDirectory()) {
				dirPath = dir.getParent();
			}
		} catch (FileNotFoundException e) {
			LOG.warn("Cloud file path '{}' does not exist, will assume that this is a directory", dir);
		}

	}

	return new CloudDirectoryStream(dirPath, isContainer, isRecursive, filter);
}
 
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:31,代碼來源:DefaultCloudFileSystemImplementation.java

示例10: checkAccepts

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
boolean checkAccepts(Filter<Path> filter, Path entry) {
	try {
		return filter.accept(entry);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:8,代碼來源:PathFilters.java

示例11: newDirectoryStream

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException {
    MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
    MCRFilesystemNode node = resolvePath(mcrPath);
    if (node instanceof MCRDirectory) {
        return new MCRDirectoryStream((MCRDirectory) node, mcrPath);
    }
    throw new NotDirectoryException(dir.toString());
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:10,代碼來源:MCRFileSystemProvider.java

示例12: newDirectoryStream

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
                                                Filter<? super Path> filter)
                                                    throws IOException
{
  throw new UnsupportedOperationException();
}
 
開發者ID:baratine,項目名稱:baratine,代碼行數:8,代碼來源:FileProviderBase.java

示例13: newDirectoryStream

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
                                                Filter<? super Path> filter)
  throws IOException
{
  JPath jPath = (JPath) dir;

  return new JDirectoryStream(jPath, filter);
}
 
開發者ID:baratine,項目名稱:baratine,代碼行數:10,代碼來源:JFileSystemProvider.java

示例14: fromDirectoryStream

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
private <T extends Resource> Map<String, T> fromDirectoryStream(Filter<Path> filter, Function<Path, T> mapper, Comparator<T> comparator) {
  
  //linkedhashmap as we want to preserve the insertion order
  try (DirectoryStream<Path> dirs = Files.newDirectoryStream(path, filter)) {
    return StreamSupport.stream(dirs.spliterator(), false)
          .map(mapper)
          .sorted(comparator)
          .collect(Collectors.toMap(Resource::getName, Function.identity(), (k, v) -> {throw new IllegalStateException("duplicate key " + k);}, LinkedHashMap::new));
  } catch (IOException e) {
    throw new IllegalStateException(e);
  }
}
 
開發者ID:digitalfondue,項目名稱:stampo,代碼行數:13,代碼來源:RootResource.java

示例15: listFiles

import java.nio.file.DirectoryStream.Filter; //導入依賴的package包/類
public static List<Path> listFiles(Path path, Filter<? super Path> filter) throws IOException
{
    List<Path> files = new ArrayList<>();
    try(DirectoryStream<Path> ds = Files.newDirectoryStream(path, filter))
    {
        for(Path p : ds)
        {
            files.add(p);
        }
    }
    return files;
}
 
開發者ID:pingzing,項目名稱:sonic-scream,代碼行數:13,代碼來源:FilesEx.java


注:本文中的java.nio.file.DirectoryStream.Filter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。