Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

LineEnd Class Reference

List of all members.

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

Detailed Description

Cyclops simulator The LineEnd class implements a generic line ending.
Author(s):
Darko Vasić , Tomislav Petković , Zvonko Kostanjčar
Version:
19-05-2001

Definition at line 21 of file LineEnd.java.


Constructor & Destructor Documentation

LineEnd::LineEnd ( Line line ) [inline]
 

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     }

LineEnd::LineEnd ( Line line,
int capacity ) [inline]
 

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     }


Member Function Documentation

void LineEnd::delete ( ) [inline]
 

Deletes line.

Definition at line 173 of file LineEnd.java.

Referenced by Node::delete().

00174     {
00175         line.delete();
00176     }

Object LineEnd::elementAt ( int i ) [inline]
 

Gets element by index.

Returns:
Returns element at index i;

Definition at line 155 of file LineEnd.java.

Referenced by Line::paint().

00156     {
00157         return storage_buffer.elementAt(i);
00158     }

Object LineEnd::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 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     }

boolean LineEnd::isEmpty ( ) [inline]
 

Test for empty buffer. Returns true if empty.

Returns:
Buffer status.

Definition at line 91 of file LineEnd.java.

Referenced by Line::transmitAll().

00092     {
00093         return storage_buffer.isEmpty();
00094     }

Object LineEnd::peek ( ) [inline]
 

Peeks at the first element.

Returns:
Returns first element.

Definition at line 145 of file LineEnd.java.

00146     {
00147         return storage_buffer.peek();
00148     }

boolean LineEnd::receive ( 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 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     }

void LineEnd::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 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     }

int LineEnd::size ( ) [inline]
 

Gets total number of elements.

Returns:
Returns number of elements.

Definition at line 165 of file LineEnd.java.

Referenced by Line::paint().

00165                       {
00166         return storage_buffer.size();
00167     }


Member Data Documentation

Line LineEnd::line [protected]
 

Line reference.

Definition at line 37 of file LineEnd.java.

int LineEnd::max_capacity [protected]
 

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

Definition at line 28 of file LineEnd.java.

int LineEnd::number_of_packets [protected]
 

Number of packets currently stored in a buffer.

Definition at line 31 of file LineEnd.java.

Stack LineEnd::storage_buffer = new Stack() [protected]
 

Packet storage.

Definition at line 34 of file LineEnd.java.


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