package io.idcache;


import io.idcache.increaser.Increaser;
import io.idcache.increaser.integer.SequentialIntIncreaser;

import java.util.concurrent.atomic.AtomicInteger;



/**
 * Created by bong on 15. 4. 23.
 */
public class IntIdCache extends AbstractNumberIdCache<Integer> {
	private final AtomicInteger mCounter;



	public IntIdCache(Integer initValue, Integer minValue, Integer maxValue, Increaser<Integer> increaser) {
		super(initValue, minValue, maxValue, increaser);

		this.mCounter = new AtomicInteger(getInitial());
	}



	public IntIdCache(Integer initValue, Integer minValue, Increaser<Integer> increaser) {
		this(initValue, minValue, Integer.MAX_VALUE, increaser);
	}



	public IntIdCache(Integer initValue, Increaser<Integer> increaser) {
		this(initValue, 0, Integer.MAX_VALUE, increaser);
	}



	public IntIdCache(Increaser<Integer> increaser) {
		this(0, 0, Integer.MAX_VALUE, increaser);
	}



	public IntIdCache() {
		this(0, 0, Integer.MAX_VALUE, new SequentialIntIncreaser());
	}



	@Override public Integer set(Integer newValue) {
		mCounter.set(newValue);
		return newValue;
	}



	@Override public Integer current() {
		return mCounter.get();
	}



	@Override protected Integer onNextImpl() throws LimitationReachedException {
		final Integer nextFactor = getIncreaser().nextFactor().intValue();
		final Integer newValue = mCounter.addAndGet(nextFactor);

		if (newValue>getMaximum() || newValue<getMinimum())
			throw new LimitationReachedException(String.format("maximum: %d, current:%d, factor:%d",
					getMaximum(), (current()-nextFactor), nextFactor));

		return newValue;
	}
}

@@ -392,37 +392,46 @@
 alue, Increaser%3C
-Integ
+? extends Numb
 er%3E increaser) %7B
@@ -598,37 +598,46 @@
 alue, Increaser%3C
-Integ
+? extends Numb
 er%3E increaser) %7B
@@ -721,36 +721,35 @@
 IdCache(Integer 
-init
+max
 Value, Increaser
@@ -741,37 +741,46 @@
 alue, Increaser%3C
-Integ
+? extends Numb
 er%3E increaser) %7B
@@ -791,39 +791,22 @@
 his(
-initValue, 0, Integer.MAX_VALUE
+0, 0, maxValue
 , in
@@ -850,21 +850,30 @@
 creaser%3C
-Integ
+? extends Numb
 er%3E incr
@@ -1027,109 +1027,8 @@
 %0A%0A%0A%0A
-%09@Override public Integer set(Integer newValue) %7B%0A%09%09mCounter.set(newValue);%0A%09%09return newValue;%0A%09%7D%0A%0A%0A%0A
 %09@Ov
@@ -1198,16 +1198,26 @@
 Factor =
+ (Integer)
  getIncr
@@ -1240,19 +1240,8 @@
 or()
-.intValue()
 ;%0A%09%09
@@ -1524,10 +1524,98 @@
 lue;%0A%09%7D%0A
+%0A%0A%0A%09@Override protected void onSetImpl(Integer newValue) %7B%0A%09%09mCounter.set(newValue);%0A%09%7D%0A
 %7D%0A

Update class structure due to IdCache interface structure changed