@Test public void basicUuidComperisonTest() { Random r = new Random(System.currentTimeMillis()); for (int i = 0; i < 100000; i++) { long ts = System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 365 * 10; long before = (long) (Math.random() * ts); long after = (long) (Math.random() * ts); if (before > after) { long tmp = after; after = before; before = tmp; } String beforeStr = UUIDConverter.fromTimeUUID(Uuids.startOf(before)); String afterStr = UUIDConverter.fromTimeUUID(Uuids.startOf(after)); if (afterStr.compareTo(beforeStr) < 0) { System.out.println("Before: " + before + " | " + beforeStr); System.out.println("After: " + after + " | " + afterStr); } Assert.assertTrue(afterStr.compareTo(beforeStr) >= 0); } }
public static String fromTimeUUID(UUID src) { if (src.version() != 1) { throw new IllegalArgumentException("Only Time-Based UUID (Version 1) is supported!"); } String str = src.toString(); return str.substring(15, 18) + str.substring(9, 13) + str.substring(0, 8) + str.substring(19, 23) + str.substring(24); }
UUIDConverter { public static String fromTimeUUID(UUID src) { if (src.version() != 1) { throw new IllegalArgumentException("Only Time-Based UUID (Version 1) is supported!"); } String str = src.toString(); return str.substring(15, 18) + str.substring(9, 13) + str.substring(0, 8) + str.substring(19, 23) + str.substring(24); } }
UUIDConverter { public static String fromTimeUUID(UUID src) { if (src.version() != 1) { throw new IllegalArgumentException("Only Time-Based UUID (Version 1) is supported!"); } String str = src.toString(); return str.substring(15, 18) + str.substring(9, 13) + str.substring(0, 8) + str.substring(19, 23) + str.substring(24); }  }
UUIDConverter { public static String fromTimeUUID(UUID src) { if (src.version() != 1) { throw new IllegalArgumentException("Only Time-Based UUID (Version 1) is supported!"); } String str = src.toString(); return str.substring(15, 18) + str.substring(9, 13) + str.substring(0, 8) + str.substring(19, 23) + str.substring(24); }  static UUID fromString(String src); static String fromTimeUUID(UUID src); static List<String> fromTimeUUIDs(List<UUID> uuids); }
UUIDConverter { public static String fromTimeUUID(UUID src) { if (src.version() != 1) { throw new IllegalArgumentException("Only Time-Based UUID (Version 1) is supported!"); } String str = src.toString(); return str.substring(15, 18) + str.substring(9, 13) + str.substring(0, 8) + str.substring(19, 23) + str.substring(24); }  static UUID fromString(String src); static String fromTimeUUID(UUID src); static List<String> fromTimeUUIDs(List<UUID> uuids);  }