Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

LineEnd.java

Go to the documentation of this file.
00001 /* Cyclops
00002  * FER - SPVP
00003  * Fakultet elektrotehnike i racunarstva (http://www.fer.hr/)
00004  * Unska 3, 10000 Zagreb, Hrvatska
00005  * (c) 2001 FER, Zagreb.
00006  */
00007 
00008 package hr.fer.zesoi.cyclops;
00009 
00010 import java.util.*;
00011 
00012 
00021 class LineEnd
00022 {
00023 
00028     protected int max_capacity;
00029 
00031     protected int number_of_packets;
00032 
00034     protected Stack storage_buffer = new Stack();
00035 
00037     protected Line line;
00038 
00042     public LineEnd (Line line)
00043     {
00044         this.line = line;
00045         max_capacity = 1;
00046         number_of_packets = 0;
00047     }
00048     /* LineEnd */
00049 
00053     public LineEnd (Line line, int capacity)
00054     {
00055         this.line = line;
00056         max_capacity = capacity;
00057         number_of_packets = 0;
00058     }
00059     /* LineEnd */
00060 
00066     public void setCapacity (int capacity)
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     }
00085     /* setCapacity */
00086 
00091     public boolean isEmpty ()
00092     {
00093         return storage_buffer.isEmpty();
00094     }
00095     /* isEmpty */
00096 
00104     public boolean receive (Object packet)
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     }
00117     /* receive */
00118 
00124     public Object get ()
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     }
00139     /* get */
00140 
00145     public Object peek ()
00146     {
00147         return storage_buffer.peek();
00148     }
00149     /* peek */
00150 
00155     public Object elementAt (int i)
00156     {
00157         return storage_buffer.elementAt(i);
00158     }
00159     /* elementAt */
00160 
00165     public int size() {
00166         return storage_buffer.size();
00167     }
00168     /* size */
00169 
00173     public void delete()
00174     {
00175         line.delete();
00176     }
00177     /* delete */
00178 
00179 }
00180 /* LineEnd */

Generated at Thu Jun 28 03:04:21 2001 for Cyclops Network Simulator by doxygen1.2.7 written by Dimitri van Heesch, © 1997-2001