Committed by
Gerrit Code Review
Refactor: Extract method to check if resource path is root
Change-Id: I87c23449c929bd169daa5fe788e340266392ddbe
Showing
2 changed files
with
11 additions
and
2 deletions
... | @@ -93,7 +93,7 @@ public final class ResourcePath { | ... | @@ -93,7 +93,7 @@ public final class ResourcePath { |
93 | * If there is no parent, empty instance will be returned. | 93 | * If there is no parent, empty instance will be returned. |
94 | */ | 94 | */ |
95 | public Optional<ResourcePath> parent() { | 95 | public Optional<ResourcePath> parent() { |
96 | - if (resources.size() > 0) { | 96 | + if (!isRoot()) { |
97 | return Optional.of(new ResourcePath(resources.subList(0, resources.size() - 1))); | 97 | return Optional.of(new ResourcePath(resources.subList(0, resources.size() - 1))); |
98 | } | 98 | } |
99 | 99 | ||
... | @@ -101,6 +101,15 @@ public final class ResourcePath { | ... | @@ -101,6 +101,15 @@ public final class ResourcePath { |
101 | } | 101 | } |
102 | 102 | ||
103 | /** | 103 | /** |
104 | + * Returns true if the path represents root. | ||
105 | + * | ||
106 | + * @return true if the path represents root, false otherwise. | ||
107 | + */ | ||
108 | + public boolean isRoot() { | ||
109 | + return resources.size() == 0; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
104 | * Returns the last component of this instance. | 113 | * Returns the last component of this instance. |
105 | * | 114 | * |
106 | * @return the last component of this instance. | 115 | * @return the last component of this instance. | ... | ... |
... | @@ -333,7 +333,7 @@ public class ConsistentResourceStore implements ResourceStore { | ... | @@ -333,7 +333,7 @@ public class ConsistentResourceStore implements ResourceStore { |
333 | */ | 333 | */ |
334 | private boolean isRegistered(TransactionalMap<ResourcePath, List<ResourcePath>> map, ResourcePath resource) { | 334 | private boolean isRegistered(TransactionalMap<ResourcePath, List<ResourcePath>> map, ResourcePath resource) { |
335 | // root is always regarded to be registered | 335 | // root is always regarded to be registered |
336 | - if (!resource.parent().isPresent()) { | 336 | + if (resource.isRoot()) { |
337 | return true; | 337 | return true; |
338 | } | 338 | } |
339 | 339 | ... | ... |
-
Please register or login to post a comment