public abstract class CopiableArray extends java.lang.Object implements Copiable
Copiable
interface. It constructs an array of Copiable
s , note that all
subclasses must implement the makeNew(int)
method. It provides
methods to manipulate elements of the array set(Copiable, int)
and
get(int)
. It also implements a copy(int, int)
method which
allows to copy an element from a specified position in the array into a new
specified position. Subclasses inherit the copy()
methodModifier | Constructor and Description |
---|---|
protected |
CopiableArray(int size)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
copy()
Implements the method as specified by
Copiable . |
void |
copy(int from,
int to)
|
Copiable |
get(int index)
Return the
Copiable at the specified position. |
int |
getSize()
Returns the number of elements in the array.
|
protected abstract CopiableArray |
makeNew(int size)
Creates a new array of the speficied size.
|
void |
set(Copiable element,
int index)
Replaces the element at the specified position with the specified
Copiable . |
protected CopiableArray(int size)
size
- The size of the array.java.lang.IllegalArgumentException
- If the size is not strictly positive,protected abstract CopiableArray makeNew(int size)
size
- The size of the array.public int getSize()
public void set(Copiable element, int index)
Copiable
.element
- Copiable to set.index
- The position in the array.java.lang.IllegalArgumentException
- If the index is not valid.public Copiable get(int index)
Copiable
at the specified position.index
- The position in the array.java.lang.IllegalArgumentException
- If the index is not valid.public void copy(int from, int to)
from
- The starting position.to
- The ending position.java.lang.IllegalArgumentException
- If the indexes are not valid.public java.lang.Object copy()
Copiable
.copy
in interface Copiable
Copiable.copy()