org.jdesktop.wonderland.client.utils
Class SmallIntegerAllocator

java.lang.Object
  extended by org.jdesktop.wonderland.client.utils.SmallIntegerAllocator

public class SmallIntegerAllocator
extends java.lang.Object

Allocates a small integer which is different from all the other small integers which have been allocated in this program run. The numbers start from 0. Numbers should be freed when they are no longer in use.

Author:
deronj

Field Summary
protected  boolean[] allocated
          An array which indicates which integers have been allocated
protected static int INCREMENT
          The amount to grow the list by when the list is exhausted
protected  int numAllocated
          The number of integers currently allocated
 
Constructor Summary
SmallIntegerAllocator()
          Construct a new instance of SmallIntegerAllocator, with no integers preallocated.
SmallIntegerAllocator(int numPreAlloc)
          Construct a new instance of SmallIntegerAllocator, with the given number of integers preallocated.
 
Method Summary
 int allocate()
          Allocate a small integer which is unique in this program run.
protected  int findInList()
          Find an unallocated integer and allocate it.
protected  int findInList(int startIdx)
          Find an unallocated integer and allocate it.
 void free(int i)
          Release an allocated integer
 int getNumAllocated()
          The number of integers currently allocated.
protected  int growList()
          All integers in our current array have been allocated and we must grow the array to contain new unallocated ones.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INCREMENT

protected static final int INCREMENT
The amount to grow the list by when the list is exhausted

See Also:
Constant Field Values

allocated

protected boolean[] allocated
An array which indicates which integers have been allocated


numAllocated

protected int numAllocated
The number of integers currently allocated

Constructor Detail

SmallIntegerAllocator

public SmallIntegerAllocator()
Construct a new instance of SmallIntegerAllocator, with no integers preallocated.


SmallIntegerAllocator

public SmallIntegerAllocator(int numPreAlloc)
Construct a new instance of SmallIntegerAllocator, with the given number of integers preallocated.

Method Detail

allocate

public int allocate()
Allocate a small integer which is unique in this program run.

Returns:
The integer.

free

public void free(int i)
Release an allocated integer

Parameters:
i - The value to release.

getNumAllocated

public int getNumAllocated()
The number of integers currently allocated.


findInList

protected int findInList()
Find an unallocated integer and allocate it. Start the search from 0.


findInList

protected int findInList(int startIdx)
Find an unallocated integer and allocate it. Start the search from the given index.


growList

protected int growList()
All integers in our current array have been allocated and we must grow the array to contain new unallocated ones.

Returns:
The length of the arary *BEFORE* this routine was called.


Open Wonderland - http://openwonderland.org