/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mypackage;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
/**
*
* @author Nuno
*/
public class TDACollection<T> implements Collection<T>, List<T> {
private Class type;
private T[] data;
public TDACollection(Class type) {
this.type = type;
data = (T[]) Array.newInstance(type, 0);
}
public int size() {
return data.length;
}
public boolean isEmpty() {
return data.length == 0;
}
public Object[] toArray() {
return data;
}
public <T> T[] toArray(T[] a) {
return (T[]) Arrays.copyOf(data, a.length);
}
public boolean add(T e) {
T[] newData = (T[]) Array.newInstance(type, data.length + 1);
System.arraycopy(data, 0, newData, 0, data.length + 1);
data = newData;
return true;
}
public T get(int index) {
return data[index];
}
public T set(int index, T element) {
return (data[index] = element);
}
public boolean contains(Object o) {
throw new UnsupportedOperationException("Not supported yet.");
}
public Iterator<T> iterator() {
throw new UnsupportedOperationException("Not supported yet.");
}
public void add(int index, T element) {
throw new UnsupportedOperationException("Not supported yet.");
}
public T remove(int index) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean remove(Object o) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean containsAll(Collection<?> c) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean addAll(Collection<? extends T> c) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void clear() {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean addAll(int index, Collection<? extends T> c) {
throw new UnsupportedOperationException("Not supported yet.");
}
public int indexOf(Object o) {
throw new UnsupportedOperationException("Not supported yet.");
}
public int lastIndexOf(Object o) {
throw new UnsupportedOperationException("Not supported yet.");
}
public ListIterator<T> listIterator() {
throw new UnsupportedOperationException("Not supported yet.");
}
public ListIterator<T> listIterator(int index) {
throw new UnsupportedOperationException("Not supported yet.");
}
public List<T> subList(int fromIndex, int toIndex) {
throw new UnsupportedOperationException("Not supported yet.");
}
}