public static ArnResource fromString(String resource) {
        Integer resourceTypeBoundary = null;
        Integer resourceIdBoundary = null;

        for (int i = 0; i < resource.length(); ++i) {
            char ch = resource.charAt(i);

            if (ch == ':' || ch == '/') {
                resourceTypeBoundary = i;
                break;
            }
        }

        if (resourceTypeBoundary != null) {
            for (int i = resource.length() - 1; i > resourceTypeBoundary; --i) {
                char ch = resource.charAt(i);

                if (ch == ':') {
                    resourceIdBoundary = i;
                    break;
                }
            }
        }

        if (resourceTypeBoundary == null) {
            // 'resource-id'
            return ArnResource.builder().withResource(resource).build();
        } else if (resourceIdBoundary == null) {
            // 'resource-type:resource-id'
            String resourceType = resource.substring(0, resourceTypeBoundary);
            String resourceId = resource.substring(resourceTypeBoundary + 1);
            return ArnResource.builder().withResourceType(resourceType).withResource(resourceId).build();
        } else {
            // 'resource-type:resource-id:qualifier'
            String resourceType = resource.substring(0, resourceTypeBoundary);
            String resourceId = resource.substring(resourceTypeBoundary + 1, resourceIdBoundary);
            String qualifier = resource.substring(resourceIdBoundary + 1);
            return ArnResource.builder()
                              .withResourceType(resourceType)
                              .withResource(resourceId)
                              .withQualifier(qualifier).build();
        }
    }
Parses a string containing either a resource, resource type and resource or
resource type, resource and qualifier into an {@link ArnResource}.
<p>
Matches:
<p><pre>
resource-id
resource-type:resource-id
resource-type/resource-id
resource-type:resource-id:qualifier
resource-type/resource-id:qualifier
</pre><p>
resource-id can be a resource name or a resource path.

@param resource - The resource string to parse.
@return {@link ArnResource}
aws-java-sdk-core/src/main/java/com/amazonaws/arn/ArnResource.java