net.sf.jabb.util.thread
Class RangedSequencer

java.lang.Object
  extended by net.sf.jabb.util.thread.Sequencer
      extended by net.sf.jabb.util.thread.RangedSequencer

public class RangedSequencer
extends Sequencer

It generates sequence of incremental numbers, within a range that can be specified, without repeating or missing of any number.
序列值生成器,保证不重复渐增,支持最大最小值的范围设定。

It is multi-thread safe, and has high performance.

它是线程安全的,而且性能高。

Author:
Zhengmao HU (James)

Field Summary
protected  long loopSpot
           
protected  long offset
           
protected  long range
           
 
Fields inherited from class net.sf.jabb.util.thread.Sequencer
currentValue
 
Constructor Summary
RangedSequencer()
          Constructs an instance with a range of [0, Long.MAX_VALUE-1] and 0 as the initial number.
创建一个实例,指定初始值和最小值都是0,最大值是Long.MAX_VALUE-1。
RangedSequencer(long init)
          Constructs an instance with a range of [0, Long.MAX_VALUE-1] and specified initial number.
创建一个实例,指定初始值。最小值是0,最大值是Long.MAX_VALU-1。
RangedSequencer(long min, long max)
          Constructs an instance, with specified range, and use the low boundary as initial number.
创建一个实例,指定最小、最大值,初始值就是最小值。
RangedSequencer(long min, long max, long init)
          Constructs an instance, with specified range and initial number.
创建一个实例,指定最小、最大、初始值。
 
Method Summary
 long next()
          Get the next number in sequence.
获得下一个序列值。
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

offset

protected long offset

range

protected long range

loopSpot

protected long loopSpot
Constructor Detail

RangedSequencer

public RangedSequencer(long min,
                       long max,
                       long init)
Constructs an instance, with specified range and initial number.
创建一个实例,指定最小、最大、初始值。

Parameters:
min - 最小值
low boundary of the range
max - 最大值
high boundary of the range
init - 初始值
the first number that will be returned by next()

RangedSequencer

public RangedSequencer(long min,
                       long max)
Constructs an instance, with specified range, and use the low boundary as initial number.
创建一个实例,指定最小、最大值,初始值就是最小值。

Parameters:
min - 最小值
low boundary of the range
max - 最大值
high boundary of the range

RangedSequencer

public RangedSequencer(long init)
Constructs an instance with a range of [0, Long.MAX_VALUE-1] and specified initial number.
创建一个实例,指定初始值。最小值是0,最大值是Long.MAX_VALU-1。

Parameters:
init - 初始值
the first number that will be returned by next()

RangedSequencer

public RangedSequencer()
Constructs an instance with a range of [0, Long.MAX_VALUE-1] and 0 as the initial number.
创建一个实例,指定初始值和最小值都是0,最大值是Long.MAX_VALUE-1。

Method Detail

next

public long next()
Get the next number in sequence.
获得下一个序列值。

Overrides:
next in class Sequencer
Returns:
the next number in sequence


Copyright © 2012. All Rights Reserved.