@Test public void allSharedTokensShouldHaveDifferentIds() { Stream<LockToken> tokens = LockTokenShare.share(LOCK_TOKEN, 3); assertThat(tokens) .extracting(LockToken::getRequestId) .doesNotHaveDuplicates() .hasSize(3); }
static Stream<LockToken> share(LockToken token, int referenceCount) { Preconditions.checkArgument(referenceCount > 0, "Reference count should be more than zero"); Preconditions.checkArgument(!(token instanceof LockTokenShare), "Can not share a shared lock token"); ReferenceCounter referenceCounter = new ReferenceCounter(referenceCount); return IntStream.range(0, referenceCount) .mapToObj(unused -> new LockTokenShare(referenceCounter, token)); }
LockTokenShare implements LockToken { static Stream<LockToken> share(LockToken token, int referenceCount) { Preconditions.checkArgument(referenceCount > 0, "Reference count should be more than zero"); Preconditions.checkArgument(!(token instanceof LockTokenShare), "Can not share a shared lock token"); ReferenceCounter referenceCounter = new ReferenceCounter(referenceCount); return IntStream.range(0, referenceCount) .mapToObj(unused -> new LockTokenShare(referenceCounter, token)); } }
LockTokenShare implements LockToken { static Stream<LockToken> share(LockToken token, int referenceCount) { Preconditions.checkArgument(referenceCount > 0, "Reference count should be more than zero"); Preconditions.checkArgument(!(token instanceof LockTokenShare), "Can not share a shared lock token"); ReferenceCounter referenceCounter = new ReferenceCounter(referenceCount); return IntStream.range(0, referenceCount) .mapToObj(unused -> new LockTokenShare(referenceCounter, token)); } private  LockTokenShare(ReferenceCounter referenceCounter, LockToken token); }
LockTokenShare implements LockToken { static Stream<LockToken> share(LockToken token, int referenceCount) { Preconditions.checkArgument(referenceCount > 0, "Reference count should be more than zero"); Preconditions.checkArgument(!(token instanceof LockTokenShare), "Can not share a shared lock token"); ReferenceCounter referenceCounter = new ReferenceCounter(referenceCount); return IntStream.range(0, referenceCount) .mapToObj(unused -> new LockTokenShare(referenceCounter, token)); } private  LockTokenShare(ReferenceCounter referenceCounter, LockToken token); @Override UUID getRequestId(); @Override SafeArg<?> toSafeArg(String name); }
LockTokenShare implements LockToken { static Stream<LockToken> share(LockToken token, int referenceCount) { Preconditions.checkArgument(referenceCount > 0, "Reference count should be more than zero"); Preconditions.checkArgument(!(token instanceof LockTokenShare), "Can not share a shared lock token"); ReferenceCounter referenceCounter = new ReferenceCounter(referenceCount); return IntStream.range(0, referenceCount) .mapToObj(unused -> new LockTokenShare(referenceCounter, token)); } private  LockTokenShare(ReferenceCounter referenceCounter, LockToken token); @Override UUID getRequestId(); @Override SafeArg<?> toSafeArg(String name);  }