de.jreality.scene.data
Class StorageModel

java.lang.Object
  extended by de.jreality.scene.data.StorageModel
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ByteBufferStorage

public abstract class StorageModel
extends Object
implements Serializable

Representation of the format of data encapsulated by a DataItem or DataList.

Author:
Holger
See Also:
Serialized Form

Field Summary
static StorageModel DOUBLE_ARRAY
           
static StorageModel DOUBLE_ARRAY_ARRAY
           
static StorageModel DOUBLE2_INLINED
           
static StorageModel DOUBLE3_ARRAY
           
static StorageModel DOUBLE3_INLINED
           
static StorageModel INT_ARRAY
           
static StorageModel INT_ARRAY_ARRAY
           
static StorageModel STRING_ARRAY
           
static StorageModel STRING_ARRAY_ARRAY
           
 
Method Summary
 StorageModel array()
          Like array(int) but without specifying an entry size.
 StorageModel array(int numPerEntry)
          Create a storage model that adds an additional dimension to an array specifying a constant length for each entry.
 void checkFormat(Object newData)
           
 DataList createReadOnly(Object v)
          Like createReadOnly(Object,int,int) assuming offset 0 and the entire array length.
 DataList createReadOnly(Object v, int start, int length)
          Create a data list using this data model.
 WritableDataList createWritableDataList(Object v)
           
 DoubleArray getAsDoubleArray(Object data, int index)
           
 IntArray getAsIntArray(Object data, int index)
           
 StringArray getAsStringArray(Object data, int index)
           
 StorageModel getComponentModel()
           
 int[] getDimensions()
          Get the dimension of the data.
 int[] getDimensions(DataList from)
          Like getDimensions() but with initialization of the first entry with the length of the specified list.
abstract  int getLength(Object data)
          Return the length of a data item in the format of this storage model.
 int getNumberOfDimensions()
           
 StorageModel inlined(int numPerEntry)
          Create a storage model that inlines an additional dimension in a linear array of length *numPerEntry.
 boolean isArray()
           
abstract  DataItem item(Object data, int i)
           
static StorageModel objectType(Class cl)
           
static StorageModel primitive(Class cl)
          Get the single-item storage model for a primitive data type.
 DoubleArray toDoubleArray(Object data)
           
 DoubleArrayArray toDoubleArrayArray(Object data)
           
 IntArray toIntArray(Object data)
           
 IntArrayArray toIntArrayArray(Object data)
           
 String toString()
          Return a string representation of the storage model, e.g.
 StringArray toStringArray(Object data)
           
 StringArrayArray toStringArrayArray(Object data)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INT_ARRAY

public static final StorageModel INT_ARRAY

DOUBLE_ARRAY

public static final StorageModel DOUBLE_ARRAY

INT_ARRAY_ARRAY

public static final StorageModel INT_ARRAY_ARRAY

DOUBLE_ARRAY_ARRAY

public static final StorageModel DOUBLE_ARRAY_ARRAY

DOUBLE2_INLINED

public static final StorageModel DOUBLE2_INLINED

DOUBLE3_INLINED

public static final StorageModel DOUBLE3_INLINED

DOUBLE3_ARRAY

public static final StorageModel DOUBLE3_ARRAY

STRING_ARRAY

public static final StorageModel STRING_ARRAY

STRING_ARRAY_ARRAY

public static final StorageModel STRING_ARRAY_ARRAY
Method Detail

primitive

public static StorageModel primitive(Class cl)
Get the single-item storage model for a primitive data type. The data type's class reference can be specified using class literal syntax type.class e.g. int.class or referring to the static constants of their counterpart reference type classes, e.g. Integer.TYPE.

Parameters:
cl - the primitive type's class representation
Returns:
the shared single-item storage model

objectType

public static StorageModel objectType(Class cl)

inlined

public StorageModel inlined(int numPerEntry)
Create a storage model that inlines an additional dimension in a linear array of length *numPerEntry. Can be applied several times, e.g. StorageModel.DOUBLE_ARRAY.inline(4).inline(4) creates a storage model for a list of 4x4 matrices still stored in a linear double[] array. Can also be used in combination with array(int).


array

public StorageModel array(int numPerEntry)
Create a storage model that adds an additional dimension to an array specifying a constant length for each entry. Can be applied several times, e.g. StorageModel.INT_ARRAY.inline(2).inline(3) creates a storage model for a list of int[2][3] entries. Can also used combined with inlined(int).

See Also:
array()

array

public StorageModel array()
Like array(int) but without specifying an entry size. Implies that entries might have different lengths. The resulting storage model will return -1 if queried for the general entry size.


createReadOnly

public final DataList createReadOnly(Object v)
Like createReadOnly(Object,int,int) assuming offset 0 and the entire array length.


createReadOnly

public DataList createReadOnly(Object v,
                               int start,
                               int length)
Create a data list using this data model. Certain storage models will return specialized data lists, e.g. DoubleArray or IntArray.

Parameters:
v - the object to wrap
start - start offset inside v
length - the number of items

createWritableDataList

public WritableDataList createWritableDataList(Object v)

toString

public String toString()
Return a string representation of the storage model, e.g. int[][3].

Overrides:
toString in class Object

getLength

public abstract int getLength(Object data)
Return the length of a data item in the format of this storage model.


getNumberOfDimensions

public int getNumberOfDimensions()

getDimensions

public int[] getDimensions()
Get the dimension of the data. The first entry is -1 for list/array types as the is the length of the list.

See Also:
getDimensions(DataList)

getDimensions

public int[] getDimensions(DataList from)
Like getDimensions() but with initialization of the first entry with the length of the specified list.


isArray

public boolean isArray()

getComponentModel

public StorageModel getComponentModel()

getAsIntArray

public IntArray getAsIntArray(Object data,
                              int index)

getAsDoubleArray

public DoubleArray getAsDoubleArray(Object data,
                                    int index)

getAsStringArray

public StringArray getAsStringArray(Object data,
                                    int index)

toIntArray

public IntArray toIntArray(Object data)

toIntArrayArray

public IntArrayArray toIntArrayArray(Object data)

toDoubleArray

public DoubleArray toDoubleArray(Object data)

toDoubleArrayArray

public DoubleArrayArray toDoubleArrayArray(Object data)

toStringArray

public StringArray toStringArray(Object data)

toStringArrayArray

public StringArrayArray toStringArrayArray(Object data)

checkFormat

public void checkFormat(Object newData)

item

public abstract DataItem item(Object data,
                              int i)