Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

Queue Class Reference

List of all members.

Public Methods

 Queue ()
 Queue (int capacity)
void setCapacity (int capacity)
boolean isEmpty ()
boolean put (Object packet)
Object get ()
Object peek ()

Protected Attributes

int max_capacity
int number_of_packets

Private Attributes

Stack storage_buffer = new Stack()

Detailed Description

The Queue class implements a generic buffer required for packet storage. Implemented as stack (JDK 1.1.8. does not support linked lists).
Author(s):
Darko Vasić , Tomislav Petković , Zvonko Kostanjčar

Definition at line 20 of file Queue.java.


Constructor & Destructor Documentation

Queue::Queue ( ) [inline]
 

Default constructor. One packet buffer is created.

Definition at line 42 of file Queue.java.

00043     {
00044         max_capacity = 1;
00045         number_of_packets = 0;
00046     }

Queue::Queue ( int capacity ) [inline]
 

Normal constructor. Buffer of specified capacity is created.

Definition at line 52 of file Queue.java.

00053     {
00054         max_capacity = (capacity < 0)? 0: capacity;
00055         number_of_packets = 0;
00056     }


Member Function Documentation

Object Queue::get ( ) [inline]
 

Gets next element (packet) and removes it from the buffer. Generates exception if buffer is empty.

Returns:
Returns buffer element (packet).

Definition at line 110 of file Queue.java.

00111     {
00112         Object packet;
00113 
00114         if (number_of_packets > 0)
00115             {
00116                 number_of_packets = number_of_packets - 1;
00117                 packet = storage_buffer.pop();
00118                 return packet;
00119             }
00120         else
00121             {
00122                 throw new NoSuchElementException("No more packages.");
00123             }
00124     }

boolean Queue::isEmpty ( ) [inline]
 

Test for empty buffer. Returns true if empty.

Returns:
Buffer status.

Definition at line 78 of file Queue.java.

00079     {
00080         return storage_buffer.isEmpty();
00081     }

Object Queue::peek ( ) [inline]
 

Peeks at the first element.

Returns:
Returns first element.

Definition at line 132 of file Queue.java.

00133     {
00134         return storage_buffer.peek();
00135     }

boolean Queue::put ( Object packet ) [inline]
 

Puts one packet in the buffer. Returns true if succesful, and false if buffer is full.

Parameters:
packet   New element.
Returns:
Returns false for full buffer.

Definition at line 90 of file Queue.java.

00091     {
00092         if (number_of_packets <= max_capacity)
00093             {
00094                 storage_buffer.push(packet);
00095                 number_of_packets = number_of_packets + 1;
00096                 return true;
00097             }
00098         else
00099             {
00100                 return false;
00101             }
00102     }

void Queue::setCapacity ( int capacity ) [inline]
 

Sets buffer capacity to specified capacity. If buffer contains more elements then specified capacity, some elements are lost.

Parameters:
capacity   Buffer capacity.

Definition at line 64 of file Queue.java.

00065     {
00066         while (capacity < number_of_packets)
00067             {
00068                 this.get();
00069             }
00070         this.max_capacity = capacity;
00071     }


Member Data Documentation

int Queue::max_capacity [protected]
 

Maximal number of packets that can pass through the line in one simulation cycle.

Definition at line 27 of file Queue.java.

int Queue::number_of_packets [protected]
 

Number of packets currently stored in a buffer.

Definition at line 32 of file Queue.java.

Stack Queue::storage_buffer = new Stack() [private]
 

Packet storage.

Definition at line 37 of file Queue.java.


The documentation for this class was generated from the following file:
Generated at Thu Jun 28 03:04:24 2001 for Cyclops Network Simulator by doxygen1.2.7 written by Dimitri van Heesch, © 1997-2001