Make use of Optional more idiomatic
Change-Id: I42b3261169e7cb8408f46c5831f72115f77fd779
diff --git a/core/net/src/main/java/org/onosproject/net/driver/impl/DriverManager.java b/core/net/src/main/java/org/onosproject/net/driver/impl/DriverManager.java
index 53a9a68..c16f558 100644
--- a/core/net/src/main/java/org/onosproject/net/driver/impl/DriverManager.java
+++ b/core/net/src/main/java/org/onosproject/net/driver/impl/DriverManager.java
@@ -148,7 +148,7 @@
.filter(d -> matches(d, mfr, hw, sw)).findFirst();
// If no matching driver is found, return default.
- return optional.isPresent() ? optional.get() : drivers.get(DEFAULT);
+ return optional.orElse(drivers.get(DEFAULT));
}
// Matches the given driver using ERE matching against the given criteria.
diff --git a/core/net/src/main/java/org/onosproject/net/edgeservice/impl/EdgeManager.java b/core/net/src/main/java/org/onosproject/net/edgeservice/impl/EdgeManager.java
index cd7335d..7340fc5 100644
--- a/core/net/src/main/java/org/onosproject/net/edgeservice/impl/EdgeManager.java
+++ b/core/net/src/main/java/org/onosproject/net/edgeservice/impl/EdgeManager.java
@@ -129,18 +129,16 @@
@Override
public void emitPacket(ByteBuffer data, Optional<TrafficTreatment> treatment) {
- TrafficTreatment.Builder builder = treatment.isPresent() ?
- DefaultTrafficTreatment.builder(treatment.get()) :
- DefaultTrafficTreatment.builder();
+ TrafficTreatment.Builder builder = treatment.map(DefaultTrafficTreatment::builder)
+ .orElse(DefaultTrafficTreatment.builder());
getEdgePoints().forEach(p -> packetService.emit(packet(builder, p, data)));
}
@Override
public void emitPacket(DeviceId deviceId, ByteBuffer data,
Optional<TrafficTreatment> treatment) {
- TrafficTreatment.Builder builder = treatment.isPresent() ?
- DefaultTrafficTreatment.builder(treatment.get()) :
- DefaultTrafficTreatment.builder();
+ TrafficTreatment.Builder builder = treatment.map(DefaultTrafficTreatment::builder)
+ .orElse(DefaultTrafficTreatment.builder());
getEdgePoints(deviceId).forEach(p -> packetService.emit(packet(builder, p, data)));
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
index 6cef3a4..1f5eb38 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
@@ -56,11 +56,11 @@
try {
List<Intent> compiled = processor.compile(data.intent(),
//TODO consider passing an optional here in the future
- stored.isPresent() ? stored.get().installables() : null);
+ stored.map(IntentData::installables).orElse(null));
return Optional.of(new Installing(processor, new IntentData(data, compiled), stored));
} catch (IntentException e) {
log.debug("Unable to compile intent {} due to: {}", data.intent(), e);
- if (stored.isPresent() && !stored.get().installables().isEmpty()) {
+ if (stored.filter(x -> x.installables().isEmpty()).isPresent()) {
// removing orphaned flows and deallocating resources
return Optional.of(new Withdrawing(processor, new IntentData(data, stored.get().installables())));
} else {