Public Methods | |
LineEnd (Line line) | |
LineEnd (Line line, int capacity) | |
void | setCapacity (int capacity) |
boolean | isEmpty () |
boolean | receive (Object packet) |
Object | get () |
Object | peek () |
Object | elementAt (int i) |
int | size () |
void | delete () |
Protected Attributes | |
int | max_capacity |
int | number_of_packets |
Stack | storage_buffer = new Stack() |
Line | line |
Definition at line 21 of file LineEnd.java.
|
Default constructor. One packet buffer is created. Definition at line 42 of file LineEnd.java. 00043 { 00044 this.line = line; 00045 max_capacity = 1; 00046 number_of_packets = 0; 00047 } |
|
Normal constructor. Buffer of specified capacity is created. Definition at line 53 of file LineEnd.java. 00054 { 00055 this.line = line; 00056 max_capacity = capacity; 00057 number_of_packets = 0; 00058 } |
|
Deletes line. Definition at line 173 of file LineEnd.java. Referenced by Node::delete().
00174 { 00175 line.delete(); 00176 } |
|
Gets element by index.
Definition at line 155 of file LineEnd.java. Referenced by Line::paint().
00156 { 00157 return storage_buffer.elementAt(i); 00158 } |
|
Gets next element (packet) and removes it from the buffer. Generates exception if buffer is empty.
Definition at line 124 of file LineEnd.java. Referenced by Line::transmitAll().
00125 { 00126 Object packet; 00127 00128 if (number_of_packets > 0) 00129 { 00130 number_of_packets = number_of_packets - 1; 00131 packet = storage_buffer.pop(); 00132 return packet; 00133 } 00134 else 00135 { 00136 throw new NoSuchElementException("No more packages."); 00137 } 00138 } |
|
Test for empty buffer. Returns true if empty.
Definition at line 91 of file LineEnd.java. Referenced by Line::transmitAll().
00092 { 00093 return storage_buffer.isEmpty(); 00094 } |
|
Peeks at the first element.
Definition at line 145 of file LineEnd.java. 00146 { 00147 return storage_buffer.peek(); 00148 } |
|
Puts one packet in the buffer. Returns true if succesful, and false if buffer is full.
Definition at line 104 of file LineEnd.java. Referenced by Node::transmitAll().
00105 { 00106 if (number_of_packets <= max_capacity) 00107 { 00108 storage_buffer.push(packet); 00109 number_of_packets = number_of_packets + 1; 00110 return true; 00111 } 00112 else 00113 { 00114 return false; 00115 } 00116 } |
|
Sets buffer capacity to specified capacity. If buffer contains more elements then specified capacity, some elements are lost.
Definition at line 66 of file LineEnd.java. Referenced by Line::Line(), Line::setCapacity(), Line::setLeftToRightCapacity(), and Line::setRightToLeftCapacity().
00067 { 00068 if (capacity > 0) 00069 { 00070 while (capacity < number_of_packets) 00071 { 00072 this.get(); 00073 } 00074 max_capacity = capacity; 00075 } 00076 else 00077 { 00078 while ( !storage_buffer.isEmpty() ) 00079 { 00080 this.get(); 00081 } 00082 max_capacity = capacity; 00083 } 00084 } |
|
Gets total number of elements.
Definition at line 165 of file LineEnd.java. Referenced by Line::paint().
00165 { 00166 return storage_buffer.size(); 00167 } |
|
Line reference. Definition at line 37 of file LineEnd.java. |
|
Maximal number of packets that can pass through the line in one simulation cycle. Definition at line 28 of file LineEnd.java. |
|
Number of packets currently stored in a buffer. Definition at line 31 of file LineEnd.java. |
|
Packet storage. Definition at line 34 of file LineEnd.java. |