Add consistency to UUIDUtils handling

* Use "_" instead of "-"
This commit is contained in:
Charles Allen 2015-03-17 16:03:41 -07:00
parent 79b1443cc3
commit 868100c79c
2 changed files with 11 additions and 4 deletions

View File

@ -28,7 +28,7 @@ import java.util.UUID;
*/
public class UUIDUtils
{
public static final String UUID_DELIM = "-";
public static final String UUID_DELIM = "_";
/**
* Generates a universally unique identifier.
@ -51,7 +51,7 @@ public class UUIDUtils
extra = Joiner.on(UUID_DELIM).join(extraStrings);
}
}
final String uuid = UUID.randomUUID().toString();
final String uuid = UUID.randomUUID().toString().replace("-", ""); // We don't use "-" in general, so remove them here.
return extra == null ? uuid : (extra + UUID_DELIM + uuid);
}
}

View File

@ -91,8 +91,15 @@ public class UUIDUtilsTest
String uuidString
)
{
UUID uuid = UUID.fromString(uuidString);
Assert.assertEquals(uuid.toString(), uuidString);
// Since we strip the "-" from the string, we need to break them back out
final ArrayList<String> strings = new ArrayList<>();
strings.add(uuidString.substring(0, 8));
strings.add(uuidString.substring(8, 12));
strings.add(uuidString.substring(12, 16));
strings.add(uuidString.substring(16, 20));
strings.add(uuidString.substring(20, 32));
UUID uuid = UUID.fromString(Joiner.on('-').join(strings));
Assert.assertEquals(uuid.toString().replace("-", ""), uuidString);
}
@Test