Class ShapeId
- java.lang.Object
-
- software.amazon.smithy.model.shapes.ShapeId
-
public final class ShapeId extends java.lang.Object implements ToShapeId, java.lang.Comparable<ShapeId>
Immutable identifier for each shape in a model.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
- Relative path :
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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
fromNode(Node node)
static ShapeId
fromOptionalNamespace(java.lang.String defaultNamespace, java.lang.String shapeName)
Builds aId
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 aId
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()
boolean
hasMember()
Checks if the ID has a member set.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 theId
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.
-
-
-
Method Detail
-
from
public static ShapeId from(java.lang.String id)
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.
-
isValidNamespace
public static boolean isValidNamespace(java.lang.CharSequence namespace)
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
public static boolean isValidIdentifier(java.lang.CharSequence identifier)
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
public 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.- 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
public static ShapeId fromParts(java.lang.String namespace, java.lang.String name)
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
public static ShapeId fromRelative(java.lang.String namespace, java.lang.String relativeName)
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
public static ShapeId fromOptionalNamespace(java.lang.String defaultNamespace, java.lang.String shapeName)
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
public ShapeId withMember(java.lang.String member)
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
public ShapeId toShapeId()
-
compareTo
public int compareTo(ShapeId other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<ShapeId>
-
withoutMember
public 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
public java.lang.String getNamespace()
Get the namespace of the shape.- Returns:
- Returns the namespace.
-
getName
public java.lang.String 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
public java.lang.String getName(ServiceShape service)
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
public java.util.Optional<java.lang.String> 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
public java.lang.String asRelativeReference()
Creates a string that contains a relative reference to the ID.- Returns:
- Returns a relative shape ID string with no namespace.
-
withNamespace
public ShapeId withNamespace(java.lang.String namespace)
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
public java.lang.String toString()
Converts theId
into a shape ID string. For example: "com.foo.bar#Baz$member".- Overrides:
toString
in classjava.lang.Object
- Returns:
- Returns a shape ID as a string.
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-