Class CompactArray<T>

java.lang.Object
com.jme3.animation.CompactArray<T>
Type Parameters:
T - the type of object (i.e. Vector3f)
All Implemented Interfaces:
JmeCloneable, Cloneable
Direct Known Subclasses:
CompactFloatArray, CompactQuaternionArray, CompactVector3Array

public abstract class CompactArray<T> extends Object implements JmeCloneable
Object is indexed and stored in primitive float[]
  • Field Details

    • indexPool

      protected Map<T,Integer> indexPool
    • index

      protected int[] index
    • array

      protected float[] array
  • Constructor Details

    • CompactArray

      public CompactArray()
      Creates a compact array
    • CompactArray

      public CompactArray(float[] compressedArray, int[] index)
      create array using serialized data
      Parameters:
      compressedArray - storage for float data
      index - storage for indices
  • Method Details

    • add

      public void add(T... objArray)
      Add objects. They are serialized automatically when get() method is called.
      Parameters:
      objArray - the objects to be added (may be null)
    • freeze

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

      protected void setInvalid(boolean invalid)
    • set

      public final void set(int index, T value)
      Parameters:
      index - zero-origin index of the element to be altered
      value - the desired 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:
      an element
    • getSerializedData

      public final float[] getSerializedData()
      return a float array of serialized data
      Returns:
      the pre-existing array
    • 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:
      an array
    • getIndex

      public final int[] getIndex(T... objArray)
      Return an array of indices for the given objects
      Parameters:
      objArray - the input objects
      Returns:
      a new array
    • getCompactIndex

      public int getCompactIndex(int objIndex)
      returns the corresponding index in the compact array
      Parameters:
      objIndex - the input index
      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
    • clone

      Create a deep clone of this array.
      Overrides:
      clone in class Object
      Returns:
      a new array
      Throws:
      CloneNotSupportedException - never
    • jmeClone

      public Object jmeClone()
      Create a shallow clone for the JME cloner.
      Specified by:
      jmeClone in interface JmeCloneable
      Returns:
      a new array
    • cloneFields

      public void cloneFields(Cloner cloner, Object original)
      Callback from Cloner to convert this shallow-cloned array into a deep-cloned one, using the specified cloner to resolve copied fields.
      Specified by:
      cloneFields in interface JmeCloneable
      Parameters:
      cloner - the cloner currently cloning this control (not null)
      original - the array from which this array was shallow-cloned (unused)
    • serialize

      protected abstract void serialize(int compactIndex, T store)
      serialize object
      Parameters:
      compactIndex - compacted object index
      store - the value to be serialized (not null, unaffected)
    • deserialize

      protected abstract T deserialize(int compactIndex, T store)
      deserialize object
      Parameters:
      compactIndex - compacted object index
      store - storage for the result
      Returns:
      the deserialized value
    • getTupleSize

      protected abstract int getTupleSize()
      serialized size of one object element
      Returns:
      the number of primitive components (floats) per object
    • getElementClass

      protected abstract Class<T> getElementClass()