Make use of Optional more idiomatic

Change-Id: I42b3261169e7cb8408f46c5831f72115f77fd779
diff --git a/core/api/src/main/java/org/onosproject/net/packet/DefaultPacketRequest.java b/core/api/src/main/java/org/onosproject/net/packet/DefaultPacketRequest.java
index 3bddee4..07d2440 100644
--- a/core/api/src/main/java/org/onosproject/net/packet/DefaultPacketRequest.java
+++ b/core/api/src/main/java/org/onosproject/net/packet/DefaultPacketRequest.java
@@ -105,7 +105,7 @@
                 .add("priority", priority)
                 .add("appId", appId)
                 .add("nodeId", nodeId)
-                .add("applies to", deviceId.isPresent() ? deviceId.get() : "all")
+                .add("applies to", deviceId.map(DeviceId::toString).orElse("all"))
                 .toString();
     }
-}
\ No newline at end of file
+}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/ApplicationCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/ApplicationCodec.java
index 4886e60..18ecedb 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/ApplicationCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/ApplicationCodec.java
@@ -23,6 +23,8 @@
 import org.onosproject.codec.JsonCodec;
 import org.onosproject.core.Application;
 
+import java.net.URI;
+
 import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
@@ -52,8 +54,7 @@
                 .put("readme", StringEscapeUtils.escapeJson(app.readme()))
                 .put("origin", app.origin())
                 .put("url", app.url())
-                .put("featuresRepo", app.featuresRepo().isPresent() ?
-                        app.featuresRepo().get().toString() : "")
+                .put("featuresRepo", app.featuresRepo().map(URI::toString).orElse(""))
                 .put("state", service.getState(app.id()).toString());
 
         result.set("features", features);
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 {
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/StoragePartition.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/StoragePartition.java
index acf88fa..d8fb580 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/StoragePartition.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/StoragePartition.java
@@ -121,11 +121,8 @@
     }
 
     private CompletableFuture<Void> closeServer() {
-        if (server.isPresent()) {
-            return server.get().close();
-        } else {
-            return CompletableFuture.completedFuture(null);
-        }
+        return server.map(StoragePartitionServer::close)
+                .orElse(CompletableFuture.completedFuture(null));
     }
 
     private CompletableFuture<Void> closeClient() {