com.davisor.data.stream
Class ListDataBuffer

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

public class ListDataBuffer
extends CollectionDataSource
implements DataBuffer

ListDataBuffer represents a data buffer that uses a standard Java list to implement a buffer of DataValue elements. The buffer also exposes the underlying list object to allow direct list content manipulation.

A data buffer has a data type that may be used to convert elements into one uniform type when data is inserted into the collection. However, arbitrary data may be also be placed directly into the collection. Data streams that read this buffer may later apply additional type conversions.

Since:
JDK1.1
See Also:
getList(), CollectionDataSource.getStream(), Type

Field Summary
 
Fields inherited from class com.davisor.data.stream.CollectionDataSource
M_collection
 
Fields inherited from class com.davisor.data.VoidData
M_type
 
Constructor Summary
ListDataBuffer()
          Default constructor that creates an empty collection with no type.
ListDataBuffer(DataStream stream)
          Creates a list data buffer from the content of the given stream.
ListDataBuffer(java.util.List list)
          Creates a list data buffer from the given list.
ListDataBuffer(java.lang.Object[] collection)
          Creates a list data buffer out of the given array.
ListDataBuffer(java.lang.Object[] collection, Type type)
          Creates a list data buffer out of the given array and type.
ListDataBuffer(Type type)
          Creates an empty Vector based list data buffer that is expected to later contain elements of the given type.
ListDataBuffer(Type type, DataStream stream)
          Creates a list data buffer from the content of the given stream, with stream elements type casted to the given type, if neccessary.
ListDataBuffer(Type type, java.util.List list)
          Creates a list data buffer from the given list and element type.
ListDataBuffer(Type type, java.lang.String buffer)
          Interpreters a string as a list of elements of the given type, separated by space characters.
ListDataBuffer(Type type, java.lang.String buffer, char separator)
          Interpreters a string as a list of elements of the given type, separated by given separator characters.
 
Method Summary
 DataValue getData(int index)
          Gets the specific data element.
 java.util.List getList()
          Gets the underlying list.
 int getSize()
          Gets the number of data in the buffer.
 DataStream getStream(boolean reversed)
          Gets a new data stream from the data source.
 
Methods inherited from class com.davisor.data.stream.CollectionDataSource
addAll, close, getCollection, getStream, setType, toString, toString
 
Methods inherited from class com.davisor.data.VoidData
equals, getDataValue, getType, 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, getStream, toString
 
Methods inherited from interface com.davisor.data.Data
getType
 

Constructor Detail

ListDataBuffer

public ListDataBuffer()
Default constructor that creates an empty collection with no type.


ListDataBuffer

public ListDataBuffer(Type type)
Creates an empty Vector based list data buffer that is expected to later contain elements of the given type.

Parameters:
type - type of buffer elements

ListDataBuffer

public ListDataBuffer(java.lang.Object[] collection)
               throws InvalidDataException
Creates a list data buffer out of the given array. The type of the data source is taken from the first array element.

Parameters:
collection - buffer elements
Throws:
InvalidDataException - if the type of the first element cannot be determined
See Also:
ListDataBuffer(List)

ListDataBuffer

public ListDataBuffer(java.lang.Object[] collection,
                      Type type)
Creates a list data buffer out of the given array and type.

Parameters:
collection - buffer elements
type - type of buffer elements
See Also:
ListDataBuffer(Type,List)

ListDataBuffer

public ListDataBuffer(java.util.List list)
               throws InvalidDataException
Creates a list data buffer from the given list. The list element content type is set to AutoType. This is probably not what you want.

Parameters:
list - buffer elements
Throws:
InvalidDataException - if the type of the first element cannot be determined
See Also:
ListDataBuffer(Type,List), CollectionDataSource.setType(com.davisor.data.Type)

ListDataBuffer

public ListDataBuffer(Type type,
                      java.util.List list)
Creates a list data buffer from the given list and element type. The list content is expected to be compatible with the given type.

Parameters:
type - type of buffer elements
list - buffer elements

ListDataBuffer

public ListDataBuffer(DataStream stream)
               throws InvalidDataException
Creates a list data buffer from the content of the given stream.

Parameters:
stream - input stream to be consumed
Throws:
InvalidDataException - if the stream contains invalid data

ListDataBuffer

public ListDataBuffer(Type type,
                      DataStream stream)
               throws InvalidDataException
Creates a list data buffer from the content of the given stream, with stream elements type casted to the given type, if neccessary.

Parameters:
type - type of buffer elements
stream - input stream to be consumed
Throws:
InvalidDataException - if the stream contains invalid data

ListDataBuffer

public ListDataBuffer(Type type,
                      java.lang.String buffer)
               throws InvalidDataException
Interpreters a string as a list of elements of the given type, separated by space characters.

Parameters:
type - type of buffer elements
buffer - input buffer to be read
Throws:
InvalidDataException - if buffer contains invalid data
See Also:
ListDataBuffer(Type,String,char)

ListDataBuffer

public ListDataBuffer(Type type,
                      java.lang.String buffer,
                      char separator)
               throws InvalidDataException
Interpreters a string as a list of elements of the given type, separated by given separator characters. If the separator is however a whitespace character, all whitespace character will be treated as separators.

Parameters:
type - type of buffer elements
buffer - input buffer to be read (may be null)
separator - element separator
Throws:
InvalidDataException - if buffer contains invalid data
Method Detail

getData

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

Specified by:
getData in interface DataBuffer
Parameters:
index - data element index
Throws:
com.davisor.core.InvalidIndexException - if no data is bound to given index

getSize

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

Specified by:
getSize in interface DataBuffer

getStream

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

Specified by:
getStream in interface DataBuffer
Parameters:
reversed - controls if stream reads buffer forwards or backwards
Throws:
InvalidDataException - if a new stream can not be created
See Also:
ListIteratorDataStream.ListIteratorDataStream(List,Type,boolean)

getList

public java.util.List getList()
Gets the underlying list. All changes to the returned list object will be reflected to the content of this data buffer.

See Also:
CollectionDataSource.getCollection()


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