Class ColorId

java.lang.Object
com.google.javascript.jscomp.colors.ColorId
All Implemented Interfaces:
LogsGson.Able, Serializable

@Immutable public final class ColorId extends Object implements Serializable, LogsGson.Able
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:
  • Method Details

    • 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(String str)
    • union

      public static ColorId union(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(Object x)
      Overrides:
      equals in class Object
    • hashCode

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

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

      public String toString()
      Overrides:
      toString in class Object
    • toLogsGson

      public String toLogsGson()
      Specified by:
      toLogsGson in interface LogsGson.Able