Please send questions to
st10@humboldt.edu .
public abstract class Cs132AbstractList implements Cs132List
{
// text thinks it is important that this be here...
public Cs132AbstractList()
{
// does nothing...?
}
// Purpose: returns true iff list has no elements
public boolean isEmpty()
{
return (this.size() == 0);
}
// NOTE that any concrete class of this must implement size() ---
// how to do THAT *is* implementation-dependent;
// Purpose: add given data newElement to beginning of list.
public void addFirst(Object newElement)
{
this.add(0, newElement);
}
// Purpose: add given data newElement to end of list.
public void addLast(Object newElement)
{
this.add( this.size(), newElement );
}
// NOTE that our add() is implementation-dependent, however;
// Purpose: IF list is not empty, return FIRST element in list.
// (we're deferring, for NOW, what to do if list IS empty.)
public Object getFirst()
{
return this.get(0);
}
// Purpose: IF the list is not empty, return the LAST element in list.
// (we're deferring, for NOW, what to do if the list IS empty.)
public Object getLast()
{
return this.get( this.size()-1 );
}
// NOTE that our get() is implementation-dependent, too
// NOTE that our remove() is implementation-dependent, too
// Purpose: empties the list
public void clear()
{
while (this.size() > 0)
{
Object ignoreMe = this.remove(0);
}
}
}