ResourceName { public static ResourceName parseResource(String resourceUrlParam) { String resourceUrl; if (resourceUrlParam.startsWith(Compute.DEFAULT_ROOT_URL)) { resourceUrl = resourceUrlParam.substring(resourceUrlParam.indexOf("/projects/") + 10); } else if (resourceUrlParam.startsWith("projects/")) { resourceUrl = resourceUrlParam.substring("projects/".length()); } else { resourceUrl = resourceUrlParam; } String[] parts = resourceUrl.split("/", 5); String apiProjectId = parts[0]; ComputeResourceType computeResourceType; String resourceName; String parentResourceName = null; if (parts.length > 1) { if (parts.length == 3) { computeResourceType = ComputeResourceType.lookup(parts[1]); resourceName = parts[2]; } else if (parts[1].equals(GLOBAL_RESOURCE_SCOPE)) { if (parts[2].equals(IMAGE_RESOURCE_TYPE_IN_GCE)) { if (ComputeUtils.ProjectMapper.valueOfProjectName(apiProjectId) != null) { computeResourceType = ComputeResourceType.DEFAULT_IMAGE; } else { computeResourceType = ComputeResourceType.CUSTOM_IMAGE; } } else { computeResourceType = ComputeResourceType.lookup(parts[2]); } resourceName = parts[3]; } else { parentResourceName = parts[2]; computeResourceType = ComputeResourceType.lookup(parts[3]); resourceName = parts[4]; } checkNotNull(computeResourceType, "Unknown compute resource type for resource URL '%s'", resourceUrl); } else { computeResourceType = ComputeResourceType.PROJECT; resourceName = parts[0]; } return new ResourceName(apiProjectId, computeResourceType, parentResourceName, resourceName); } ResourceName(
      String apiProjectId,
      ComputeResourceType resourceType,
      @Nullable String parentResourceName,
      String resourceName); String getApiProjectId(); ComputeResourceType getResourceType(); String getResourceName(); @Nullable String getParentResourceName(); String getResourceUrl(); @Override String toString(); @Override int hashCode(); @Override boolean equals(@Nullable Object o); static ResourceName parseResource(String resourceUrlParam); static ResourceName buildName(Instance instance); static ResourceName buildName(
      Project project,
      ComputeResourceType computeResourceType,
      String simpleName); static ResourceName buildName(
      Project project,
      ComputeResourceType computeResourceType,
      @Nullable String parentResourceName,
      String simpleName); static ResourceName buildName(
      String apiProjectId,
      ComputeResourceType computeResourceType,
      String simpleName); static ResourceName buildName(
      String apiProjectId,
      ComputeResourceType computeResourceType,
      @Nullable String parentResourceName,
      String simpleName); static ResourceName buildName(ProjectUser projectUser, ResourceId resourceId); static ResourceName buildName(
      ProjectUser projectUser,
      @Nullable String parentResourceName,
      ResourceId resourceId); static ResourceName buildName(Project project, ResourceId resourceId); static ResourceName buildName(
      Project project,
      @Nullable String parentResourceName,
      ResourceId resourceId); static ResourceName buildName(String apiProjectId, ResourceId resourceId); static ResourceName buildName(
      String apiProjectId,
      @Nullable String parentResourceName,
      ResourceId resourceId); static @Nullable ResourceName parseFromErrorMessage(GoogleJsonError error); static @Nullable ResourceName parseFromErrorMessage(String errorMessage);  }
@Test public void parseResource_createdByOlderApi_ok() { ResourceName.parseResource(ZONE_URL.replaceFirst(API_TAG, "v1beta0")); }