ch.javasoft.jbase
Class MemoryTable<E>

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

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

The MemoryTable stores the entities in memory in an array list.


Constructor Summary
MemoryTable()
          Constructor for an empty MemoryTable with storing entities in an ArrayList instance.
MemoryTable(List<E> list)
          Constructor for a MemoryTable based on the specified list instance.
 
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryTable

public MemoryTable()
Constructor for an empty MemoryTable with storing entities in an ArrayList instance.


MemoryTable

public MemoryTable(List<E> list)
Constructor for a MemoryTable based on the specified list instance. Changes to the list are also reflected by this memory table (and vice versa).

Method Detail

add

public int add(E entity)
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

close

public void close(boolean erase)
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>

flush

public void flush()
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>

get

public E get(int index)
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>

remove

public void remove(int index)
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>

set

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

Specified by:
set in interface Table<E>

swap

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

Specified by:
swap in interface Table<E>

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

size

public int size()
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>