From: Jaroslav Tóth Date: Mon, 22 Feb 2021 08:04:13 +0000 (+0100) Subject: Use Optional.isEmpty() X-Git-Tag: v1.13.2~15 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=98a820a6085dc303a39b0c1d9098abfde963416a;p=netconf.git Use Optional.isEmpty() Java 11 introduced Optional.isEmpty(), which allows us to convert !Optional.isPresent() callsites. Perform this conversion across the entire repostitory. Change-Id: I515a550bb6aa56b6d89cea020f5399ca27884833 Signed-off-by: Jaroslav Tóth Signed-off-by: Robert Varga --- diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/TransactionProvider.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/TransactionProvider.java index 33b8fce481..e41f019c9f 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/TransactionProvider.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/TransactionProvider.java @@ -74,7 +74,7 @@ public class TransactionProvider implements AutoCloseable { ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR); } - if (!getCandidateTransaction().isPresent()) { + if (getCandidateTransaction().isEmpty()) { // Validating empty transaction, just return true LOG.debug("Validating empty candidate transaction for session {}", netconfSessionIdForReporting); return; @@ -93,7 +93,7 @@ public class TransactionProvider implements AutoCloseable { } public synchronized boolean commitTransaction() throws DocumentedException { - if (!getCandidateTransaction().isPresent()) { + if (getCandidateTransaction().isEmpty()) { //making empty commit without prior opened transaction, just return true LOG.debug("Making commit without open candidate transaction for session {}", netconfSessionIdForReporting); return true; @@ -119,7 +119,7 @@ public class TransactionProvider implements AutoCloseable { public synchronized void abortTransaction() { LOG.debug("Aborting current candidateTransaction"); final Optional otx = getCandidateTransaction(); - if (!otx.isPresent()) { + if (otx.isEmpty()) { LOG.warn("discard-changes triggerd on an empty transaction for session: {}", netconfSessionIdForReporting); return; } diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractConfigOperation.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractConfigOperation.java index 9e3989cc49..f6b827c252 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractConfigOperation.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractConfigOperation.java @@ -58,7 +58,7 @@ abstract class AbstractConfigOperation extends AbstractSingletonNetconfOperation } final Optional urlElement = parent.getOnlyChildElementOptionally(URL_KEY); - if (!urlElement.isPresent()) { + if (urlElement.isEmpty()) { throw new DocumentedException("Invalid RPC, neither not element is present", DocumentedException.ErrorType.PROTOCOL, DocumentedException.ErrorTag.MISSING_ELEMENT, diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java index 2576641b83..acf55aab5b 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java @@ -87,7 +87,7 @@ abstract class AbstractEdit extends AbstractConfigOperation { final String elementName = element.getName(); final Optional schemaNode = module.findDataChildByName(QName.create(module.getQNameModule(), element.getName())); - if (!schemaNode.isPresent()) { + if (schemaNode.isEmpty()) { throw new DocumentedException( "Unable to find node " + elementName + " with namespace: " + namespace + "in module: " + module.toString(), diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfig.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfig.java index 939fcb1d3c..341f84bb3a 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfig.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfig.java @@ -121,7 +121,7 @@ public final class CopyConfig extends AbstractEdit { private static XmlElement getSourceElement(final XmlElement parent) throws DocumentedException { final Optional sourceElement = parent.getOnlyChildElementOptionally(SOURCE_KEY); - if (!sourceElement.isPresent()) { + if (sourceElement.isEmpty()) { throw new DocumentedException(" element is missing", DocumentedException.ErrorType.PROTOCOL, DocumentedException.ErrorTag.MISSING_ELEMENT, diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java index 443b8c64fd..614d4b66c4 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java @@ -82,7 +82,7 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation { final URI namespaceURI = createNsUri(namespace); final Optional module = getModule(namespaceURI); - if (!module.isPresent()) { + if (module.isEmpty()) { LOG.debug("Cannot handle rpc: {}, {}", netconfOperationName, namespace); return HandlingPriority.CANNOT_HANDLE; } @@ -135,7 +135,7 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation { final URI namespaceURI = createNsUri(netconfOperationNamespace); final Optional moduleOptional = getModule(namespaceURI); - if (!moduleOptional.isPresent()) { + if (moduleOptional.isEmpty()) { throw new DocumentedException("Unable to find module in Schema Context with namespace and name : " + namespaceURI + " " + netconfOperationName + schemaContext.getCurrentContext(), ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, ErrorSeverity.ERROR); @@ -144,7 +144,7 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation { final Optional rpcDefinitionOptional = getRpcDefinitionFromModule(moduleOptional.get(), namespaceURI, netconfOperationName); - if (!rpcDefinitionOptional.isPresent()) { + if (rpcDefinitionOptional.isEmpty()) { throw new DocumentedException( "Unable to find RpcDefinition with namespace and name : " + namespaceURI + " " + netconfOperationName, diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java index 0ec329012e..bcffae9216 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java @@ -198,7 +198,7 @@ public class FilterContentValidator { for (final QName qualifiedName : keyDefinition) { final Optional childElements = current.getOnlyChildElementOptionally(qualifiedName.getLocalName()); - if (!childElements.isPresent()) { + if (childElements.isEmpty()) { return Collections.emptyMap(); } final Optional keyValue = childElements.get().getOnlyTextContentOptionally(); diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/Get.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/Get.java index 6aaa8d8002..4751c3323b 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/Get.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/Get.java @@ -45,7 +45,7 @@ public class Get extends AbstractGet { throws DocumentedException { final Optional dataRootOptional = getDataRootFromFilter(operationElement); - if (!dataRootOptional.isPresent()) { + if (dataRootOptional.isEmpty()) { return document.createElement(XmlNetconfConstants.DATA_KEY); } @@ -57,7 +57,7 @@ public class Get extends AbstractGet { LogicalDatastoreType.OPERATIONAL, dataRoot).get(); transactionProvider.abortRunningTransaction(rwTx); - if (!normalizedNodeOptional.isPresent()) { + if (normalizedNodeOptional.isEmpty()) { return document.createElement(XmlNetconfConstants.DATA_KEY); } diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/GetConfig.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/GetConfig.java index 26207a9f11..aadf1b9a88 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/GetConfig.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/GetConfig.java @@ -54,7 +54,7 @@ public class GetConfig extends AbstractGet { } final Optional dataRootOptional = getDataRootFromFilter(operationElement); - if (!dataRootOptional.isPresent()) { + if (dataRootOptional.isEmpty()) { return document.createElement(XmlNetconfConstants.DATA_KEY); } @@ -71,7 +71,7 @@ public class GetConfig extends AbstractGet { transactionProvider.abortRunningTransaction(rwTx); } - if (!normalizedNodeOptional.isPresent()) { + if (normalizedNodeOptional.isEmpty()) { return document.createElement(XmlNetconfConstants.DATA_KEY); } diff --git a/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscription.java b/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscription.java index 3f3d14ed96..685ba76188 100644 --- a/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscription.java +++ b/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscription.java @@ -69,12 +69,12 @@ public class CreateSubscription extends AbstractSingletonNetconfOperation // Replay not supported final Optional startTime = operationElement.getOnlyChildElementWithSameNamespaceOptionally("startTime"); - checkArgument(!startTime.isPresent(), "StartTime element not yet supported"); + checkArgument(startTime.isEmpty(), "StartTime element not yet supported"); // Stop time not supported final Optional stopTime = operationElement.getOnlyChildElementWithSameNamespaceOptionally("stopTime"); - checkArgument(!stopTime.isPresent(), "StopTime element not yet supported"); + checkArgument(stopTime.isEmpty(), "StopTime element not yet supported"); final StreamNameType streamNameType = parseStreamIfPresent(operationElement); diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NetconfHelloMessage.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NetconfHelloMessage.java index d46336a962..564847304b 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NetconfHelloMessage.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NetconfHelloMessage.java @@ -97,7 +97,7 @@ public final class NetconfHelloMessage extends NetconfMessage { final Optional optNamespace = element.getNamespaceOptionally(); // accept even if hello has no namespace - return !optNamespace.isPresent() + return optNamespace.isEmpty() || XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0.equals(optNamespace.get()); } } diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlElement.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlElement.java index 4a92fddb52..a07a785f1d 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlElement.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlElement.java @@ -392,7 +392,7 @@ public final class XmlElement { public String getNamespace() throws MissingNameSpaceException { Optional namespaceURI = getNamespaceOptionally(); - if (!namespaceURI.isPresent()) { + if (namespaceURI.isEmpty()) { throw new MissingNameSpaceException(String.format("No namespace defined for %s", this), DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlUtil.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlUtil.java index d3c4061428..8454831317 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlUtil.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlUtil.java @@ -122,7 +122,7 @@ public final class XmlUtil { public static Element createElement(final Document document, final String qname, final Optional namespaceURI) { - if (!namespaceURI.isPresent()) { + if (namespaceURI.isEmpty()) { return document.createElement(qname); } diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/NetconfDataTreeServiceActor.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/NetconfDataTreeServiceActor.java index e6923c22b4..7f007d146f 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/NetconfDataTreeServiceActor.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/NetconfDataTreeServiceActor.java @@ -187,7 +187,7 @@ public final class NetconfDataTreeServiceActor extends UntypedAbstractActor { Futures.addCallback(feature, new FutureCallback<>() { @Override public void onSuccess(final Optional> result) { - if (!result.isPresent()) { + if (result.isEmpty()) { sender.tell(new EmptyReadResponse(), self); return; } diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/ReadAdapter.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/ReadAdapter.java index b34f846d9e..2a56fe7e2a 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/ReadAdapter.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/ReadAdapter.java @@ -51,7 +51,7 @@ class ReadAdapter { tx.read(store, path).addCallback(new FutureCallback>>() { @Override public void onSuccess(final Optional> result) { - if (!result.isPresent()) { + if (result.isEmpty()) { sender.tell(new EmptyReadResponse(), self); return; } diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/MountPointEndToEndTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/MountPointEndToEndTest.java index 59916be1a9..83bd1d80ea 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/MountPointEndToEndTest.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/MountPointEndToEndTest.java @@ -684,7 +684,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest { private void awaitMountPointNotPresent(final DOMMountPointService mountPointService) { await().atMost(5, TimeUnit.SECONDS).until( - () -> !mountPointService.getMountPoint(yangNodeInstanceId).isPresent()); + () -> mountPointService.getMountPoint(yangNodeInstanceId).isEmpty()); } private static DOMDataBroker getDOMDataBroker(final DOMMountPoint mountPoint) { diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageUtil.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageUtil.java index a32cd277b6..d61b3c6d27 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageUtil.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageUtil.java @@ -78,7 +78,7 @@ public final class NetconfMessageUtil { // Extract child element from with or without(fallback) the same namespace Optional capabilitiesElement = responseElement .getOnlyChildElementWithSameNamespaceOptionally(XmlNetconfConstants.CAPABILITIES); - if (!capabilitiesElement.isPresent()) { + if (capabilitiesElement.isEmpty()) { capabilitiesElement = responseElement.getOnlyChildElementOptionally(XmlNetconfConstants.CAPABILITIES); } diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SubtreeFilter.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SubtreeFilter.java index 3b4043aa20..49fbc559be 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SubtreeFilter.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SubtreeFilter.java @@ -43,7 +43,7 @@ public final class SubtreeFilter { Optional maybeFilter = operationNameAndNamespace.getOperationElement() .getOnlyChildElementOptionally(XmlNetconfConstants.FILTER, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); - if (!maybeFilter.isPresent()) { + if (maybeFilter.isEmpty()) { return rpcReply; } XmlElement filter = maybeFilter.get(); diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceMountPointContext.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceMountPointContext.java index 0783ad6b64..bc8703d7d5 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceMountPointContext.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceMountPointContext.java @@ -67,7 +67,7 @@ final class DeviceMountPointContext extends AbstractEffectiveModelContextProvide static MountPointContext create(final MountPointContext emptyContext, final ContainerNode mountData) { final Optional> optMountPoint = mountData.getChild(MOUNT_POINT); - if (!optMountPoint.isPresent()) { + if (optMountPoint.isEmpty()) { LOG.debug("mount-point list not present in {}", mountData); return emptyContext; } @@ -102,7 +102,7 @@ final class DeviceMountPointContext extends AbstractEffectiveModelContextProvide final ChoiceNode schemaRef = (ChoiceNode) child; final Optional> maybeShared = schemaRef.getChild(SHARED_SCHEMA); - if (!maybeShared.isPresent()) { + if (maybeShared.isEmpty()) { LOG.debug("Ignoring non-shared mountpoint entry {}", entry); continue; } diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/LibraryModulesSchemas.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/LibraryModulesSchemas.java index a82b39b7ce..6ef8577429 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/LibraryModulesSchemas.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/LibraryModulesSchemas.java @@ -264,7 +264,7 @@ public final class LibraryModulesSchemas implements NetconfDeviceSchemas { LOG.warn("Unable to download yang library from {}", connection.getURL(), e); } - if (!optionalModulesStateNode.isPresent()) { + if (optionalModulesStateNode.isEmpty()) { return new LibraryModulesSchemas(ImmutableMap.of()); } diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java index f48d57812f..ecbee257ce 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java @@ -313,7 +313,7 @@ public class NetconfDevice private ListenableFuture createMountPointContext(final EffectiveModelContext schemaContext, final BaseSchema baseSchema, final NetconfDeviceCommunicator listener) { final MountPointContext emptyContext = new EmptyMountPointContext(schemaContext); - if (!schemaContext.findModule(SchemaMountConstants.RFC8528_MODULE).isPresent()) { + if (schemaContext.findModule(SchemaMountConstants.RFC8528_MODULE).isEmpty()) { return Futures.immediateFuture(emptyContext); } diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfStateSchemas.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfStateSchemas.java index 92705dcced..496809cf68 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfStateSchemas.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfStateSchemas.java @@ -145,7 +145,7 @@ public final class NetconfStateSchemas implements NetconfDeviceSchemas { final Optional> optSchemasNode = findSchemasNode(schemasNodeResult.getResult(), schemaContext); - if (!optSchemasNode.isPresent()) { + if (optSchemasNode.isEmpty()) { LOG.warn("{}: Unable to detect available schemas, get to {} was empty", id, STATE_SCHEMAS_IDENTIFIER); return EMPTY; } @@ -174,9 +174,7 @@ public final class NetconfStateSchemas implements NetconfDeviceSchemas { for (final MapEntryNode schemaNode : ((MapNode) child.get()).getValue()) { final Optional fromCompositeNode = RemoteYangSchema.createFromNormalizedNode(id, schemaNode); - if (fromCompositeNode.isPresent()) { - availableYangSchemas.add(fromCompositeNode.get()); - } + fromCompositeNode.ifPresent(availableYangSchemas::add); } return new NetconfStateSchemas(availableYangSchemas); @@ -188,7 +186,7 @@ public final class NetconfStateSchemas implements NetconfDeviceSchemas { return Optional.empty(); } final Optional> rpcResultOpt = ((ContainerNode)result).getChild(NETCONF_DATA_NODEID); - if (!rpcResultOpt.isPresent()) { + if (rpcResultOpt.isEmpty()) { return Optional.empty(); } @@ -206,7 +204,7 @@ public final class NetconfStateSchemas implements NetconfDeviceSchemas { final Optional> nStateNode = ((DataContainerNode) dataNode).getChild( toId(NetconfState.QNAME)); - if (!nStateNode.isPresent()) { + if (nStateNode.isEmpty()) { return Optional.empty(); } @@ -246,7 +244,7 @@ public final class NetconfStateSchemas implements NetconfDeviceSchemas { childNode = NetconfMessageTransformUtil.IETF_NETCONF_MONITORING_SCHEMA_NAMESPACE; final Optional namespaceValue = getSingleChildNodeValue(schemaNode, childNode); - if (!namespaceValue.isPresent()) { + if (namespaceValue.isEmpty()) { LOG.warn("{}: Ignoring schema due to missing namespace", id); return Optional.empty(); } diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java index 3b125cdf40..5d3e1da407 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java @@ -104,7 +104,7 @@ public class JsonNormalizedNodeBodyReader final InputStream entityStream, final boolean isPost) throws IOException { final Optional nonEmptyInputStreamOptional = RestUtil.isInputStreamEmpty(entityStream); - if (!nonEmptyInputStreamOptional.isPresent()) { + if (nonEmptyInputStreamOptional.isEmpty()) { return new NormalizedNodeContext(path, null); } final NormalizedNodeResult resultHolder = new NormalizedNodeResult(); diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java index 0f308b0338..de744eeef8 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java @@ -104,7 +104,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider private PatchContext readFrom(final InstanceIdentifierContext path, final InputStream entityStream) throws IOException { final Optional nonEmptyInputStreamOptional = RestUtil.isInputStreamEmpty(entityStream); - if (!nonEmptyInputStreamOptional.isPresent()) { + if (nonEmptyInputStreamOptional.isEmpty()) { return new PatchContext(path, null, null); } diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlNormalizedNodeBodyReader.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlNormalizedNodeBodyReader.java index 215c1b4d78..8246d3bc9f 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlNormalizedNodeBodyReader.java @@ -107,7 +107,7 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro XMLStreamException, ParserConfigurationException, URISyntaxException { final InstanceIdentifierContext path = getInstanceIdentifierContext(); final Optional nonEmptyInputStreamOptional = RestUtil.isInputStreamEmpty(entityStream); - if (!nonEmptyInputStreamOptional.isPresent()) { + if (nonEmptyInputStreamOptional.isEmpty()) { // represent empty nopayload input return new NormalizedNodeContext(path, null); } diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlToPatchBodyReader.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlToPatchBodyReader.java index a1f3b4b159..ef5be04b77 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlToPatchBodyReader.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlToPatchBodyReader.java @@ -99,7 +99,7 @@ public class XmlToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider i try { final InstanceIdentifierContext path = getInstanceIdentifierContext(); final Optional nonEmptyInputStreamOptional = RestUtil.isInputStreamEmpty(entityStream); - if (!nonEmptyInputStreamOptional.isPresent()) { + if (nonEmptyInputStreamOptional.isEmpty()) { // represent empty nopayload input return new PatchContext(path, null, null); } diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java index 0eba3a783a..3a4c0ec1cf 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java @@ -548,8 +548,8 @@ public class BrokerFacade implements Closeable { try { final Optional> optional = transaction.read(datastore, path).get(); - return !optional.isPresent() ? null : withDefa == null ? optional.get() : - prepareDataByParamWithDef(optional.get(), path, withDefa); + return optional.map(normalizedNode -> withDefa == null ? normalizedNode : + prepareDataByParamWithDef(normalizedNode, path, withDefa)).orElse(null); } catch (InterruptedException e) { LOG.warn("Error reading {} from datastore {}", path, datastore.name(), e); throw new RestconfDocumentedException("Error reading data.", e); diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java index 627a9d9db2..1ff9545173 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java @@ -583,7 +583,7 @@ public final class ControllerContext implements EffectiveModelContextListener, C final YangInstanceIdentifier partialPath = this.dataNormalizer.toNormalized(builder.build()); final Optional mountOpt = this.mountService.getMountPoint(partialPath); - if (!mountOpt.isPresent()) { + if (mountOpt.isEmpty()) { LOG.debug("Instance identifier to missing mount point: {}", partialPath); throw new RestconfDocumentedException("Mount point does not exist.", ErrorType.PROTOCOL, ErrorTag.DATA_MISSING); diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java index 24a14d7c1e..57b7d0d94f 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java @@ -404,7 +404,7 @@ public final class RestconfImpl implements RestconfService { if (mountPoint != null) { final Optional mountRpcServices = mountPoint.getService(DOMRpcService.class); - if (!mountRpcServices.isPresent()) { + if (mountRpcServices.isEmpty()) { LOG.debug("Error: Rpc service is missing."); throw new RestconfDocumentedException("Rpc service is missing."); } @@ -498,7 +498,7 @@ public final class RestconfImpl implements RestconfService { final ListenableFuture response; if (mountPoint != null) { final Optional mountRpcServices = mountPoint.getService(DOMRpcService.class); - if (!mountRpcServices.isPresent()) { + if (mountRpcServices.isEmpty()) { throw new RestconfDocumentedException("Rpc service is missing."); } response = mountRpcServices.get().invokeRpc(rpc.getQName(), input); @@ -1321,7 +1321,7 @@ public final class RestconfImpl implements RestconfService { final String paramName) { final Optional> optAugNode = value.getChild( SAL_REMOTE_AUG_IDENTIFIER); - if (!optAugNode.isPresent()) { + if (optAugNode.isEmpty()) { return null; } final DataContainerChild augNode = optAugNode.get(); @@ -1330,7 +1330,7 @@ public final class RestconfImpl implements RestconfService { } final Optional> enumNode = ((AugmentationNode) augNode).getChild( new NodeIdentifier(QName.create(SAL_REMOTE_AUGMENT, paramName))); - if (!enumNode.isPresent()) { + if (enumNode.isEmpty()) { return null; } final Object rawValue = enumNode.get().getValue(); diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/ListenerAdapter.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/ListenerAdapter.java index 8afc8dedae..b9e738927a 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/ListenerAdapter.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/ListenerAdapter.java @@ -209,7 +209,7 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster break; } - if (!optionalNormalizedNode.isPresent()) { + if (optionalNormalizedNode.isEmpty()) { LOG.error("No node present in notification for {}", candidateNode); return; } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java index d3dc392da0..590bb7bd72 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java @@ -184,7 +184,7 @@ final class CreateStreamUtil { private static T parseEnum(final ContainerNode data, final Class clazz, final String paramName) { final Optional> optAugNode = data.getChild( RestconfStreamsConstants.SAL_REMOTE_AUG_IDENTIFIER); - if (!optAugNode.isPresent()) { + if (optAugNode.isEmpty()) { return null; } final DataContainerChild augNode = optAugNode.get(); @@ -193,7 +193,7 @@ final class CreateStreamUtil { } final Optional> enumNode = ((AugmentationNode) augNode).getChild( new NodeIdentifier(QName.create(RestconfStreamsConstants.SAL_REMOTE_AUGMENT, paramName))); - if (!enumNode.isPresent()) { + if (enumNode.isEmpty()) { return null; } final Object value = enumNode.get().getValue(); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java index 5408b7015b..6b06b5278a 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java @@ -48,7 +48,7 @@ public class RestconfDataStreamServiceImpl implements RestconfDataStreamService final String streamName = ListenersBroker.createStreamNameFromUri(identifier); final Optional listener = listenersBroker.getListenerFor(streamName); - if (!listener.isPresent()) { + if (listener.isEmpty()) { LOG.debug("Listener for stream with name {} was not found.", streamName); throw new RestconfDocumentedException("Data missing", ErrorType.APPLICATION, ErrorTag.DATA_MISSING); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java index 8bef7a3f46..9eee1b462e 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java @@ -136,7 +136,7 @@ public final class RestconfInvokeOperationsUtil { public static DOMActionResult invokeActionViaMountPoint(final DOMMountPoint mountPoint, final ContainerNode data, final Absolute schemaPath, final YangInstanceIdentifier yangIId) { final Optional mountPointService = mountPoint.getService(DOMActionService.class); - if (!mountPointService.isPresent()) { + if (mountPointService.isEmpty()) { throw new RestconfDocumentedException("DomAction service is missing."); } return prepareActionResult(mountPointService.get().invokeAction(schemaPath, prepareDataTreeId(yangIId), data)); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java index e6567c1eea..305b93ff7a 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java @@ -84,7 +84,7 @@ public final class ParserIdentifier { if (identifier == null || !identifier.contains(RestconfConstants.MOUNT)) { return createIIdContext(schemaContext, identifier, null); } - if (!mountPointService.isPresent()) { + if (mountPointService.isEmpty()) { throw new RestconfDocumentedException("Mount point service is not available"); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java index 334a774dd5..de31eb364d 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java @@ -139,7 +139,7 @@ public final class YangInstanceIdentifierDeserializer { // parse value final QName key = keys.next(); Optional leafSchemaNode = listSchemaNode.findDataChildByName(key); - RestconfDocumentedException.throwIf(!leafSchemaNode.isPresent(), ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT, + RestconfDocumentedException.throwIf(leafSchemaNode.isEmpty(), ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT, "Schema not found for %s", key); final String value = findAndParsePercentEncoded(nextIdentifierFromNextSequence(IDENTIFIER_PREDICATE));