import javax.swing.AbstractListModel;
-
/**
+ * @param <T>
+ * The type of the elements
* @author David Roden <droden@gmail.com>
*/
-public class SortedListModel extends AbstractListModel implements List {
+public class SortedListModel<T extends Comparable<T>> extends AbstractListModel implements List<T> {
- private List elements = new ArrayList();
+ /** The elements. */
+ private List<T> elements = new ArrayList<T>();
/**
* {@inheritDoc}
/**
* {@inheritDoc}
*/
- public void add(int index, Object element) {
+ public void add(int index, T element) {
elements.add(index, element);
Collections.sort(elements);
fireContentsChanged(this, 0, size());
/**
* {@inheritDoc}
*/
- public boolean add(Object o) {
+ public boolean add(T o) {
boolean result = elements.add(o);
Collections.sort(elements);
fireContentsChanged(this, 0, size());
/**
* {@inheritDoc}
*/
- public boolean addAll(Collection c) {
+ public boolean addAll(Collection<? extends T> c) {
boolean result = elements.addAll(c);
Collections.sort(elements);
fireContentsChanged(this, 0, size());
/**
* {@inheritDoc}
*/
- public boolean addAll(int index, Collection c) {
+ public boolean addAll(int index, Collection<? extends T> c) {
boolean result = elements.addAll(index, c);
Collections.sort(elements);
fireContentsChanged(this, 0, size());
/**
* {@inheritDoc}
*/
- public boolean containsAll(Collection c) {
+ public boolean containsAll(Collection<?> c) {
return elements.containsAll(c);
}
/**
* {@inheritDoc}
*/
- public Object get(int index) {
+ public T get(int index) {
return elements.get(index);
}
/**
* {@inheritDoc}
*/
- public Iterator iterator() {
+ public Iterator<T> iterator() {
return elements.iterator();
}
/**
* {@inheritDoc}
*/
- public ListIterator listIterator() {
+ public ListIterator<T> listIterator() {
return elements.listIterator();
}
/**
* {@inheritDoc}
*/
- public ListIterator listIterator(int index) {
+ public ListIterator<T> listIterator(int index) {
return elements.listIterator(index);
}
/**
* {@inheritDoc}
*/
- public Object remove(int index) {
+ public T remove(int index) {
fireContentsChanged(this, 0, size());
return elements.remove(index);
}
/**
* {@inheritDoc}
*/
- public boolean removeAll(Collection c) {
+ public boolean removeAll(Collection<?> c) {
fireContentsChanged(this, 0, size());
return elements.removeAll(c);
}
/**
* {@inheritDoc}
*/
- public boolean retainAll(Collection c) {
+ public boolean retainAll(Collection<?> c) {
fireContentsChanged(this, 0, size());
return elements.retainAll(c);
}
/**
* {@inheritDoc}
*/
- public Object set(int index, Object element) {
- Object result = elements.set(index, element);
+ public T set(int index, T element) {
+ T result = elements.set(index, element);
Collections.sort(elements);
fireContentsChanged(this, 0, size());
return result;
/**
* {@inheritDoc}
*/
- public List subList(int fromIndex, int toIndex) {
+ public List<T> subList(int fromIndex, int toIndex) {
return elements.subList(fromIndex, toIndex);
}
/**
* {@inheritDoc}
*/
- public Object[] toArray(Object[] a) {
+ public <U extends Object> U[] toArray(U[] a) {
return elements.toArray(a);
}