Class ShapeId

java.lang.Object
software.amazon.smithy.model.shapes.ShapeId
All Implemented Interfaces:
Comparable<ShapeId>, ToShapeId

public final class ShapeId extends Object implements ToShapeId, 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
  • Method Details

    • from

      public static ShapeId from(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.
    • fromNode

      public static ShapeId fromNode(Node node)
    • isValidNamespace

      public static boolean isValidNamespace(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(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(String namespace, String name, 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(String namespace, 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(String namespace, String relativeName)
      Builds a Id 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 from relativeName.
      Throws:
      ShapeIdSyntaxException - when the namespace or shape reference is malformed.
    • fromOptionalNamespace

      public static ShapeId fromOptionalNamespace(String defaultNamespace, String shapeName)
      Builds a 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.

      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(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()
      Specified by:
      toShapeId in interface ToShapeId
      Returns:
      Returns the shape ID of an object.
    • compareTo

      public int compareTo(ShapeId other)
      Specified by:
      compareTo in interface 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 String getNamespace()
      Get the namespace of the shape.
      Returns:
      Returns the namespace.
    • getName

      public 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 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 Optional<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 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(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 String toString()
      Converts the Id into a shape ID string. For example: "com.foo.bar#Baz$member".
      Overrides:
      toString in class Object
      Returns:
      Returns a shape ID as a string.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object