Class UUIDComparator

java.lang.Object
com.fasterxml.uuid.UUIDComparator
All Implemented Interfaces:
Comparator<UUID>

public class UUIDComparator extends Object implements Comparator<UUID>
Default UUID comparator is not very useful, since it just does blind byte-by-byte comparison which does not work well for time+location - based UUIDs. Additionally, it also uses signed comparisons for longs which can lead to unexpected behavior This comparator does implement proper lexical ordering: starting with type (different types are collated separately), followed by time and location (for time/location based), and simple lexical (byte-by-byte) ordering for name/hash and random versions.
Author:
tatu
  • Constructor Details

    • UUIDComparator

      public UUIDComparator()
  • Method Details

    • compare

      public int compare(UUID u1, UUID u2)
      Specified by:
      compare in interface Comparator<UUID>
    • staticCompare

      public static int staticCompare(UUID u1, UUID u2)
      Static helper method that can be used instead of instantiating comparator (used by unit tests, can be used by code too)
    • compareULongs

      protected static final int compareULongs(long l1, long l2)
    • compareUInts

      protected static final int compareUInts(int i1, int i2)