Class ShapeId
- All Implemented Interfaces:
Comparable<ShapeId>
,ToShapeId
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.
- Relative path :
ShapeName
- Relative path with a member :
ShapeName$memberName
- Absolute path :
name.space#ShapeName
- Absolute path with a member :
name.space#ShapeName$memberName
-
Method Summary
Modifier and TypeMethodDescriptionCreates a string that contains a relative reference to the ID.int
boolean
static ShapeId
Creates an absolute shape ID from the given string.static ShapeId
static ShapeId
fromOptionalNamespace
(String defaultNamespace, String shapeName) Builds aId
from the given reference.static ShapeId
Creates an absolute shape ID from parts of a shape ID.static ShapeId
Creates an absolute shape ID from parts of a shape ID.static ShapeId
fromRelative
(String namespace, String relativeName) Builds aId
from a relative shape reference.Gets the optional member of the shape.getName()
Get the name of the shape.getName
(ServiceShape service) Get the name of the shape when it is used within the contextual closure of a service.Get the namespace of the shape.int
hashCode()
boolean
Checks if the ID has a member set.static boolean
isValidIdentifier
(CharSequence identifier) Checks if the given string is a valid identifier.static boolean
isValidNamespace
(CharSequence namespace) Checks if the given string is a valid namespace.toString()
Converts theId
into a shape ID string.withMember
(String member) Creates a new Shape.Id with a member add to it.withNamespace
(String namespace) Creates a shape ID that uses a different namespace than the current ID.Creates a new Shape.Id with no member.
-
Method Details
-
from
Creates an absolute shape ID from the given string.- Parameters:
id
- Shape ID to parse.- Returns:
- The parsed ID.
- Throws:
ShapeIdSyntaxException
- when the ID is malformed.
-
fromNode
-
isValidNamespace
Checks if the given string is a valid namespace.- Parameters:
namespace
- Namespace value to check.- Returns:
- Returns true if this is a valid namespace.
-
isValidIdentifier
Checks if the given string is a valid identifier.- Parameters:
identifier
- Identifier value to check.- Returns:
- Returns true if this is a valid identifier.
-
fromParts
Creates an absolute shape ID from parts of a shape ID.- Parameters:
namespace
- Namespace of the shape.name
- Name of the shape.member
- Optional/nullable member name.- Returns:
- The parsed ID.
- Throws:
ShapeIdSyntaxException
- when the ID is malformed.
-
fromParts
Creates an absolute shape ID from parts of a shape ID.- Parameters:
namespace
- Namespace of the shape.name
- Name of the shape.- Returns:
- The parsed ID.
- Throws:
ShapeIdSyntaxException
- when the ID is malformed.
-
fromRelative
Builds aId
from a relative shape reference.The given shape reference must not contain a namespace prefix. It may contain a member.
- Parameters:
namespace
- The namespace.relativeName
- A relative shape reference.- Returns:
- Returns a
Id
extracted fromrelativeName
. - Throws:
ShapeIdSyntaxException
- when the namespace or shape reference is malformed.
-
fromOptionalNamespace
Builds aId
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.
- Parameters:
defaultNamespace
- The namespace to use when the shape reference does not contain a namespace.shapeName
- A relative or absolute shape reference.- Returns:
- Returns a
Id
extracted from shape reference. - Throws:
ShapeIdSyntaxException
- when the namespace or shape reference is malformed.
-
withMember
Creates a new Shape.Id with a member add to it.- Parameters:
member
- Member to set.- Returns:
- returns a new Shape.Id
- Throws:
ShapeIdSyntaxException
- if the member name syntax is invalid.
-
toShapeId
-
compareTo
- Specified by:
compareTo
in interfaceComparable<ShapeId>
-
withoutMember
Creates a new Shape.Id with no member.- Returns:
- returns a new Shape.Id, or the existing shape if it has no member.
-
getNamespace
Get the namespace of the shape.- Returns:
- Returns the namespace.
-
getName
Get the name of the shape.Use
getName(ServiceShape)
when performing transformations like code generation of the shapes used in services or clients.- Returns:
- Returns the name.
-
getName
Get the name of the shape when it is used within the contextual closure of a 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.- Parameters:
service
- Service shape used to contextualize the name.- Returns:
- Returns the contextualized shape name when used in a service.
-
getMember
Gets the optional member of the shape.- Returns:
- Returns the optional member.
-
hasMember
public boolean hasMember()Checks if the ID has a member set.- Returns:
- Returns true if the ID has a member.
-
asRelativeReference
Creates a string that contains a relative reference to the ID.- Returns:
- Returns a relative shape ID string with no namespace.
-
withNamespace
Creates a shape ID that uses a different namespace than the current ID.- Parameters:
namespace
- Namespace to use.- Returns:
- Returns the shape ID with the changed namespace.
- Throws:
ShapeIdSyntaxException
- if the namespace is invalid.
-
toString
Converts theId
into a shape ID string. For example: "com.foo.bar#Baz$member". -
equals
-
hashCode
public int hashCode()
-