jodd.util.idgen
Class SimpleIdGenerator

java.lang.Object
  extended by jodd.util.idgen.SimpleIdGenerator

public class SimpleIdGenerator
extends java.lang.Object

Simple synchronized int ids sequence generator. It takes the positive sequence range (boundaries are included). Optionally, it supports cycling, when counter reaches the max value. Otherwise an exception is thrown.

See Also:
SimpleLongIdGenerator

Field Summary
protected  boolean cycle
           
protected  int initialValue
           
protected  int maxValue
           
protected  int value
           
 
Constructor Summary
SimpleIdGenerator()
          Creates a new default cycled id generator.
SimpleIdGenerator(int initialValue)
          Creates a new cycled id generator with specified initial value.
SimpleIdGenerator(int initialValue, int maxValue)
          Creates a new cycled id generator with specified range.
SimpleIdGenerator(int initialValue, int maxValue, boolean cycle)
          Creates a new id generator with specified range and cycling flag.
 
Method Summary
 int next()
          Returns the next value from the sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

value

protected volatile int value

initialValue

protected int initialValue

maxValue

protected int maxValue

cycle

protected boolean cycle
Constructor Detail

SimpleIdGenerator

public SimpleIdGenerator()
Creates a new default cycled id generator. Starts from 1 and counts up to max int value.


SimpleIdGenerator

public SimpleIdGenerator(int initialValue)
Creates a new cycled id generator with specified initial value.


SimpleIdGenerator

public SimpleIdGenerator(int initialValue,
                         int maxValue)
Creates a new cycled id generator with specified range.


SimpleIdGenerator

public SimpleIdGenerator(int initialValue,
                         int maxValue,
                         boolean cycle)
Creates a new id generator with specified range and cycling flag.

Method Detail

next

public int next()
Returns the next value from the sequence. Thread-safe.



Copyright ©2008 Jodd Team