com.davisor.data.stream
Class LazyListDataBuffer

java.lang.Object
  extended bycom.davisor.data.VoidData
      extended bycom.davisor.data.stream.CollectionDataSource
          extended bycom.davisor.data.stream.ListDataBuffer
              extended bycom.davisor.data.stream.LazyListDataBuffer
All Implemented Interfaces:
Data, DataBuffer, DataSource

public class LazyListDataBuffer
extends ListDataBuffer

LazyListDataBuffer implements a delayed initialization list data buffer. In particular, the buffer will be filled with data copied from a given data source, but only when the buffer is actually accessed the first time with a call to any of the DataBuffer interface methods.

The initialization status of lazy list data buffers can be checked with notInitialized() method which will return true until the the buffer has been initialized. Please note that an notInitialized() call will not trigger data buffer initialization.

Since:
JDK1.4
See Also:
notInitialized()

Field Summary
 boolean DEBUG
          debug switch
protected  DataSource M_dataSource
          Data buffer data source.
 
Fields inherited from class com.davisor.data.stream.CollectionDataSource
M_collection
 
Fields inherited from class com.davisor.data.VoidData
M_type
 
Constructor Summary
LazyListDataBuffer(DataSource dataSource)
          Creates a new delayed initialization list data buffer.
 
Method Summary
 DataValue getData(int index)
          Gets the specific data element.
 int getSize()
          Gets the number of data in the buffer.
 DataStream getStream()
          Gets a new data stream from the data source.
 DataStream getStream(boolean reversed)
          Gets a new data stream from the data source.
 Type getType()
          Gets the type of this data object.
protected  void init()
          Delayed initializer.
 boolean notInitialized()
          Tests if this instance has not been initialized.
 java.lang.String toString(java.lang.String id, java.lang.String dataName)
          Gets XML representation for the asked channel.
 
Methods inherited from class com.davisor.data.stream.ListDataBuffer
getList
 
Methods inherited from class com.davisor.data.stream.CollectionDataSource
addAll, close, getCollection, setType, toString
 
Methods inherited from class com.davisor.data.VoidData
equals, getDataValue, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.davisor.data.stream.DataSource
close
 

Field Detail

DEBUG

public final boolean DEBUG
debug switch

See Also:
Constant Field Values

M_dataSource

protected DataSource M_dataSource
Data buffer data source.

Constructor Detail

LazyListDataBuffer

public LazyListDataBuffer(DataSource dataSource)
Creates a new delayed initialization list data buffer.

Method Detail

getType

public Type getType()
             throws InvalidDataException
Gets the type of this data object.

Specified by:
getType in interface Data
Overrides:
getType in class VoidData
Returns:
the type associated with this data object
Throws:
InvalidDataException

getStream

public DataStream getStream()
                     throws InvalidDataException
Gets a new data stream from the data source.

Specified by:
getStream in interface DataSource
Overrides:
getStream in class CollectionDataSource
Throws:
InvalidDataException
See Also:
IteratorDataStream.IteratorDataStream(Collection,Type)

toString

public java.lang.String toString(java.lang.String id,
                                 java.lang.String dataName)
Gets XML representation for the asked channel.

Specified by:
toString in interface DataSource
Overrides:
toString in class CollectionDataSource
Parameters:
id - channel id
dataName - channel dataName

getData

public DataValue getData(int index)
                  throws com.davisor.core.InvalidIndexException
Gets the specific data element.

If current data source has not yet been consulted, it will be, now.

Specified by:
getData in interface DataBuffer
Overrides:
getData in class ListDataBuffer
Parameters:
index - data element index
Throws:
com.davisor.core.InvalidIndexException - if no data is bound to given index
See Also:
notInitialized()

getSize

public int getSize()
Gets the number of data in the buffer.

If current data source has not yet been consulted, it will be, now. If initialization fails, buffer size remains zero.

Specified by:
getSize in interface DataBuffer
Overrides:
getSize in class ListDataBuffer
See Also:
notInitialized()

getStream

public DataStream getStream(boolean reversed)
                     throws InvalidDataException
Gets a new data stream from the data source.

If current data source has not yet been consulted, it will be, now.

Specified by:
getStream in interface DataBuffer
Overrides:
getStream in class ListDataBuffer
Parameters:
reversed - controls if stream reads buffer forwards or backwards
Throws:
InvalidDataException - if a new stream can not be created
See Also:
notInitialized()

init

protected void init()
             throws InvalidDataException
Delayed initializer. This method will set object list and type, and fill the list with elements copied from current data source. Once all data from the data source has been consumed, the original data source is discarded.

Throws:
InvalidDataException

notInitialized

public boolean notInitialized()
Tests if this instance has not been initialized.

Returns:
true if this instances has not been initialized yet


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