- synchronized void reset() {
- int min = secureRandom.nextInt(ConcurrentTimeUuidState.MAX_CLOCKSEQUENCE - rangeSize);
- int max = min + rangeSize;
+ synchronized void reset(long range) {
+ // long min = secureRandom.nextInt(ConcurrentTimeUuidState.MAX_CLOCKSEQUENCE -
+ // rangeSize);
+ // long max = min + rangeSize;
+
+ long min, max;
+ if (range >= 0) {
+ if (range > MAX_CLOCKSEQUENCE)
+ throw new IllegalArgumentException("Range " + Long.toHexString(range) + " is too big");
+ long previousRange = this.range;
+ this.range = range & 0x3F00;
+ if (this.range != range) {
+ this.range = previousRange;
+ throw new IllegalArgumentException(
+ "Range is not properly formatted: " + range + " (0x" + Long.toHexString(range) + ")");
+ }
+
+ min = this.range;
+ max = min | 0xFF;
+ } else {// full range
+ this.range = range;
+ min = 0;
+ max = MAX_CLOCKSEQUENCE;
+ }
+ assert min == (int) min;
+ assert max == (int) max;
+
+ // TODO rather use assertions