我需要一些帮助。我创建了一个功能接口,该接口具有一个称为filter的抽象方法:
@FunctionalInterface
interface FileFilter {
/**
* This method gets a file path and filters it in some method.
* @return a list of the remaining files after this filter.
* @throws IOException
*/
abstract boolean filter(Path path) throws IOException;
}
我需要为此方法创建一些不同的实现,分为两组:1.几个按不同文件大小过滤的文件(它们之间的区别是标准)。2.一些按不同文件名过滤的文件。 (它们之间的唯一区别是String方法的单一选择-contains
/ startsWith
等。
对我来说,创建一个不同的函数来实现我的filter
方法似乎很愚蠢,但它们都非常相似,但是我想不出一种解决方法。我想为每个组编写一个函数(返回正确的lambda)。
谢谢!
将另一个参数传递给过滤器呢?说,新类FilterCriteria具有所需的多个字段。如果类型为FilterCriteria的对象中的对应值不为null,则将其调用以进行过滤。