I have a Set of Currencies as Set<String>
and RequiredCurrency as Set<String>
. I have to check if any of required currency is present in currency set or not . I have written BiPredicate
for that as below and trying to use the same in anyMatch()
. But it is not working for me. How can i achieve it .
Set<String> currencyValues = currencies.getCurrencies().values()
.stream()
.map(currencyEntity -> {
return currencyEntity.getNameOfSymbol();
}).collect(Collectors.toSet());
Set<String> requestCurrencyCodes = globalPricingRequests.stream().map(globalPricingRequest -> {
return globalPricingRequest.getCurrencyISOCode();
}).collect(Collectors.toSet());
BiPredicate<Set<String>, String> checkIfCurrencyPresent = Set::contains;
boolean isCurrencyCodeValid = requestCurrencyCodes.stream().anyMatch(checkIfCurrencyPresent.test(currencyValues));
I am unable to pass the requestCurrencyCode in checkIfCurrencyPresent.test(currencyValues)
.
Stream.anyMatch
takes aPredicate
, not aBiPredicate
. That said, usinganyMatch(currencyValues::contains)
should fit your needs.anyMatch
getPredicate
as argument. so you should passPredicate
insteadBiPredicate
Predicate
, how you could use it.. So precisely, you just needed aPredicate
in your current use case and not aBiPredicate
.