Sharkysoft home

lava.util
Class EnumerationLookaheadWindow

java.lang.Object
  |
  +--lava.util.EnumerationLookaheadWindow
All Implemented Interfaces:
java.util.Enumeration

public class EnumerationLookaheadWindow
extends java.lang.Object
implements java.util.Enumeration

An EnumerationLookaheadWindow provides the user with a "sliding window" into an Enumeration. This lets the user "peek ahead" into the Enumeration while searching for specific Objects. A window_size parameter, specified when the window is initialized, determines the extent the window can look ahead into the Enumeration.

When an EnumerationLookaheadWindow is initialized, the window is filled by consuming objects from the Enumeration. Objects that have entered the window can be accessed without removing them (otherwise, it wouldn't be much of a "lookahead" window, would it?). Additionally, Objects in the window can be removed in random order; it is not necessary to always consume the first Object in the window. When an Object is removed, other Objects in the window "slide over" to fill the hole. The hole at the end of the window, of course, is filled by reading another Object from the Enumeration.

Since:
1998
Version:
1998.11.05

Field Summary
protected  java.util.Enumeration en
           
protected  FifoQueue queue
           
protected  int window_size
           
 
Constructor Summary
EnumerationLookaheadWindow(java.util.Enumeration en, int window_size)
          Creates a new window into the given Enumeration, using the given window size.
 
Method Summary
 java.lang.Object elementAt(int pos)
          Returns the entry at the given position without removing it.
 int elementsWaiting()
          Returns the number of elements waiting in the window.
protected  void fill()
          Fills the window with new elements from the Enumeration.
protected  void fillOne()
          Adds one more element to the queue.
 boolean hasMoreElements()
          Indicates whether this enumeration has more elements.
 java.lang.Object nextElement()
          Returns the next element.
 java.lang.Object removeElementAt(int pos)
          Removes the entry at the given position in the window and returns it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

en

protected java.util.Enumeration en

queue

protected FifoQueue queue

window_size

protected final int window_size
Constructor Detail

EnumerationLookaheadWindow

public EnumerationLookaheadWindow(java.util.Enumeration en,
                                  int window_size)
Creates a new window into the given Enumeration, using the given window size.
Parameters:
en - the Enumeration
window_size - the size of the lookahead window
Method Detail

fill

protected final void fill()
Fills the window with new elements from the Enumeration.

fillOne

protected final void fillOne()
Adds one more element to the queue.

Details: fillOne consumes an Object from the Enumeration and places it at the end of the look-ahead window.

Since:
1998.11.05

removeElementAt

public java.lang.Object removeElementAt(int pos)
Removes the entry at the given position in the window and returns it. The position, pos, is considered "out of bounds" if (pos < 0 || pos >= size ()). If pos is out of bounds, a NoSuchElementException is thrown.
Parameters:
pos - the position
Returns:
the entry at the given position
Throws:
java.util.NoSuchElementException - if pos is invalid
Since:
1998

elementAt

public java.lang.Object elementAt(int pos)
Returns the entry at the given position without removing it. The position, pos, is considered "out of bounds" if (pos < 0 || pos >= size ()). If pos is out of bounds, a NoSuchElementException is thrown.
Parameters:
pos - the position
Returns:
the entry at the given position, or null if there is no such entry
Since:
1998

elementsWaiting

public int elementsWaiting()
Returns the number of elements waiting in the window. This is equal to the window size that was specified when this instance was created, unless the last element of the Enumeration is already waiting in the window.
Returns:
the number of elements waiting in the window
Since:
1998

nextElement

public java.lang.Object nextElement()
Returns the next element.

Details: DETAILS FORTHCOMING

Specified by:
nextElement in interface java.util.Enumeration
Parameters:
-  
Returns:
 
Throws:
-  
Since:
1998.11.05

hasMoreElements

public boolean hasMoreElements()
Indicates whether this enumeration has more elements.
Specified by:
hasMoreElements in interface java.util.Enumeration
Returns:
true iff there are more elements
Since:
1998

Sharkysoft home