implement the JmeCloneable interface for CompactArray
This commit is contained in:
parent
8fab216fd3
commit
8a3d628263
@ -31,6 +31,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.jme3.animation;
|
package com.jme3.animation;
|
||||||
|
|
||||||
|
import com.jme3.util.clone.Cloner;
|
||||||
|
import com.jme3.util.clone.JmeCloneable;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -40,7 +42,7 @@ import java.util.Map;
|
|||||||
* @author Lim, YongHoon
|
* @author Lim, YongHoon
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public abstract class CompactArray<T> {
|
public abstract class CompactArray<T> implements JmeCloneable {
|
||||||
|
|
||||||
private Map<T, Integer> indexPool = new HashMap<T, Integer>();
|
private Map<T, Integer> indexPool = new HashMap<T, Integer>();
|
||||||
protected int[] index;
|
protected int[] index;
|
||||||
@ -68,6 +70,7 @@ public abstract class CompactArray<T> {
|
|||||||
* They are serialized automatically when get() method is called.
|
* They are serialized automatically when get() method is called.
|
||||||
* @param objArray
|
* @param objArray
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void add(T... objArray) {
|
public void add(T... objArray) {
|
||||||
if (objArray == null || objArray.length == 0) {
|
if (objArray == null || objArray.length == 0) {
|
||||||
return;
|
return;
|
||||||
@ -190,6 +193,7 @@ public abstract class CompactArray<T> {
|
|||||||
* @param objArray
|
* @param objArray
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final int[] getIndex(T... objArray) {
|
public final int[] getIndex(T... objArray) {
|
||||||
int[] index = new int[objArray.length];
|
int[] index = new int[objArray.length];
|
||||||
for (int i = 0; i < index.length; i++) {
|
for (int i = 0; i < index.length; i++) {
|
||||||
@ -228,6 +232,7 @@ public abstract class CompactArray<T> {
|
|||||||
* decompress and return object array
|
* decompress and return object array
|
||||||
* @return decompress and return object array
|
* @return decompress and return object array
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final T[] toObjectArray() {
|
public final T[] toObjectArray() {
|
||||||
try {
|
try {
|
||||||
T[] compactArr = (T[]) Array.newInstance(getElementClass(), getSerializedSize() / getTupleSize());
|
T[] compactArr = (T[]) Array.newInstance(getElementClass(), getSerializedSize() / getTupleSize());
|
||||||
@ -247,6 +252,47 @@ public abstract class CompactArray<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* serialize object
|
||||||
* @param compactIndex compacted object index
|
* @param compactIndex compacted object index
|
||||||
|
Loading…
x
Reference in New Issue
Block a user