com.davisor.data.stream
Class EnumeratorDataStream

java.lang.Object
  extended bycom.davisor.data.VoidData
      extended bycom.davisor.data.stream.EnumeratorDataStream
All Implemented Interfaces:
Data, DataStream
Direct Known Subclasses:
EnumeratorTypeStream

public class EnumeratorDataStream
extends VoidData
implements DataStream

EnumeratorDataStream represents a data stream that uses a standard Java enumerator to implement a stream of elements. The elements may or may not be DataValues, and they may or may not be of a mutually equal type. The stream itself has a single type, however.

References to DataValue elements are returned as they are. Elements not of the expected type are converted, first to data objects of the proper type, and then the converted objects are returned. The original objects in the source are not changed.

Since:
JDK1.1
See Also:
next(), IteratorDataStream, Type

Field Summary
protected  DataValue M_data
          Reference to the next data element to be returned.
protected  java.util.Enumeration M_enumerator
          Underlying stream enumerator.
protected  long M_index
          Element id counter.
protected  java.lang.Object M_metaData
          Stream meta data (may be null).
protected  boolean M_next
          Flag that tells if there still is data in this stream.
 
Fields inherited from class com.davisor.data.VoidData
M_type
 
Fields inherited from interface com.davisor.data.stream.DataStream
INITIAL_INDEX
 
Constructor Summary
EnumeratorDataStream(java.util.Enumeration enumerator)
          Creates a data stream out of an enumerator.
EnumeratorDataStream(java.util.Enumeration enumerator, Type type)
          Creates a data stream out of an enumerator and the given type.
 
Method Summary
 boolean close()
          Dummy implementation.
 long getIndex()
          Retrieves the index number of the element returned by the latest next() call.
 boolean hasNext()
          Tests if the stream still contains data.
 DataValue next()
          Gets the next data value from the stream.
 
Methods inherited from class com.davisor.data.VoidData
equals, getDataValue, getType, hashCode, setType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.davisor.data.Data
getType
 

Field Detail

M_data

protected DataValue M_data
Reference to the next data element to be returned.


M_enumerator

protected java.util.Enumeration M_enumerator
Underlying stream enumerator.


M_index

protected long M_index
Element id counter.


M_next

protected boolean M_next
Flag that tells if there still is data in this stream.


M_metaData

protected java.lang.Object M_metaData
Stream meta data (may be null).

Constructor Detail

EnumeratorDataStream

public EnumeratorDataStream(java.util.Enumeration enumerator)
                     throws InvalidDataException
Creates a data stream out of an enumerator. The data stream type is set to AutoType.

Throws:
InvalidDataException - if the first element was not a DataValue, and no suitable type could be created for it
See Also:
EnumeratorDataStream(Enumeration,Type)

EnumeratorDataStream

public EnumeratorDataStream(java.util.Enumeration enumerator,
                            Type type)
                     throws InvalidDataException
Creates a data stream out of an enumerator and the given type.

Throws:
InvalidDataException - if the first element is not of the given type and cannot be converted to a data object of that type
See Also:
EnumeratorDataStream(Enumeration)
Method Detail

close

public boolean close()
Dummy implementation.

Specified by:
close in interface DataStream
Returns:
if stream closing was successfull or not
See Also:
DataStream.hasNext()

getIndex

public long getIndex()
Retrieves the index number of the element returned by the latest next() call. The index represents the position of the element within this stream. The stream index may or may not be equal to any other indexes the element itself thinks it posesses.

The index value is initially -1, indicating no element. After first next() call, index becomes 0, then 1, and so on. This functionality resembles java.sql.resultSet#getRow method functionality, but with the difference that the index counter starts from 0, not 1.

Specified by:
getIndex in interface DataStream
Returns:
element index

hasNext

public boolean hasNext()
Tests if the stream still contains data.

Specified by:
hasNext in interface DataStream
Returns:
true if it does.

next

public DataValue next()
               throws InvalidDataException
Gets the next data value from the stream.

Specified by:
next in interface DataStream
Throws:
InvalidDataException - if the stream content does not satisfy the stream type.


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.