com.jme3.animation
Class CompactArray<T>

java.lang.Object
  extended by com.jme3.animation.CompactArray<T>
Type Parameters:
T -
Direct Known Subclasses:
CompactQuaternionArray, CompactVector3Array

public abstract class CompactArray<T>
extends java.lang.Object

Object is indexed and stored in primitive float[]


Field Summary
protected  float[] array
           
protected  int[] index
           
 
Constructor Summary
CompactArray()
          Creates a compact array
CompactArray(float[] compressedArray, int[] index)
          create array using serialized data
 
Method Summary
 void add(T... objArray)
          Add objects.
protected abstract  T deserialize(int compactIndex, T store)
          deserialize object
protected  float[] ensureCapacity(float[] arr, int size)
          Ensure the capacity for the given array and the given size
 void freeze()
          release objects.
 T get(int index, T store)
          returns the object for the given index
 int getCompactIndex(int objIndex)
          returns the corresponding index in the compact array
 int getCompactObjectSize()
           
protected abstract  java.lang.Class<T> getElementClass()
           
 int[] getIndex(T... objArray)
          retrun an array of indices for the given objects
 float[] getSerializedData()
          return a float array of serialized data
protected  int getSerializedSize()
           
 int getTotalObjectSize()
           
protected abstract  int getTupleSize()
          serialized size of one object element
 void serialize()
          serialize this compact array
protected abstract  void serialize(int compactIndex, T store)
          serialize object
 void set(int index, T value)
           
 T[] toObjectArray()
          decompress and return object array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

index

protected int[] index

array

protected float[] array
Constructor Detail

CompactArray

public CompactArray()
Creates a compact array


CompactArray

public CompactArray(float[] compressedArray,
                    int[] index)
create array using serialized data

Parameters:
compressedArray -
index -
Method Detail

add

public void add(T... objArray)
Add objects. They are serialized automatically when get() method is called.

Parameters:
objArray -

freeze

public void freeze()
release objects. add() method call is not allowed anymore.


set

public final void set(int index,
                      T value)
Parameters:
index -
value -

get

public final T get(int index,
                   T store)
returns the object for the given index

Parameters:
index - the index
store - an object to store the result
Returns:

getSerializedData

public final float[] getSerializedData()
return a float array of serialized data

Returns:

serialize

public final void serialize()
serialize this compact array


getSerializedSize

protected final int getSerializedSize()
Returns:
compacted array's primitive size

ensureCapacity

protected float[] ensureCapacity(float[] arr,
                                 int size)
Ensure the capacity for the given array and the given size

Parameters:
arr - the array
size - the size
Returns:

getIndex

public final int[] getIndex(T... objArray)
retrun an array of indices for the given objects

Parameters:
objArray -
Returns:

getCompactIndex

public int getCompactIndex(int objIndex)
returns the corresponding index in the compact array

Parameters:
objIndex -
Returns:
object index in the compacted object array

getTotalObjectSize

public final int getTotalObjectSize()
Returns:
uncompressed object size

getCompactObjectSize

public final int getCompactObjectSize()
Returns:
compressed object size

toObjectArray

public final T[] toObjectArray()
decompress and return object array

Returns:
decompress and return object array

serialize

protected abstract void serialize(int compactIndex,
                                  T store)
serialize object

Parameters:
compactIndex - compacted object index
store -

deserialize

protected abstract T deserialize(int compactIndex,
                                 T store)
deserialize object

Parameters:
compactIndex - compacted object index
store -

getTupleSize

protected abstract int getTupleSize()
serialized size of one object element


getElementClass

protected abstract java.lang.Class<T> getElementClass()