Class StandardId

  • All Implemented Interfaces:
    Serializable, Comparable<StandardId>, org.joda.beans.Bean, org.joda.beans.ImmutableBean

    public final class StandardId
    extends Object
    implements Comparable<StandardId>, org.joda.beans.ImmutableBean, 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
    • Method Detail

      • of

        public static StandardId of​(String scheme,
                                    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​(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:
        IllegalArgumentException - if the identifier cannot be parsed
      • encodeScheme

        public static String encodeScheme​(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 Comparable<StandardId>
        Parameters:
        other - the other external identifier
        Returns:
        negative if this is less, zero if equal, positive if greater
      • equals

        public boolean equals​(Object obj)
        Checks if this identifier equals another, comparing the scheme and value.
        Overrides:
        equals in class 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 Object
        Returns:
        the hash code
      • toString

        public 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 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
      • metaBean

        public StandardId.Meta metaBean()
        Specified by:
        metaBean in interface org.joda.beans.Bean
      • getScheme

        public 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 String getValue()
        Gets the value of the identifier within the scheme.
        Returns:
        the value of the property, not null