@Test public void testValidate() throws Exception { Uuids.validate("94528104-2121-46d3-ad47-a9f0b296ed1f"); Uuids.validate("94528104-2121-46d3-aD47-a9f0b296ed1f"); try { Uuids.validate("94528104-2121-46d3-ad47a9f0b296ed1f"); fail(); } catch (IllegalArgumentException e) { } try { Uuids.validate("94528104-2121-46d3-aR47a9f0b296ed1f"); fail(); } catch (IllegalArgumentException e) { } }
public static void validate(String uuid) throws IllegalArgumentException { if(uuid == null) { throw new IllegalArgumentException("Uuid is null."); } final int length = uuid.length(); if(length != 36) { throw new IllegalArgumentException("Uuid: '" + uuid + "' - has invalid length."); } int i = 0; while(i < length) { char c = uuid.charAt(i); if(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f' || (c == '-' && (i == 8 || i == 13 || i == 18 || i == 23))) { i++; continue; } throw new IllegalArgumentException("Uuid: '" + uuid + "' - has invalid char '" + c + "' at " + i + "."); } }
Uuids { public static void validate(String uuid) throws IllegalArgumentException { if(uuid == null) { throw new IllegalArgumentException("Uuid is null."); } final int length = uuid.length(); if(length != 36) { throw new IllegalArgumentException("Uuid: '" + uuid + "' - has invalid length."); } int i = 0; while(i < length) { char c = uuid.charAt(i); if(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f' || (c == '-' && (i == 8 || i == 13 || i == 18 || i == 23))) { i++; continue; } throw new IllegalArgumentException("Uuid: '" + uuid + "' - has invalid char '" + c + "' at " + i + "."); } } }
Uuids { public static void validate(String uuid) throws IllegalArgumentException { if(uuid == null) { throw new IllegalArgumentException("Uuid is null."); } final int length = uuid.length(); if(length != 36) { throw new IllegalArgumentException("Uuid: '" + uuid + "' - has invalid length."); } int i = 0; while(i < length) { char c = uuid.charAt(i); if(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f' || (c == '-' && (i == 8 || i == 13 || i == 18 || i == 23))) { i++; continue; } throw new IllegalArgumentException("Uuid: '" + uuid + "' - has invalid char '" + c + "' at " + i + "."); } }  }
Uuids { public static void validate(String uuid) throws IllegalArgumentException { if(uuid == null) { throw new IllegalArgumentException("Uuid is null."); } final int length = uuid.length(); if(length != 36) { throw new IllegalArgumentException("Uuid: '" + uuid + "' - has invalid length."); } int i = 0; while(i < length) { char c = uuid.charAt(i); if(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f' || (c == '-' && (i == 8 || i == 13 || i == 18 || i == 23))) { i++; continue; } throw new IllegalArgumentException("Uuid: '" + uuid + "' - has invalid char '" + c + "' at " + i + "."); } }  static void validate(String uuid); static UUID liteRandom(); static String longUid(); }
Uuids { public static void validate(String uuid) throws IllegalArgumentException { if(uuid == null) { throw new IllegalArgumentException("Uuid is null."); } final int length = uuid.length(); if(length != 36) { throw new IllegalArgumentException("Uuid: '" + uuid + "' - has invalid length."); } int i = 0; while(i < length) { char c = uuid.charAt(i); if(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f' || (c == '-' && (i == 8 || i == 13 || i == 18 || i == 23))) { i++; continue; } throw new IllegalArgumentException("Uuid: '" + uuid + "' - has invalid char '" + c + "' at " + i + "."); } }  static void validate(String uuid); static UUID liteRandom(); static String longUid();  }