Skip to content

Commit

Permalink
make the length and count of the branch node identifiers configurable…
Browse files Browse the repository at this point in the history
… at the constructor
  • Loading branch information
cbeer committed Jun 25, 2013
1 parent dfd898c commit 1a26123
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Expand Up @@ -14,7 +14,18 @@
public class UUIDPathMinter extends BasePidMinter {

static final Timer timer = getMetrics().timer(name(UUIDPathMinter.class, "mint"));
private final int length;
private final int count;

public UUIDPathMinter() {
this(2,4);

}

public UUIDPathMinter(final int length, final int count) {
this.length = length;
this.count = count;
}

/**
* Mint a unique identifier as a UUID
Expand All @@ -27,7 +38,7 @@ public String mintPid() {

try {
final String s = randomUUID().toString();
final Iterable<String> split = Splitter.fixedLength(2).split(s.substring(0, 8));
final Iterable<String> split = Splitter.fixedLength(length).split(s.substring(0, length * count));

return Joiner.on("/").join(split) + "/" + s;
} finally {
Expand Down
Expand Up @@ -24,7 +24,7 @@ public class UUIDPathMinterTest {
@Test
public void testMintPid() throws Exception {

final PidMinter pidMinter = new UUIDPathMinter();
final PidMinter pidMinter = new UUIDPathMinter(3, 1);

final String pid = pidMinter.mintPid();

Expand Down

0 comments on commit 1a26123

Please sign in to comment.