Code example for Queue

Methods: poll, remove, size

0
	public boolean add(int handle, T object)
	{ 
		if( !m_handles.containsKey( handle ) )
		{ 
			m_handles.put( handle, object );
			m_freeHandles.remove( handle );
			return true; 
		} 
		else 
		{ 
			return false; 
		} 
		 
	} 
	 
	/** 
	 * Returns the object corresponding to the given handle 
	 * but does not remove it. 
	 *  
	 * @param handle  
	 * @return The object corresponding to the handle, or null if 
	 *         no such handle is in the table. 
	 */ 
	public T get(int handle)
	{ 
		return m_handles.get( handle );
	} 
	 
	/** 
	 * Removes the given object corresponding to the given 
	 * handle from the table. 
	 *  
	 * @param handle 
	 */ 
	public void remove(int handle)
	{ 
		if( m_handles.containsKey( handle ) )
		{ 
			m_handles.remove( handle );
			m_freeHandles.add( handle );
		} 
	} 
	 
	/** 
	 * Returns the next available handle. 
	 *  
	 * @return The next available handle. 
	 */ 
	private int getNextHandle() 
	{ 
		if( m_freeHandles.size( ) > 0 )
		{ 
			return m_freeHandles.poll( );
		} 
		else 
		{ 
			return m_nextHandle++;
		}