Reputation: 2052
How can I change:
if (pAlarms[0].getMoIdentifier().isPresent()) {
Optional<AlarmValue[]> alarmValues = getAlarmsFromMo(pAlarms[0].getMoIdentifier().get());
}
into ifPresent()
?
Upvotes: 0
Views: 155
Reputation: 770
Even though you asked for using ifPresent()
, I think using flatMap()
makes a lot more sense in your example. With it you should be able to do this:
Optional<AlarmValue[]> alarmValues = pAlarms[0].getMoIdentifier().flatMap(this::getAlarmsFromMo)
Upvotes: 4
Reputation: 73558
This should do it.
pAlarms[0].getMoIdentifier().ifPresent(moId -> {
Optional<AlarmValue[]> alarmValues = getAlarmsFromMo(moId);
});
Upvotes: 2