ch.javasoft.jbase
Interface Table<E>

All Known Implementing Classes:
CachedTableSoftReference, CachedTableWeakReference, ConcurrentTable, FixedWidthTable, MemoryTable, MultiplexedAppendTable, VariableWidthTable

public interface Table<E>

A Table stores entity objects, sometimes called row. Entities can be added, removed and accessed by index.

The underlying mechanism to store the entities can be persistent (e.g. in a file or database) or volatile (e.g. stored in memory only). Different strategies might be used, for instance, entities with predefined size might be stored in a more efficient way than variable size objects. It is also possible to use caches in front of persistent tables to improve performance.


Method Summary
 int add(E entity)
          Adds a new entity to the table.
 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.
 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.
 

Method Detail

size

int size()
         throws IOException
Returns the size of the table, i.e. the number of rows or entities.

Throws:
IOException

get

E get(int index)
      throws IOException
Returns the entity at the given position. Note that (row) indices might change if entities are added or removed.

Throws:
IOException

set

void set(int index,
         E entity)
         throws IOException
Replaces the entity at the given position by the specified entity.

Throws:
IOException

swap

void swap(int indexA,
          int indexB)
          throws IOException
Swaps the two entities specified by their index.

Throws:
IOException

add

int add(E entity)
        throws IOException
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.

Returns:
the position of the added entity, i.e. size-1
Throws:
IOException

remove

void remove(int index)
            throws IOException
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.

Throws:
IOException

removeAll

void removeAll()
               throws IOException
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.

Throws:
IOException

flush

void flush()
           throws IOException
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).

Throws:
IOException

close

void close(boolean erase)
           throws IOException
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.

Throws:
IOException