Refactor: Extract method to check if resource path is root
Change-Id: I87c23449c929bd169daa5fe788e340266392ddbe
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java
index 7c78a9a..3aa29f6 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java
@@ -93,7 +93,7 @@
* If there is no parent, empty instance will be returned.
*/
public Optional<ResourcePath> parent() {
- if (resources.size() > 0) {
+ if (!isRoot()) {
return Optional.of(new ResourcePath(resources.subList(0, resources.size() - 1)));
}
@@ -101,6 +101,15 @@
}
/**
+ * Returns true if the path represents root.
+ *
+ * @return true if the path represents root, false otherwise.
+ */
+ public boolean isRoot() {
+ return resources.size() == 0;
+ }
+
+ /**
* Returns the last component of this instance.
*
* @return the last component of this instance.
diff --git a/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
index a071414..8347c03 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
@@ -333,7 +333,7 @@
*/
private boolean isRegistered(TransactionalMap<ResourcePath, List<ResourcePath>> map, ResourcePath resource) {
// root is always regarded to be registered
- if (!resource.parent().isPresent()) {
+ if (resource.isRoot()) {
return true;
}