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() |
Definition at line 20 of file Queue.java.
|
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 } |
|
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 } |
|
Gets next element (packet) and removes it from the buffer. Generates exception if buffer is empty.
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 } |
|
Test for empty buffer. Returns true if empty.
Definition at line 78 of file Queue.java. 00079 { 00080 return storage_buffer.isEmpty(); 00081 } |
|
Peeks at the first element.
Definition at line 132 of file Queue.java. 00133 { 00134 return storage_buffer.peek(); 00135 } |
|
Puts one packet in the buffer. Returns true if succesful, and false if buffer is full.
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 } |
|
Sets buffer capacity to specified capacity. If buffer contains more elements then specified capacity, some elements are lost.
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 } |
|
Maximal number of packets that can pass through the line in one simulation cycle. Definition at line 27 of file Queue.java. |
|
Number of packets currently stored in a buffer. Definition at line 32 of file Queue.java. |
|
Packet storage. Definition at line 37 of file Queue.java. |