package io.idcache;


import io.idcache.increaser.Increaser;



/**
 * Created by bong on 15. 4. 23.
 */
public abstract class AbstractNumberIdCache<T> implements IdCache<T> {
	private final Increaser<T> mIncreaser;
	private final T mInitialValue;
	private final T mMinimumValue;
	private final T mMaximumValue;

	private LimitationPolicy mLimitPolicy = LimitationPolicy.ROLL_TO_MINIMUM_POLICY;



	public AbstractNumberIdCache(T initValue, T minValue, T maxValue, Increaser<T> increaser) {
		this.mInitialValue = initValue;
		this.mMinimumValue = minValue;
		this.mMaximumValue = maxValue;
		this.mIncreaser = increaser;
	}



	public T getInitial() {
		return this.mInitialValue;
	}



	public T getMinimum() {
		return this.mMinimumValue;
	}



	public T getMaximum() {
		return this.mMaximumValue;
	}



	@Override public abstract T current();



	@Override public final T next() {
		T value;

		try {
			value = onNextImpl();

		} catch (LimitationReachedException e) {
			switch (getLimitationPolicy()) {
				case INITIALIZE_POLICY:
					return set(getInitial());

				case ROLL_TO_MINIMUM_POLICY:
					return set(getMinimum());

				case ROLL_TO_MAXIMUM_POLICY:
					return set(getMaximum());

				case THROW_EXCEPTION_POLICY:
				default:
					throw new LimitationReachedException(e);
			}
		}

		return value;
	}



	protected abstract T onNextImpl() throws LimitationReachedException;



	public Increaser<T> getIncreaser() {
		return this.mIncreaser;
	}



	public void setLimitationPolicy(LimitationPolicy policy) {
		this.mLimitPolicy = policy;
	}



	public LimitationPolicy getLimitationPolicy() {
		return mLimitPolicy;
	}
}

@@ -54,16 +54,76 @@
 reaser;%0A
+import io.idcache.increaser.integer.SequentialIntIncreaser;%0A
 %0A%0A%0A/**%0A 
@@ -207,255 +207,60 @@
 he%3CT
-%3E implements IdCache%3CT%3E %7B%0A%09private final Increaser%3CT%3E mIncreaser;%0A%09private final T mInitialValue;%0A%09private final T mMinimumValue;%0A%09private final T mMaximumValue;%0A%0A%09private LimitationPolicy mLimitPolicy = LimitationPolicy.ROLL_TO_MINIMUM_POLICY;%0A%0A%0A
+ extends Number%3E extends AbstractGenericIdCache%3CT%3E %7B
 %0A%09pu
@@ -333,17 +333,17 @@
 creaser%3C
-T
+?
 %3E increa
@@ -355,1149 +355,108 @@
 %7B%0A%09%09
-this.mInitialValue = initValue;%0A%09%09this.mMinimumValue = minValue;%0A%09%09this.mMaximumValue = maxValue;%0A%09%09this.mIncreaser = increaser;%0A%09%7D%0A%0A%0A%0A%09public T getInitial() %7B%0A%09%09return this.mInitialValue;%0A%09%7D%0A%0A%0A%0A%09public T getMinimum() %7B%0A%09%09return this.mMinimumValue;%0A%09%7D%0A%0A%0A%0A%09public T getMaximum() %7B%0A%09%09return this.mMaximumValue;%0A%09%7D%0A%0A%0A%0A%09@Override public abstract T current();%0A%0A%0A%0A%09@Override public final T next() %7B%0A%09%09T value;%0A%0A%09%09try %7B%0A%09%09%09value = onNextImpl();%0A%0A%09%09%7D catch (LimitationReachedException e) %7B%0A%09%09%09switch (getLimitationPolicy()) %7B%0A%09%09%09%09case INITIALIZE_POLICY:%0A%09%09%09%09%09return set(getInitial());%0A%0A%09%09%09%09case ROLL_TO_MINIMUM_POLICY:%0A%09%09%09%09%09return set(getMinimum());%0A%0A%09%09%09%09case ROLL_TO_MAXIMUM_POLICY:%0A%09%09%09%09%09return set(getMaximum());%0A%0A%09%09%09%09case THROW_EXCEPTION_POLICY:%0A%09%09%09%09default:%0A%09%09%09%09%09throw new LimitationReachedException(e);%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09return value;%0A%09%7D%0A%0A%0A%0A%09protected abstract T onNextImpl() throws LimitationReachedException;%0A%0A%0A%0A%09public Increaser%3CT%3E getIncreaser() %7B%0A%09%09return this.mIncreaser;%0A%09%7D%0A%0A%0A%0A%09public void setLimitationPolicy(LimitationPolicy policy) %7B%0A%09%09this.mLimitPolicy = policy;%0A%09%7D%0A%0A%0A%0A%09public LimitationPolicy getLimitationPolicy() %7B%0A%09%09return mLimitPolicy
+super(initValue, minValue, maxValue, (increaser != null) ? increaser : new SequentialIntIncreaser())
 ;%0A%09%7D

Separate into two implementation * AbstractNumberIdCache * AbstractGenericIdCache