net.sourceforge.worldsaver.util
Class IDGenerator

java.lang.Object
  |
  +--net.sourceforge.worldsaver.util.IDGenerator

public class IDGenerator
extends java.lang.Object

This class guarantees to provide positive, unique long values for usage as IDs.

Version:
23 Dec 2000
Author:
Andreas Schmitz

Constructor Summary
IDGenerator()
          Creates a new empty generator.
IDGenerator(java.util.HashSet val)
          Creates a new generator with the already used values contained in the given HashSet.
 
Method Summary
 long getNextID()
          Returns the next ID.
 void remove(long id)
          Releases a value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IDGenerator

public IDGenerator()
Creates a new empty generator.

IDGenerator

public IDGenerator(java.util.HashSet val)
Creates a new generator with the already used values contained in the given HashSet. Caution: the HashSet may only contain Long objects!
Parameters:
val - the HashSet with the used values
Method Detail

getNextID

public long getNextID()
Returns the next ID. Returns 0 if no more IDs are available!
Returns:
the unique ID, always positive if valid

remove

public void remove(long id)
Releases a value. A value that is removed may be returned again when calling the getNextID method.
Parameters:
id - the value that is to be released