Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中的谓词约简_Java_Reduce_Predicate - Fatal编程技术网

Java中的谓词约简

Java中的谓词约简,java,reduce,predicate,Java,Reduce,Predicate,我一直在尝试采用这种方法,将谓词简化为一个过滤器 类别定义: @Command(name = "Devices", description = "Fetch Devices from SecureTrack", subcommands = {InterfaceCommand.class}) class TufinDevices implements Runnable { . . . private void filter(TufinDeviceCollection<TufinDevice&

我一直在尝试采用这种方法,将谓词简化为一个过滤器

类别定义:

@Command(name = "Devices", description = "Fetch Devices from SecureTrack", subcommands = {InterfaceCommand.class})
class TufinDevices implements Runnable {
.
.
.
private void filter(TufinDeviceCollection<TufinDevice> devices) {
List<Predicate<? super TufinDevice>> filters = new ArrayList();

if (modelContains != null) {

        System.out.println("modelContains " + Arrays.asList(deviceID));
        Predicate< ? super TufinDevice> deviceFilter = device -> Arrays.stream(modelContains)
                .allMatch(input -> device.getModel().toLowerCase().contains(input.toLowerCase()));

        filters.add(deviceFilter);

    }

if (hostNameContains != null) {
        Predicate<TufinDevice> deviceFilter = device -> Arrays.stream(hostNameContains)
                .allMatch(input -> device.getHostName().toLowerCase().contains(input.toLowerCase()));

        filters.add(deviceFilter);
    }
 devices.stream().filter(filters.stream().reduce(Predicate::or).orElse(t->true));
 }
这条路线需要如何实施才能发挥作用。它抱怨说

Predicate<CAP1> can't be converted to Predicate<? super CAP2>

谓词无法转换为谓词什么是
过滤器
?刚刚用该信息更新了帖子。是的,Tufin设备是一个自定义类。代码包含在类中的方法中。我会更新这两个。它很复杂,因为它是一个Picocli项目。不过我会把这句话发出去的。
Predicate<CAP1> can't be converted to Predicate<? super CAP2>