Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: Extract method to check if resource path is root

Change-Id: I87c23449c929bd169daa5fe788e340266392ddbe
......@@ -93,7 +93,7 @@ public final class ResourcePath {
* 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 @@ public final class ResourcePath {
}
/**
* 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.
......
......@@ -333,7 +333,7 @@ public class ConsistentResourceStore implements ResourceStore {
*/
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;
}
......