[英]Combining Predicates within Lambda Expression
這是一個兩部分的問題。
我有一個布爾字段和幾個String []字段,我需要評估每個謂詞。
以下代碼獲取每個設備的接口。 然后,我想基於謂詞評估那些接口。
.filter(predicates.stream()。reduce(Predicate :: or)給出此錯誤: 我不確定如何解決。
parentReference.getDevices().stream().parallel().filter(ASA_PREDICATE).forEach((device) -> { List<Predicate<? super TufinInterface>> predicates = new ArrayList(); if (iName != null) { Predicate< ? super TufinInterface> iNameFilter = myInterface -> Arrays.stream(iName) .allMatch(input -> myInterface.getName().toLowerCase().contains(input.toLowerCase())); predicates.add(iNameFilter); } if (ipLow != null) { Predicate< ? super TufinInterface> ipLowFilter = myInterface -> Arrays.stream(ipLow) .allMatch(input -> myInterface.getName().toLowerCase().contains(input.toLowerCase())); predicates.add(ipLowFilter); } if (ip != null) { Predicate< ? super TufinInterface> ipFilter = myInterface -> Arrays.stream(ip) .allMatch(input -> myInterface.getName().toLowerCase().contains(input.toLowerCase())); predicates.add(ipFilter); } if (zone != null) { Predicate< ? super TufinInterface> zoneFilter = myInterface -> Arrays.stream(zone) .allMatch(input -> myInterface.getName().toLowerCase().contains(input.toLowerCase())); predicates.add(zoneFilter); } try { ArrayList<TufinInterface> tufinInterfaces = Tufin.GET_INTERFACES(parentReference.user, parentReference.password, parentReference.hostName, device) .stream() .filter(predicates.stream().reduce(Predicate::or) .orElse(t->true)).parallel().collect(Collectors.toCollection(ArrayList<TufinInterface>::new)); interfaces.addAll(tufinInterfaces); } catch (IOException | NoSuchAlgorithmException | KeyManagementException | JSONException | Tufin.IncompatibleDeviceException ex) { Logger.getLogger(InterfaceCommand.class.getName()).log(Level.SEVERE, null, ex); } });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.