diff --git a/jme3-core/src/main/java/com/jme3/animation/CompactArray.java b/jme3-core/src/main/java/com/jme3/animation/CompactArray.java index e32eff6c4..f251b44a2 100644 --- a/jme3-core/src/main/java/com/jme3/animation/CompactArray.java +++ b/jme3-core/src/main/java/com/jme3/animation/CompactArray.java @@ -31,6 +31,8 @@ */ package com.jme3.animation; +import com.jme3.util.clone.Cloner; +import com.jme3.util.clone.JmeCloneable; import java.lang.reflect.Array; import java.util.HashMap; import java.util.Map; @@ -40,7 +42,7 @@ import java.util.Map; * @author Lim, YongHoon * @param */ -public abstract class CompactArray { +public abstract class CompactArray implements JmeCloneable { private Map indexPool = new HashMap(); protected int[] index; @@ -68,6 +70,7 @@ public abstract class CompactArray { * They are serialized automatically when get() method is called. * @param objArray */ + @SuppressWarnings("unchecked") public void add(T... objArray) { if (objArray == null || objArray.length == 0) { return; @@ -190,6 +193,7 @@ public abstract class CompactArray { * @param objArray * @return */ + @SuppressWarnings("unchecked") public final int[] getIndex(T... objArray) { int[] index = new int[objArray.length]; for (int i = 0; i < index.length; i++) { @@ -228,6 +232,7 @@ public abstract class CompactArray { * decompress and return object array * @return decompress and return object array */ + @SuppressWarnings("unchecked") public final T[] toObjectArray() { try { T[] compactArr = (T[]) Array.newInstance(getElementClass(), getSerializedSize() / getTupleSize()); @@ -247,6 +252,47 @@ public abstract class CompactArray { } } + /** + * Create a deep clone of this array. + * + * @return a new array + * @throws java.lang.CloneNotSupportedException + */ + @Override + public Object clone() throws CloneNotSupportedException { + return Cloner.deepClone(this); + } + + /** + * Create a shallow clone for the JME cloner. + * + * @return a new array + */ + @Override + public Object jmeClone() { + try { + return super.clone(); + } catch (CloneNotSupportedException exception) { + throw new RuntimeException("Can't clone array", exception); + } + } + + /** + * Callback from {@link com.jme3.util.clone.Cloner} to convert this + * shallow-cloned array into a deep-cloned one, using the specified cloner + * to resolve copied fields. + * + * @param cloner the cloner currently cloning this control (not null) + * @param original the array from which this array was shallow-cloned + * (unused) + */ + @Override + public void cloneFields(Cloner cloner, Object original) { + indexPool = cloner.clone(indexPool); + index = cloner.clone(index); + array = cloner.clone(array); + } + /** * serialize object * @param compactIndex compacted object index