Remove method from GuidCreator

The method withoutOverrunException() is not necessary anymore.
This commit is contained in:
Fabio Lima 2020-02-24 00:03:38 -03:00
parent 7ec2a7cc98
commit 111592751a
3 changed files with 4 additions and 23 deletions

View File

@ -51,7 +51,7 @@ Add these lines to your `pom.xml`.
<dependency>
<groupId>com.github.f4b6a3</groupId>
<artifactId>ulid-creator</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</dependency>
```
See more options in [maven.org](https://search.maven.org/artifact/com.github.f4b6a3/ulid-creator) and [mvnrepository.com](https://mvnrepository.com/artifact/com.github.f4b6a3/ulid-creator).
@ -160,4 +160,3 @@ String ulid = UlidCreator.getGuidCreator()
.createUlid();
```
If you use the `GuidCreator` directly, you need do handle the `UlidCreatorException`, in the case that too many ULIDs are requested within the same millisecond.

View File

@ -108,10 +108,10 @@ public class UlidCreator {
}
private static class GuidCreatorLazyHolder {
static final GuidCreator INSTANCE = getGuidCreator().withoutOverrunException();
static final GuidCreator INSTANCE = getGuidCreator();
}
private static class FastGuidCreatorLazyHolder {
static final GuidCreator INSTANCE = getGuidCreator().withFastRandomGenerator().withoutOverrunException();
static final GuidCreator INSTANCE = getGuidCreator().withFastRandomGenerator();
}
}

View File

@ -51,7 +51,6 @@ public class GuidCreator {
protected long firstHigh;
protected long previousTimestamp;
protected boolean enableOverrunException = true;
protected Random random;
@ -202,10 +201,7 @@ public class GuidCreator {
protected synchronized void increment() {
if ((++this.low == this.firstLow) && (++this.high == this.firstHigh)) {
this.reset();
// Too many requests
if (enableOverrunException) {
throw new UlidCreatorException(OVERRUN_MESSAGE);
}
throw new UlidCreatorException(OVERRUN_MESSAGE);
}
}
@ -261,20 +257,6 @@ public class GuidCreator {
return (T) this;
}
/**
* Used to disable the overrun exception.
*
* An exception is thrown when too many requests are made within the same
* millisecond.
*
* @return {@link GuidCreator}
*/
@SuppressWarnings("unchecked")
public synchronized <T extends GuidCreator> T withoutOverrunException() {
this.enableOverrunException = false;
return (T) this;
}
private static class SecureRandomLazyHolder {
static final Random INSTANCE = new SecureRandom();
}