Java Reference
In-Depth Information
LISTING 13-1 The class AList
import java.util.Arrays;
/**
A class that implements a list of objects by using an array.
The list is never full.
@author Frank M. Carrano
*/
public class AList<T> implements ListInterface<T>
{
private T[] list; // array of list entries
private int numberOfEntries;
private static final int DEFAULT_INITIAL_CAPACITY = 25;
public AList()
{
this (DEFAULT_INITIAL_CAPACITY); // call next constructor
} // end default constructor
public AList( int initialCapacity)
{
numberOfEntries = 0;
// the cast is safe because the new array contains null entries
@SuppressWarnings("unchecked")
T[] tempList = (T[]) new Object[initialCapacity];
list = tempList;
} // end constructor
public void add(T newEntry)
{
ensureCapacity();
list[numberOfEntries] = newEntry;
numberOfEntries++;
} // end add
public boolean add( int newPosition, T newEntry)
{ < Implementation deferred >
} // end add
public T remove( int givenPosition)
{ < Implementation deferred >
} // end remove
public void clear()
{ < Implementation deferred >
} // end clear
public boolean replace( int givenPosition, T newEntry)
Search WWH ::




Custom Search