net.sourceforge.jsh3modtool.gui.imagetable.cache
Class Queue

java.lang.Object
  extended by net.sourceforge.jsh3modtool.gui.imagetable.cache.Queue

public class Queue
extends java.lang.Object

Active queue that threads can listen on item addition and/or removal of items.

Author:
erma

Field Summary
protected  java.util.Vector listeners
           
protected  int numberOfAvailablePlaces
           
protected  java.util.Vector queueItems
           
 
Constructor Summary
Queue()
          Creates a new instance of Queue
Queue(int numberOfPlaces)
          Creates a new instance of Queue
 
Method Summary
 boolean add(QueueItem item)
          Adds the specified item to the queue.
protected  boolean add(QueueItem item, int index)
           
 boolean addFirst(QueueItem item)
          Adds the specified item to the end of the queue.
 boolean addLast(QueueItem item)
          Adds the specified item to the end of the queue.
 void addListener(QueueListener listener)
          Add a QueueListener to this object
protected  void fireAdditionEvent()
          Fire event that there is a new item in the queue
protected  void fireItemAdded(QueueItem item)
          Notify all listeners that an item has been added
protected  void fireItemRemoved(QueueItem item)
          Notify all listeners that an item has been removed
protected  void fireRemovalEvent()
          Fire event that there is one less item in the queue
 QueueItem getFirst()
          Returns the first item in the queue
 QueueItem getLast()
          Returns the last item in the queue
 boolean isEmpty()
          Returns if the queue is empty.
protected  QueueItem remove(int index)
          Remove the item at the specified index and return it.
 QueueItem remove(QueueItem item)
          Removes the queueitem from the queue
 void removeAll()
          Removes all items in the queue
 QueueItem removeFirst()
          Removes the first item and returns it.
 QueueItem removeLast()
          Removes the last item and returns it.
 void removeListener(QueueListener listener)
          Remove a QueueListener from this object
 int size()
          Returns the size of the queue
 boolean waitForEmptyQueue()
          Waits until the queue is empty for the specified timeout time This method behaves exactly as if it simply performs the call waitForEmptyQueue(0)
 boolean waitForEmptyQueue(long timeout)
          Waits until the queue is empty for the specified timeout time
 boolean waitForEmptySpace()
          Waits until there is an available place in the queue.
 boolean waitForEmptySpace(long timeout)
          Waits until there is an available place in the queue for the specified timeout time
 boolean waitForFirstObject()
          Waits until there is an object in the queue
 boolean waitForFirstObject(long timeout)
          Waits until there is an object in the queue for the specified timeout time
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

protected java.util.Vector listeners

numberOfAvailablePlaces

protected int numberOfAvailablePlaces

queueItems

protected java.util.Vector queueItems
Constructor Detail

Queue

public Queue()
Creates a new instance of Queue


Queue

public Queue(int numberOfPlaces)
Creates a new instance of Queue

Parameters:
numberOfPlaces - Maximum capacity
Method Detail

waitForFirstObject

public boolean waitForFirstObject()
Waits until there is an object in the queue

Returns:
false if this wait() (thread) was interrupted; true otherwise

waitForFirstObject

public boolean waitForFirstObject(long timeout)
Waits until there is an object in the queue for the specified timeout time

Parameters:
timeout - the maximum time to wait in milliseconds.
Returns:
false if this wait() (thread) was interrupted; true otherwise

waitForEmptySpace

public boolean waitForEmptySpace()
Waits until there is an available place in the queue. This method behaves exactly as if it simply performs the call waitForEmptySpace(0)

Returns:
false if this wait() (thread) was interrupted; true otherwise

waitForEmptySpace

public boolean waitForEmptySpace(long timeout)
Waits until there is an available place in the queue for the specified timeout time

Parameters:
timeout - the maximum time to wait in milliseconds.
Returns:
false if this wait() (thread) was interrupted; true otherwise

waitForEmptyQueue

public boolean waitForEmptyQueue()
Waits until the queue is empty for the specified timeout time This method behaves exactly as if it simply performs the call waitForEmptyQueue(0)

Returns:
false if this wait() (thread) was interrupted; true otherwise

waitForEmptyQueue

public boolean waitForEmptyQueue(long timeout)
Waits until the queue is empty for the specified timeout time

Parameters:
timeout - the maximum time to wait in milliseconds.
Returns:
false if this wait() (thread) was interrupted; true otherwise

fireAdditionEvent

protected void fireAdditionEvent()
Fire event that there is a new item in the queue


fireRemovalEvent

protected void fireRemovalEvent()
Fire event that there is one less item in the queue


add

public boolean add(QueueItem item)
Adds the specified item to the queue.

Parameters:
item - the item to add
Returns:
true if it was sucessfully added; false if there was no place.

addLast

public boolean addLast(QueueItem item)
Adds the specified item to the end of the queue.

Parameters:
item - the item to add
Returns:
true if it was sucessfully added; false if there was no place.

addFirst

public boolean addFirst(QueueItem item)
Adds the specified item to the end of the queue.

Parameters:
item - the item to add
Returns:
true if it was sucessfully added; false if there was no place.

add

protected boolean add(QueueItem item,
                      int index)

removeAll

public void removeAll()
Removes all items in the queue


remove

protected QueueItem remove(int index)
Remove the item at the specified index and return it.

Parameters:
index - the item index to remove
Returns:
the removed item

remove

public QueueItem remove(QueueItem item)
Removes the queueitem from the queue

Parameters:
item - the item to remove from the queue
Returns:
the removed item; null if there wasnt such item in the queue

removeFirst

public QueueItem removeFirst()
Removes the first item and returns it.

Returns:
the removed item; null if there was no items in the queue

removeLast

public QueueItem removeLast()
Removes the last item and returns it.

Returns:
the removed item; null if there was no items in the queue

getFirst

public QueueItem getFirst()
Returns the first item in the queue

Returns:
the first item; null if the queue was empty

getLast

public QueueItem getLast()
Returns the last item in the queue

Returns:
the last item; null if the queue was empty

size

public int size()
Returns the size of the queue

Returns:
the size of the queue

isEmpty

public boolean isEmpty()
Returns if the queue is empty.

Returns:
if the queue is empty.

addListener

public void addListener(QueueListener listener)
Add a QueueListener to this object

Parameters:
listener - the listener

removeListener

public void removeListener(QueueListener listener)
Remove a QueueListener from this object

Parameters:
listener - the listener

fireItemAdded

protected void fireItemAdded(QueueItem item)
Notify all listeners that an item has been added

Parameters:
item - the item

fireItemRemoved

protected void fireItemRemoved(QueueItem item)
Notify all listeners that an item has been removed

Parameters:
item - the item


Copyright © 2005 sourceforge.net. All Rights Reserved.