import java.util.NoSuchElementException;
import java.lang.StringBuffer;
class AList<E> implements List<E> {
private E listArray[];
private static final int DEFAULT_SIZE = 10;
private int maxSize;
private int listSize;
private int curr;
@SuppressWarnings("unchecked")
AList(int size) {
maxSize = size;
listSize = curr = 0;
listArray = (E[])new Object[size];
}
AList() {
this(DEFAULT_SIZE);
}
public void clear() {
listSize = curr = 0;
}
public boolean insert(E it) {
if (listSize >= maxSize) {
return false;
}
for (int i=listSize; i>curr; i--) {
listArray[i] = listArray[i-1];
}
listArray[curr] = it;
listSize++;
return true;
}
public boolean append(E it) {
if (listSize >= maxSize) {
return false;
}
listArray[listSize++] = it;
return true;
}
public E remove() throws NoSuchElementException {
if ((curr<0) || (curr>=listSize)) {
throw new NoSuchElementException("remove() in AList has current of " + curr + " and size of "
+ listSize + " that is not a a valid element");
}
E it = listArray[curr];
for(int i=curr; i<listSize-1; i++) {
listArray[i] = listArray[i+1];
}
listSize--;
return it;
}
public void moveToStart() {
curr = 0;
}
public void moveToEnd() {
curr = listSize;
}
public void prev() {
if (curr != 0) {
curr--;
}
}
public void next() {
if (curr < listSize) {
curr++;
}
}
public int length() {
return listSize;
}
public int currPos() {
return curr;
}
public boolean moveToPos(int pos) {
if ((pos < 0) || (pos > listSize)) {
return false;
}
curr = pos;
return true;
}
public boolean isAtEnd() {
return curr == listSize;
}
public E getValue() throws NoSuchElementException {
if ((curr < 0) || (curr >= listSize)) {
throw new NoSuchElementException("getvalue() in AList has current of " + curr + " and size of "
+ listSize + " that is not a a valid element");
}
return listArray[curr];
}
public boolean isEmpty() {
return listSize == 0;
}
}