Class ColorId

  • All Implemented Interfaces:
    java.io.Serializable

    @Immutable
    public final class ColorId
    extends java.lang.Object
    implements java.io.Serializable
    A probablistically unique ID for a Color.

    This is a semantic wrapper around UUID bytes to provide better typing when passing those bytes around. It also hosts some utility methods to ensure consistent byte handling and help with testing/debugging.

    If two Colors have the same ID, they should be considered to represent the same "logical" Color, perhaps inferred in different libraries. Ideally, those instances would be reconciled before either Color is instantiated.

    IDs have an intentionally unspecified width so that it may expand if needed in the future. For the purposes of comparison, serialization, and display, leading 0s are ignored.

    See Also:
    Serialized Form
    • Method Detail

      • fromUnsigned

        public static ColorId fromUnsigned​(long x)
      • fromUnsigned

        public static ColorId fromUnsigned​(int x)
      • fromUnsigned

        public static ColorId fromUnsigned​(byte x)
      • fromBytes

        public static ColorId fromBytes​(com.google.protobuf.ByteString bytes)
      • fromBytes

        public static ColorId fromBytes​(byte[] bytes)
      • fromAscii

        public static ColorId fromAscii​(java.lang.String str)
      • union

        public static ColorId union​(java.util.Set<ColorId> ids)
        Defines how IDs for unions are combined.

        Ideally, this function would preserve the algebraic properties of the union operation. However, doing so is difficult (impossible?) while also providing good hashing. Those properties are summarized below.

        This method must never be passed IDs of existing unions. Lack of associativity means the result will not be the same as unioning all the IDs simultaneously.

         | name          | has   | example                       | note                        |
         |---------------|-------|-------------------------------|-----------------------------|
         | associativity | false | f(x, f(y, z)) = f(f(x, y), z) |                             |
         | commutativity | true  |       f(x, y) = f(y, x)       |                             |
         | idempotence   | true  |    f(x, x, y) = f(x, y)       | `ids` is a Set              |
         | identity      | true  |          f(x) = x             | singleton unions are banned |
         
      • equals

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

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

        public com.google.protobuf.ByteString asByteString()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object