public class MessageQueue extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private int |
count |
private Message[] |
elements |
private int |
head |
private int |
tail |
Constructor and Description |
---|
MessageQueue(int capacity)
Constructs an empty message queue.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Message aMessage)
Append a message at tail.
|
boolean |
isFull()
Checks whether this queue is full
|
Message |
peek()
Get message at head.
|
Message |
remove()
Remove message at head.
|
int |
size()
Get the total number of messages in the queue.
|
public MessageQueue(int capacity)
capacity
- the maximum capacity of the queue
Precondition: capacity > 0
public Message remove()
Precondition: size() > 0
public void add(Message aMessage)
aMessage
- the message to be appended
Precondition: !isFull();
public int size()
public boolean isFull()