I'm pretty new with functional interface and have no idea how to do this when passing it as a parameter. I hope you could help me with it. So I have this class called NumberValidation:
public class NumberValidation {
public static Predicate<CommonNumber> isExisting(Function<CommonNumber, CommonNumber> retrieve){
return (p ->{
return Optional.ofNullable(retrieve.apply(p)).isPresent();
});
}
public static Predicate<CommonNumber> isNotExisting(Function<CommonNumber, CommonNumber> retrieve){
return (p ->{
return !Optional.ofNullable(retrieve.apply(p)).isPresent();
});
}
}
As you can see I have two functions namely isExisting and isNotExisting with a parameter Function<CommomNumber, CommonNumber>. Say I want to use one of these functions like this:
public CommonNumber apply(CommonNumber t) {
return Optional.of(t).filter(p -> {
return NumberValidation.isExisting(//parameter here);
});
}
I have no idea how I'm going to pass that parameter. I tried return NumberValidation.isExisting(t) and as well as return NumberValidation.isExisting(p) but I keep getting an error since the required parameter is a Function<CommonNumber,CommonNumber>
isExistingfunction and pass aFunction<CommonNumber, CommonNumber>parameter