edu.ksu.cis.cooprobot.simulator.communication
Class PriorityQueue

java.lang.Object
  extended byedu.ksu.cis.cooprobot.simulator.communication.PriorityQueue

public class PriorityQueue
extends Object

This PriorityQueue class is used to keep Message in Queue in ascending order of receivedTime. Robots have their own priorityqueue. It keeps incoming message and wait for the owner call getMessage operation to retrive message from the queue.

This queue is implemented by LinkList. Message will be added to a queue in the right order.

Author:
Acharaporn Pattaravanichanon

Field Summary
private  LinkedList list
          A list of messages
 
Constructor Summary
PriorityQueue()
          PriorityQueue Constructor
 
Method Summary
 void add(Message msg)
          Adding message to a queue in order of receivedTime
 Message get(int index)
          Get specific message from the queue without deleting
 int getInsertIndex(long time)
          Helper method to get the right adding position.
 boolean isEmpty()
          Check if queue is empty
 Message remove(int index)
          Removing specific message from the queue
 int size()
          Get size of priority queue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

list

private LinkedList list
A list of messages

Constructor Detail

PriorityQueue

public PriorityQueue()
PriorityQueue Constructor

Method Detail

add

public void add(Message msg)
Adding message to a queue in order of receivedTime

Parameters:
msg - - message adding to a queue

getInsertIndex

public int getInsertIndex(long time)
Helper method to get the right adding position.

Parameters:
time - - receive time of new message adding to a queue

remove

public Message remove(int index)
Removing specific message from the queue

Parameters:
index - - the position of removing message
Returns:
a message

get

public Message get(int index)
Get specific message from the queue without deleting

Parameters:
index - - the position of message
Returns:
a message

size

public int size()
Get size of priority queue

Returns:
size of queue

isEmpty

public boolean isEmpty()
Check if queue is empty

Returns:
true if queue is empty, false otherwise