Instead of creating a class (your K
class) that implements Predicate<Prescription<D, I>>
, you can assign a lambda expression to a Predicate
variable.
For example:
Predicate<Prescription<BaseDose<DoseInstance>, DoseInstance>> pred =
p -> DepositType.DATE == p.getBaseDeposit().getDepositType();
If you need a lambda expression with multiple statements, you can write:
Predicate<Prescription<BaseDose<DoseInstance>, DoseInstance>> pred =
p -> {
final SigningStatus signingStatus = p.getSigningStatus();
return !p.isReplacedByLatest() && SigningStatus.INVALIDATED.equals(signingStatus);
};
though this can be simplified to a single statement:
Predicate<Prescription<BaseDose<DoseInstance>, DoseInstance>> pred =
p -> !p.isReplacedByLatest() && SigningStatus.INVALIDATED.equals(p.getSigningStatus());
Predicate<Prescription<D, I>>
is a functional interface, so yes. The whole thing can probably be written asinput -> DepositType.DATE == input.getBaseDeposit().getDepositType()
. – ernest_k