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.

        scheme - the scheme of the identifier, not empty
        value - the value of the identifier, not empty
        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'.

        str - the identifier to parse
        the identifier
        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.

        scheme - the scheme to encode
        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>
        other - the other external identifier
        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.
        equals in class Object
        obj - the other object
        true if equal
      • hashCode

        public int hashCode()
        Returns a suitable hash code, based on the scheme and value.
        hashCode in class Object
        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).

        toString in class Object
        a parsable representation of the identifier
      • meta

        public static StandardId.Meta meta()
        The meta-bean for StandardId.
        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.

        the value of the property, not null
      • getValue

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