Added a clone() method and implement Cloneable.

Removed whitespace from the ends of lines.
cleanup_build_scripts
Paul Speed 9 years ago
parent 7b29c58fe0
commit c6aac78f42
  1. 20
      jme3-core/src/main/java/com/jme3/util/SafeArrayList.java

@ -68,7 +68,7 @@ import java.util.*;
* @version $Revision$ * @version $Revision$
* @author Paul Speed * @author Paul Speed
*/ */
public class SafeArrayList<E> implements List<E> { public class SafeArrayList<E> implements List<E>, Cloneable {
// Implementing List directly to avoid accidentally acquiring // Implementing List directly to avoid accidentally acquiring
// incorrect or non-optimal behavior from AbstractList. For // incorrect or non-optimal behavior from AbstractList. For
@ -97,6 +97,24 @@ public class SafeArrayList<E> implements List<E> {
addAll(c); addAll(c);
} }
public SafeArrayList<E> clone() {
try {
SafeArrayList<E> clone = (SafeArrayList<E>)super.clone();
// Clone whichever backing store is currently active
if( backingArray != null ) {
clone.backingArray = backingArray.clone();
}
if( buffer != null ) {
clone.buffer = (List<E>)((ArrayList<E>)buffer).clone();
}
return clone;
} catch( CloneNotSupportedException e ) {
throw new AssertionError();
}
}
protected final <T> T[] createArray(Class<T> type, int size) { protected final <T> T[] createArray(Class<T> type, int size) {
return (T[])java.lang.reflect.Array.newInstance(type, size); return (T[])java.lang.reflect.Array.newInstance(type, size);
} }

Loading…
Cancel
Save