ArnResource { 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) { return ArnResource.builder().withResource(resource).build(); } else if (resourceIdBoundary == null) { String resourceType = resource.substring(0, resourceTypeBoundary); String resourceId = resource.substring(resourceTypeBoundary + 1); return ArnResource.builder().withResourceType(resourceType).withResource(resourceId).build(); } else { 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(); } } private  ArnResource(Builder b); String getResourceType(); String getResource(); String getQualifier(); static Builder builder(); static ArnResource fromString(String resource); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test(expected = IllegalArgumentException.class) public void fromString_colonForm_typeWithNoId() { ArnResource.fromString("bob:"); }
@Test(expected = IllegalArgumentException.class) public void fromString_slashForm_typeWithNoId() { ArnResource.fromString("bob/"); }