Skip to content

Commit

Permalink
Make the UUIDPidMinter a special case of the UUIDPathMinter
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Oct 8, 2014
1 parent 5188186 commit 6b294e6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
Expand Up @@ -74,6 +74,11 @@ public String mintPid() {

try {
final String s = randomUUID().toString();

if (length == 0 || count == 0) {
return s;
}

final Iterable<String> split =
fixedLength(length).split(s.substring(0, length * count));

Expand Down
Expand Up @@ -28,24 +28,10 @@
* @author ajs6f
* @since Feb 7, 2013
*/
public class UUIDPidMinter extends BasePidMinter {
public class UUIDPidMinter extends UUIDPathMinter {

static final Timer timer = RegistryService.getInstance().getMetrics().timer(
name(UUIDPidMinter.class, "mint"));

/**
* Mint a unique identifier as a UUID
* @return uuid
*/
@Override
public String mintPid() {

final Timer.Context context = timer.time();

try {
return randomUUID().toString();
} finally {
context.stop();
}
}
public UUIDPidMinter() { super(0,0); }
}
Expand Up @@ -27,8 +27,9 @@
*/
public class UUIDPathMinterTest {

public static final String UUID_PATTERN = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}";
private static final String PID_PATTERN =
"[a-f0-9]{3}/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}";
"[a-f0-9]{3}/" + UUID_PATTERN;

@Test
public void testMintPid() {
Expand All @@ -39,4 +40,14 @@ public void testMintPid() {
.find());

}

@Test
public void testMintPidWithoutSegments() {

final String pid = new UUIDPathMinter(0, 0).mintPid();

assertTrue("PID wasn't a UUID path", compile(UUID_PATTERN).matcher(pid)
.find());

}
}

0 comments on commit 6b294e6

Please sign in to comment.