Class ShapeId

  • All Implemented Interfaces:
    java.lang.Comparable<ShapeId>, ToShapeId

    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
    • 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 absoluteShapeId)
      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 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 withoutMember()
      Creates a new Shape.Id with no member.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • from

        public static ShapeId from​(java.lang.String absoluteShapeId)
        Creates an absolute shape ID from the given string.
        Parameters:
        absoluteShapeId - 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 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​(java.lang.String defaultNamespace,
                                                    java.lang.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​(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()
        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 java.lang.Comparable<ShapeId>
      • withoutMember

        public ShapeId withoutMember()
        Creates a new Shape.Id with no member.
        Returns:
        returns a new Shape.Id
      • 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.
        Returns:
        Returns the name.
      • getMember

        public java.util.Optional<java.lang.String> getMember()
        Gets the optional member of the shape.
        Returns:
        Returns the optional 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.
      • toString

        public java.lang.String toString()
        Converts the Id into a shape ID string. For example: "com.foo.bar#Baz$member".
        Overrides:
        toString in class java.lang.Object
        Returns:
        Returns a shape ID as a string.
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object