ch.javasoft.jbase.util
Class CachedTableWeakReference<E>

java.lang.Object
  extended by ch.javasoft.jbase.util.CachedTableWeakReference<E>
All Implemented Interfaces:
Table<E>

public class CachedTableWeakReference<E>
extends Object
implements Table<E>

The CachedTableWeakReference is a table which caches entries of an underlying tables using weak references. Weak references are possibly cleared by the garbage collector on the demand of memory.


Constructor Summary
CachedTableWeakReference(Table<E> baseTable)
           
CachedTableWeakReference(Table<E> baseTable, int paletteSize, boolean cacheOnWrite)
           
 
Method Summary
 int add(E entity)
          Adds a new entity to the table.
protected  void cacheEntity(int index, E entity, boolean force)
           
 void clearCache()
           
 void close(boolean erase)
          Closes this table.
 void flush()
          Flush ensures that all write operations are persisted.
 E get(int index)
          Returns the entity at the given position.
protected  ch.javasoft.jbase.util.CachedTableWeakReference.Palette getPalette(int index, boolean forceCreate)
           
 void remove(int index)
          Removes the entity at the given position from the table.
 void removeAll()
          Closes this table.
 void set(int index, E entity)
          Replaces the entity at the given position by the specified entity.
 int size()
          Returns the size of the table, i.e.
 void swap(int indexA, int indexB)
          Swaps the two entities specified by their index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedTableWeakReference

public CachedTableWeakReference(Table<E> baseTable)

CachedTableWeakReference

public CachedTableWeakReference(Table<E> baseTable,
                                int paletteSize,
                                boolean cacheOnWrite)
Method Detail

getPalette

protected ch.javasoft.jbase.util.CachedTableWeakReference.Palette getPalette(int index,
                                                                             boolean forceCreate)

cacheEntity

protected void cacheEntity(int index,
                           E entity,
                           boolean force)

add

public int add(E entity)
        throws IOException
Description copied from interface: Table
Adds a new entity to the table. The index of the added entity is at end of table, i.e. size-1 after adding the new entity.

Specified by:
add in interface Table<E>
Returns:
the position of the added entity, i.e. size-1
Throws:
IOException

removeAll

public void removeAll()
               throws IOException
Description copied from interface: Table
Closes this table. Pending write operations are flushed, and underlying files are closed. Subsequent access to the table is not allowed and causes exceptions. Multiple calls to this close method do not cause any exceptions.

Specified by:
removeAll in interface Table<E>
Throws:
IOException

close

public void close(boolean erase)
           throws IOException
Description copied from interface: Table
Closes this table. Pending write operations are flushed, and underlying files are closed. Subsequent access to the table is not allowed and causes exceptions. Multiple calls to this close method do not cause any exceptions.

Specified by:
close in interface Table<E>
Throws:
IOException

flush

public void flush()
           throws IOException
Description copied from interface: Table
Flush ensures that all write operations are persisted. Writing to files ore databases might involve caches (operating system caches or application caches). Calling this method enforces that all cached data is written to the underlying layer(s).

Specified by:
flush in interface Table<E>
Throws:
IOException

get

public E get(int index)
      throws IOException
Description copied from interface: Table
Returns the entity at the given position. Note that (row) indices might change if entities are added or removed.

Specified by:
get in interface Table<E>
Throws:
IOException

remove

public void remove(int index)
            throws IOException
Description copied from interface: Table
Removes the entity at the given position from the table. If this was the last entity, it is just removed. If it is another (not the last) row, the entity at the last row is moved to the specified position of the entity to remove.

Specified by:
remove in interface Table<E>
Throws:
IOException

set

public void set(int index,
                E entity)
         throws IOException
Description copied from interface: Table
Replaces the entity at the given position by the specified entity.

Specified by:
set in interface Table<E>
Throws:
IOException

swap

public void swap(int indexA,
                 int indexB)
          throws IOException
Description copied from interface: Table
Swaps the two entities specified by their index.

Specified by:
swap in interface Table<E>
Throws:
IOException

size

public int size()
         throws IOException
Description copied from interface: Table
Returns the size of the table, i.e. the number of rows or entities.

Specified by:
size in interface Table<E>
Throws:
IOException

clearCache

public void clearCache()