public final class ShapeId extends java.lang.Object implements ToShapeId, java.lang.Comparable<ShapeId>
A shape ID is constructed from an absolute or relative shape
reference. A shape reference has the following structure:
NAMESPACE#NAME$MEMBER
An absolute reference contains a namespace and a pound sign. A relative reference omits the namespace and pound sign prefix. In both absolute and relative shape references, the member is optional.
ShapeName
ShapeName$memberName
name.space#ShapeName
name.space#ShapeName$memberName
Modifier and Type | Method and Description |
---|---|
java.lang.String |
asRelativeReference()
Creates a string that contains a relative reference to the ID.
|
int |
compareTo(ShapeId other) |
boolean |
equals(java.lang.Object other) |
static ShapeId |
from(java.lang.String id)
Creates an absolute shape ID from the given string.
|
static ShapeId |
fromOptionalNamespace(java.lang.String defaultNamespace,
java.lang.String shapeName)
Builds a
Id from the given reference. |
static ShapeId |
fromParts(java.lang.String namespace,
java.lang.String name)
Creates an absolute shape ID from parts of a shape ID.
|
static ShapeId |
fromParts(java.lang.String namespace,
java.lang.String name,
java.lang.String member)
Creates an absolute shape ID from parts of a shape ID.
|
static ShapeId |
fromRelative(java.lang.String namespace,
java.lang.String relativeName)
Builds a
Id from a relative shape reference. |
java.util.Optional<java.lang.String> |
getMember()
Gets the optional member of the shape.
|
java.lang.String |
getName()
Get the name of the shape.
|
java.lang.String |
getName(ServiceShape service)
Get the name of the shape when it is used within the contextual
closure of a service.
|
java.lang.String |
getNamespace()
Get the namespace of the shape.
|
int |
hashCode() |
static boolean |
isValidIdentifier(java.lang.CharSequence identifier)
Checks if the given string is a valid identifier.
|
static boolean |
isValidNamespace(java.lang.CharSequence namespace)
Checks if the given string is a valid namespace.
|
ShapeId |
toShapeId() |
java.lang.String |
toString()
Converts the
Id into a shape ID string. |
ShapeId |
withMember(java.lang.String member)
Creates a new Shape.Id with a member add to it.
|
ShapeId |
withNamespace(java.lang.String namespace)
Creates a shape ID that uses a different namespace than the current ID.
|
ShapeId |
withoutMember()
Creates a new Shape.Id with no member.
|
public static ShapeId from(java.lang.String id)
id
- Shape ID to parse.ShapeIdSyntaxException
- when the ID is malformed.public static boolean isValidNamespace(java.lang.CharSequence namespace)
namespace
- Namespace value to check.public static boolean isValidIdentifier(java.lang.CharSequence identifier)
identifier
- Identifier value to check.public static ShapeId fromParts(java.lang.String namespace, java.lang.String name, java.lang.String member)
namespace
- Namespace of the shape.name
- Name of the shape.member
- Optional/nullable member name.ShapeIdSyntaxException
- when the ID is malformed.public static ShapeId fromParts(java.lang.String namespace, java.lang.String name)
namespace
- Namespace of the shape.name
- Name of the shape.ShapeIdSyntaxException
- when the ID is malformed.public static ShapeId fromRelative(java.lang.String namespace, java.lang.String relativeName)
Id
from a relative shape reference.
The given shape reference must not contain a namespace prefix. It may contain a member.
namespace
- The namespace.relativeName
- A relative shape reference.Id
extracted from relativeName
.ShapeIdSyntaxException
- when the namespace or shape reference
is malformed.public static ShapeId fromOptionalNamespace(java.lang.String defaultNamespace, java.lang.String shapeName)
Id
from the given reference.
If the shape reference contains a namespace, it is treated as an absolute reference. If it does not contain a namespace prefix, it is treated as a relative shape reference and the given default namespace is used.
defaultNamespace
- The namespace to use when the shape reference
does not contain a namespace.shapeName
- A relative or absolute shape reference.Id
extracted from shape reference.ShapeIdSyntaxException
- when the namespace or shape reference
is malformed.public ShapeId withMember(java.lang.String member)
member
- Member to set.ShapeIdSyntaxException
- if the member name syntax is invalid.public ShapeId toShapeId()
public int compareTo(ShapeId other)
compareTo
in interface java.lang.Comparable<ShapeId>
public ShapeId withoutMember()
public java.lang.String getNamespace()
public java.lang.String getName()
Use getName(ServiceShape)
when performing transformations
like code generation of the shapes used in services or clients.
public java.lang.String getName(ServiceShape service)
This method should be used when performing transformations like code generation of a Smithy model. Service shapes can rename shapes used within the closure of a service to give shapes unambiguous names independent of a namespace.
This is a mirror of ServiceShape.getContextualName(ToShapeId)
that serves to make this functionality more discoverable.
service
- Service shape used to contextualize the name.public java.util.Optional<java.lang.String> getMember()
public java.lang.String asRelativeReference()
public ShapeId withNamespace(java.lang.String namespace)
namespace
- Namespace to use.ShapeIdSyntaxException
- if the namespace is invalid.public java.lang.String toString()
Id
into a shape ID string.
For example: "com.foo.bar#Baz$member".toString
in class java.lang.Object
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object