jclass
Class DynamicNumbers

java.lang.Object
  |
  +--jclass.DynamicNumbers

public class DynamicNumbers
extends java.lang.Object

A class able to dynamically allocate and dealocate unique numbers in a given range. Once allocated, a number must be freed in order to be allocable again.

Written: Radu Sion
Version: 0.14x
Source: DynamicNumbers.java

Visit Smart Software 


Constructor Summary
DynamicNumbers(int maxrange)
           
 
Method Summary
 void freeNumber(int nr)
          Deallocates a number.
 int getFreeNumber()
          Allocates a new unique number in the given range.
 int getRange()
          Returns the number that was passed as parameter to the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicNumbers

public DynamicNumbers(int maxrange)
Parameters:
maxrange - The range in which to allocate numbers. The numbers will be allocated in the range 1 to maxrange
Method Detail

getFreeNumber

public int getFreeNumber()
                  throws FullException
Allocates a new unique number in the given range.
Returns:
The allocated int
Throws:
FullException - When there are no more unallocated numbers available

freeNumber

public void freeNumber(int nr)
Deallocates a number. (no checkings are performed)
Parameters:
nr - The number to dealocate

getRange

public int getRange()
Returns the number that was passed as parameter to the constructor.
Returns:
See constructor (maxrange)