verinec.netsim.util.tables
Class SlidingWindowBuffer

java.lang.Object
  extended by java.util.Dictionary
      extended by java.util.Hashtable
          extended by verinec.netsim.util.tables.SlidingWindowBuffer
All Implemented Interfaces:
Serializable, Cloneable, Map

public class SlidingWindowBuffer
extends Hashtable

A sliding window buffer

Version:
$Revision: 47 $
Author:
Dominik Jungo
See Also:
Serialized Form

Field Summary
private  int capacity
           
private  int lastAcked
           
 
Constructor Summary
SlidingWindowBuffer(int initialCapacity)
          Creates a new sliding window buffer.
 
Method Summary
 byte get()
          gets the first part of data (a byte) from the contiguous part of the window and removes it from the buffer
 byte get(int key)
          gets data (a byte) from the contiguous part of the window and removes it from the buffer
 int getAck()
          gets the address of the last part of the buffer that can be acknowledged
private  Integer getSmallestKey()
           
 int put(int key, byte data)
          writes a byte of data
private  void updateLastAcked()
           
 int windowsize()
          gets the remaining window size
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

capacity

private int capacity

lastAcked

private int lastAcked
Constructor Detail

SlidingWindowBuffer

public SlidingWindowBuffer(int initialCapacity)
Creates a new sliding window buffer.

Parameters:
initialCapacity - the window size (capacity of the buffer)
Method Detail

put

public int put(int key,
               byte data)
        throws NetSimException
writes a byte of data

Parameters:
key - a key
data - the data
Returns:
address of the last part of data in a contiguous part
Throws:
NetSimException - if there if no more spave left in buffer or the address is out of window range

getAck

public int getAck()
gets the address of the last part of the buffer that can be acknowledged

Returns:
the address of the last part of the buffer that can be acknowledged

updateLastAcked

private void updateLastAcked()

get

public byte get(int key)
         throws NetSimException
gets data (a byte) from the contiguous part of the window and removes it from the buffer

Parameters:
key - the address of the byte
Returns:
the requested byte
Throws:
NetSimException - if requested element not in buffer or separated by missing part

getSmallestKey

private Integer getSmallestKey()

get

public byte get()
         throws NetSimException
gets the first part of data (a byte) from the contiguous part of the window and removes it from the buffer

Returns:
the first byte from the contiguous part of the window
Throws:
NetSimException - if requested element not in buffer or separated by missing part

windowsize

public int windowsize()
gets the remaining window size

Returns:
the window size

Copyright © 2005 Verinec, DIUF