Class StandardId

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<StandardId>, Bean, ImmutableBean

    public final class StandardId
    extends java.lang.Object
    implements java.lang.Comparable<StandardId>, ImmutableBean, java.io.Serializable
    An immutable standard identifier for an item.

    A standard identifier is used to uniquely identify domain objects. It is formed from two parts, the scheme and value.

    The scheme defines a single way of identifying items, while the value is an identifier within that scheme. A value from one scheme may refer to a completely different real-world item than the same value from a different scheme.

    Real-world examples of StandardId include instances of:

    • Cusip
    • Isin
    • Reuters RIC
    • Bloomberg BUID
    • Bloomberg Ticker
    • Trading system OTC trade ID

    This class is immutable and thread-safe.

    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  StandardId.Meta
      The meta-bean for StandardId.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(StandardId other)
      Compares the external identifiers, sorting alphabetically by scheme followed by value.
      static java.lang.String encodeScheme​(java.lang.String scheme)
      Encode a string suitable for use as the scheme.
      boolean equals​(java.lang.Object obj)
      Checks if this identifier equals another, comparing the scheme and value.
      java.lang.String getScheme()
      Gets the scheme that categorizes the identifier value.
      java.lang.String getValue()
      Gets the value of the identifier within the scheme.
      int hashCode()
      Returns a suitable hash code, based on the scheme and value.
      static StandardId.Meta meta()
      The meta-bean for StandardId.
      StandardId.Meta metaBean()  
      static StandardId of​(java.lang.String scheme, java.lang.String value)
      Obtains an instance from a scheme and value.
      static StandardId parse​(java.lang.String str)
      Parses an StandardId from a formatted scheme and value.
      java.lang.String toString()
      Returns the identifier in a standard string format.
      • Methods inherited from class java.lang.Object

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

      • of

        public static StandardId of​(java.lang.String scheme,
                                    java.lang.String value)
        Obtains an instance from a scheme and value.

        The scheme must be non-empty and match the regular expression '[A-Za-z0-9:/+.=_-]*'. This permits letters, numbers, colon, forward-slash, plus, dot, equals, underscore and dash. If necessary, the scheme can be encoded using encodeScheme(String).

        The value must be non-empty and match the regular expression '[!-z][ -z]*'. This includes all standard printable ASCII characters excluding curly brackets, pipe and tilde.

        Parameters:
        scheme - the scheme of the identifier, not empty
        value - the value of the identifier, not empty
        Returns:
        the identifier
      • parse

        public static StandardId parse​(java.lang.String str)
        Parses an StandardId from a formatted scheme and value.

        This parses the identifier from the form produced by toString() which is '$scheme~$value'.

        Parameters:
        str - the identifier to parse
        Returns:
        the identifier
        Throws:
        java.lang.IllegalArgumentException - if the identifier cannot be parsed
      • encodeScheme

        public static java.lang.String encodeScheme​(java.lang.String scheme)
        Encode a string suitable for use as the scheme.

        This uses percent encoding, just like URI.

        Parameters:
        scheme - the scheme to encode
        Returns:
        the encoded scheme
      • compareTo

        public int compareTo​(StandardId other)
        Compares the external identifiers, sorting alphabetically by scheme followed by value.
        Specified by:
        compareTo in interface java.lang.Comparable<StandardId>
        Parameters:
        other - the other external identifier
        Returns:
        negative if this is less, zero if equal, positive if greater
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks if this identifier equals another, comparing the scheme and value.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the other object
        Returns:
        true if equal
      • hashCode

        public int hashCode()
        Returns a suitable hash code, based on the scheme and value.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code
      • toString

        public java.lang.String toString()
        Returns the identifier in a standard string format.

        The returned string is in the form '$scheme~$value'. This is suitable for use with parse(String).

        Overrides:
        toString in class java.lang.Object
        Returns:
        a parsable representation of the identifier
      • meta

        public static StandardId.Meta meta()
        The meta-bean for StandardId.
        Returns:
        the meta-bean, not null
      • getScheme

        public java.lang.String getScheme()
        Gets the scheme that categorizes the identifier value.

        This provides the universe within which the identifier value has meaning.

        Returns:
        the value of the property, not null
      • getValue

        public java.lang.String getValue()
        Gets the value of the identifier within the scheme.
        Returns:
        the value of the property, not null