org.simantics.databoard.file
Class RandomAccessBinaryList<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<T>
          extended by org.simantics.databoard.file.RandomAccessBinaryList<T>
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, java.util.RandomAccess, IFileList<T>
Direct Known Subclasses:
FileList

public class RandomAccessBinaryList<T>
extends java.util.AbstractList<T>
implements IFileList<T>, java.util.RandomAccess

BlobList is a RandomAccessBinary backend implementation of a List collection. add() and get() operations serialize and deserialize objects from binary format. Set, remove, insert and add operations flush() modifications to before return.

Each operation may throw RuntimeIOException, if there is IOException in the RandomAccessBinary

Entry position index is on open if the file has variable width data type (eg. String). The entire file is scanned through.

TODO lazy index. Append alone (add()) doesn't require scan.

Author:
Toni Kalajainen
See Also:
File based implementation

Constructor Summary
RandomAccessBinaryList(RandomAccessBinary blob, Binding binding, long startPos, SerializationFormat format)
          Create new random access list backed by a file
 
Method Summary
 void add(int index, T element)
           
 boolean addAll(java.util.Collection<? extends T> c)
           
 boolean addAll(int index, java.util.Collection<? extends T> c)
           
 void close()
          Flushes the caches and closes the file handle.
 T get(int index)
           
 Binding getBinding()
          Get class-data type binding
 java.io.File getFile()
          Get the mapped file
 boolean isOpen()
           
 T remove(int index)
           
 void removeRange(int fromIndex, int toIndex)
          Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.
 T set(int index, T element)
           
 void setAll(java.util.Collection<? extends T> c)
          Replace the whole content with the content of another collection
 int size()
           
 
Methods inherited from class java.util.AbstractList
add, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, clear, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, retainAll, subList, toArray, toArray
 

Constructor Detail

RandomAccessBinaryList

public RandomAccessBinaryList(RandomAccessBinary blob,
                              Binding binding,
                              long startPos,
                              SerializationFormat format)
                       throws java.io.IOException,
                              SerializerConstructionException,
                              SerializationException
Create new random access list backed by a file

Parameters:
blob - blob
binding -
startPos - The position of the first sample in file
format - serialization format
Throws:
java.io.IOException
SerializerConstructionException - could not create serializer, never thrown with BinarySerializationFormat
SerializationException - Error with the file, could not build entry index
Method Detail

size

public int size()
         throws RuntimeIOException
Specified by:
size in interface java.util.Collection<T>
Specified by:
size in interface java.util.List<T>
Specified by:
size in class java.util.AbstractCollection<T>
Throws:
RuntimeIOException

isOpen

public boolean isOpen()

close

public void close()
Flushes the caches and closes the file handle.

Specified by:
close in interface IFileList<T>

getBinding

public Binding getBinding()
Description copied from interface: IFileList
Get class-data type binding

Specified by:
getBinding in interface IFileList<T>
Returns:
the binding

get

public T get(int index)
      throws RuntimeIOException
Specified by:
get in interface java.util.List<T>
Specified by:
get in class java.util.AbstractList<T>
Throws:
RuntimeIOException

add

public void add(int index,
                T element)
         throws RuntimeIOException,
                RuntimeBindingException
Specified by:
add in interface java.util.List<T>
Overrides:
add in class java.util.AbstractList<T>
Throws:
RuntimeIOException
RuntimeBindingException

setAll

public void setAll(java.util.Collection<? extends T> c)
            throws RuntimeIOException
Replace the whole content with the content of another collection

Parameters:
c - collection
Throws:
RuntimeIOException

set

public T set(int index,
             T element)
      throws RuntimeIOException,
             RuntimeBindingException
Specified by:
set in interface java.util.List<T>
Overrides:
set in class java.util.AbstractList<T>
Throws:
RuntimeIOException
RuntimeBindingException

removeRange

public void removeRange(int fromIndex,
                        int toIndex)
                 throws RuntimeIOException
Description copied from interface: IFileList
Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the List by (toIndex - fromIndex) elements. (If toIndex==fromIndex, this operation has no effect.)

Specified by:
removeRange in interface IFileList<T>
Overrides:
removeRange in class java.util.AbstractList<T>
Parameters:
fromIndex - the index of the first element to removed.
toIndex - index after last element to be removed (exculsive).
Throws:
RuntimeIOException

remove

public T remove(int index)
         throws RuntimeIOException
Specified by:
remove in interface java.util.List<T>
Overrides:
remove in class java.util.AbstractList<T>
Throws:
RuntimeIOException

addAll

public boolean addAll(java.util.Collection<? extends T> c)
               throws RuntimeIOException
Specified by:
addAll in interface java.util.Collection<T>
Specified by:
addAll in interface java.util.List<T>
Overrides:
addAll in class java.util.AbstractCollection<T>
Throws:
RuntimeIOException

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends T> c)
               throws RuntimeIOException,
                      RuntimeBindingException
Specified by:
addAll in interface java.util.List<T>
Overrides:
addAll in class java.util.AbstractList<T>
Throws:
RuntimeIOException
RuntimeBindingException

getFile

public java.io.File getFile()
Description copied from interface: IFileList
Get the mapped file

Specified by:
getFile in interface IFileList<T>
Returns:
file