Class Database

java.lang.Object
  extended by Database

public class Database
extends Object

In-memory implementation of a database of rows and named columns, supporting basic creation and deletion actions, as well as file output in CSV format.

Author:
fhogenboom

Field Summary
private static org.slf4j.Logger _log
           
private  TreeMap<String,LinkedList<String>> columns
           
private  String name
           
 
Constructor Summary
Database(String name)
          Constructor.
 
Method Summary
 void addField(String name)
          Add column (field) to the Database.
 void addValue(String name, String value)
          Add row (value) to a column (field) of the Database.
 void flush()
          Flushes the Database by clearing all the columns.
 void init()
          Initializes the Database by creating the necessary data structures.
 void removeField(String name)
          Remove column (field) from the Database.
 void removeValue(String name, String value)
          Remove row (value) from a column (field) of the Database.
 void saveToFile(String path, String file, String ext)
          Save Database to a CSV formatted file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

private String name

columns

private TreeMap<String,LinkedList<String>> columns

_log

private static org.slf4j.Logger _log
Constructor Detail

Database

public Database(String name)
Constructor.

Parameters:
name - Name of the Database.
Method Detail

init

public void init()
Initializes the Database by creating the necessary data structures.


flush

public void flush()
Flushes the Database by clearing all the columns.


addField

public void addField(String name)
Add column (field) to the Database.

Parameters:
name - Name of field to be added.

removeField

public void removeField(String name)
Remove column (field) from the Database.

Parameters:
name - Name of field to be removed.

addValue

public void addValue(String name,
                     String value)
Add row (value) to a column (field) of the Database.

Parameters:
name - Name of field to be updated.
value - Value to be added.

removeValue

public void removeValue(String name,
                        String value)
Remove row (value) from a column (field) of the Database.

Parameters:
name - Name of field to be updated.
value - Value to be removed.

saveToFile

public void saveToFile(String path,
                       String file,
                       String ext)
Save Database to a CSV formatted file.

Parameters:
path - Output folder name (relative paths are allowed).
file - Output file name (without extension).
ext - Output file extension (preferably .csv).