org.magnos.data
Class DataSet

java.lang.Object
  extended by org.magnos.data.AbstractData
      extended by org.magnos.data.DataSet
All Implemented Interfaces:
Data

public class DataSet
extends AbstractData

A set of data pieces.

Author:
Philip Diffenderfer

Constructor Summary
DataSet(DataSet set)
          Instantiates a new DataSet.
DataSet(int size)
          Instantiates a new DataSet.
 
Method Summary
 void add(Data... datas)
          Adds a piece of data to this set.
 Data copy()
          Creates a clone of this data.
static DataSet create(Data... data)
          Creates a DataSet with the given array of data.
<T extends Data>
T
get(int index)
          Gets the data element at the given index.
 int getSetSize()
          Returns the current or actual size of the DataSet.
protected  void onRead(int location, Store store)
          Reads this data from the given store at the given location.
protected  void onWrite(int location, Store store)
          Writes this data to the given store at the given location.
 
Methods inherited from class org.magnos.data.AbstractData
getActualLocation, getLocation, getParent, getSize, getStore, read, read, read, read, setLocation, setParent, setStore, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSet

public DataSet(int size)
Instantiates a new DataSet.

Parameters:
size - The fixed size of the DataSet in bytes.

DataSet

public DataSet(DataSet set)
Instantiates a new DataSet.

Parameters:
set - A DataSet to copy data from.
Method Detail

add

public void add(Data... datas)
Adds a piece of data to this set. If the set cannot hold the given data a RuntimeException will be thrown.

Parameters:
datas - The data to add to the set.
Throws:
java.lang.RuntimeException - The data was to large to add to this set.

get

public <T extends Data> T get(int index)
Gets the data element at the given index.

Type Parameters:
T - The element retrieved from the list is cast to this type.
Parameters:
index - The index of the data in this set.
Returns:
The data at the given index.
Throws:
java.lang.IndexOutOfBoundsException - No data exists at the given index.

getSetSize

public int getSetSize()
Returns the current or actual size of the DataSet.

Returns:
The current or actual size of the DataSet in bytes.

onRead

protected void onRead(int location,
                      Store store)
Reads this data from the given store at the given location.

Specified by:
onRead in class AbstractData
Parameters:
location - The offset in bytes from the beginning of the store to read from.
store - The store to read from.

onWrite

protected void onWrite(int location,
                       Store store)
Writes this data to the given store at the given location.

Specified by:
onWrite in class AbstractData
Parameters:
location - The offset in bytes from the beginning of the store to write to.
store - The store to write to.

copy

public Data copy()
Creates a clone of this data. The resulting data will be of the same type, have the same location, the same store, and have other similar attributes to this type.

Returns:
A clone of this data.

create

public static DataSet create(Data... data)
Creates a DataSet with the given array of data.

Parameters:
data - The data to add to the DataSet.
Returns:
The reference to a newly instantiated DataSet which contains the given data.