com.mooapi.server.util
Class SequenceIdProvider

java.lang.Object
  extended by com.mooapi.server.util.SequenceIdProvider
All Implemented Interfaces:
IdProvider<java.lang.Integer>

public class SequenceIdProvider
extends java.lang.Object
implements IdProvider<java.lang.Integer>

This class implements a sequence-based integer ID provider.

Author:
Steve Taylor

Constructor Summary
SequenceIdProvider()
          Initialize the sequence generator such that the first call to acquireId() will return 0;
SequenceIdProvider(int nextId)
          Initialize the sequence generator such that the first call to acquireId() will return nextId
 
Method Summary
 java.lang.Integer acquireId()
          Acquire a unique ID from this provider.
 java.lang.Integer getNextId()
          Get the next value that will be returned from a call to acquireId().
 void releaseId(java.lang.Integer id)
          Release an ID to this provider.
 void setNextId(int nextId)
          Set the next value to be returned by acquireId().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequenceIdProvider

public SequenceIdProvider()
Initialize the sequence generator such that the first call to acquireId() will return 0;


SequenceIdProvider

public SequenceIdProvider(int nextId)
Initialize the sequence generator such that the first call to acquireId() will return nextId

Parameters:
nextId - The value to return from the first call to acquireId().
Method Detail

getNextId

public java.lang.Integer getNextId()
Get the next value that will be returned from a call to acquireId(). This will not actually acquire an ID.

Returns:
The next ID to be returned by acquireId().

setNextId

public void setNextId(int nextId)
Set the next value to be returned by acquireId().

Parameters:
nextId - The next value to be returned by acquireId().

acquireId

public java.lang.Integer acquireId()
Acquire a unique ID from this provider. A unique ID is defined as an ID that is not found in the set of IDs currently on loan from this provider.

Specified by:
acquireId in interface IdProvider<java.lang.Integer>
Returns:
A unique ID.

releaseId

public void releaseId(java.lang.Integer id)

Release an ID to this provider.

This has no effect on this implementation as it is purely sequence driven.

Specified by:
releaseId in interface IdProvider<java.lang.Integer>
Parameters:
id - The ID to release.


Copyright © 2009. All Rights Reserved.