cowtowncoder / java-uuid-generator

Java Uuid Generator (JUG) is a Java library for generating all standard UUID versions (v1 - v7)
Apache License 2.0
751 stars 103 forks source link

Add customisable clock to UUIDTimer #36

Closed FWDekker closed 4 years ago

FWDekker commented 4 years ago

Fixes #20.

Adds a class called UUIDClock of which the only purpose is to return the current time using System.currentTimeMillis(). End users can create a subclass of UUIDClock to return whatever they want. The UUIDClock is given to the UUIDTimer in its constructor, and the clock is used instead of directly calling System.currentTimeMillis. I've added a separate constructor to UUIDTimer for backwards compatibility; using the old constructor will cause the UUIDTimer to use the default implementation of UUIDClock.

I've added a single test which verifies that creating two different UUIDTimers in the same way will result in the same result.

cowtowncoder commented 4 years ago

@FWDekker thank you for submitting this -- seems legit, but I need to spend some time thinking it through just to make sure. Hoping to merge soon, then release new minor version due to API addition (3.3.0)

FWDekker commented 4 years ago

Do you have any updates on this? If there are any specific doubts or complaints you have I'd be happy to address those.

cowtowncoder commented 4 years ago

@FWDekker No doubts, just little bit busy life outside OSS work. This was on top of my todo list, so happy to merge now and hopefully get release out tonight (once I have access to my build system). Thank you for the improvement!

FWDekker commented 4 years ago

@cowtowncoder No worries! And thanks for the merge!

cowtowncoder commented 4 years ago

Thank you for the PR: 3.3.0 should be out now via Maven Central.