From c15821c17bd4a9fe0eb81b204468b44f8c9af9c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 15 Jan 2010 07:15:39 +0100 Subject: [PATCH] Use generics. --- src/de/todesbaum/util/swing/SortedListModel.java | 40 +++++++++++++----------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/de/todesbaum/util/swing/SortedListModel.java b/src/de/todesbaum/util/swing/SortedListModel.java index 21823be..3bdf6d9 100644 --- a/src/de/todesbaum/util/swing/SortedListModel.java +++ b/src/de/todesbaum/util/swing/SortedListModel.java @@ -28,13 +28,15 @@ import java.util.ListIterator; import javax.swing.AbstractListModel; - /** + * @param + * The type of the elements * @author David Roden <droden@gmail.com> */ -public class SortedListModel extends AbstractListModel implements List { +public class SortedListModel> extends AbstractListModel implements List { - private List elements = new ArrayList(); + /** The elements. */ + private List elements = new ArrayList(); /** * {@inheritDoc} @@ -53,7 +55,7 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@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()); @@ -62,7 +64,7 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@inheritDoc} */ - public boolean add(Object o) { + public boolean add(T o) { boolean result = elements.add(o); Collections.sort(elements); fireContentsChanged(this, 0, size()); @@ -72,7 +74,7 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@inheritDoc} */ - public boolean addAll(Collection c) { + public boolean addAll(Collection c) { boolean result = elements.addAll(c); Collections.sort(elements); fireContentsChanged(this, 0, size()); @@ -82,7 +84,7 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@inheritDoc} */ - public boolean addAll(int index, Collection c) { + public boolean addAll(int index, Collection c) { boolean result = elements.addAll(index, c); Collections.sort(elements); fireContentsChanged(this, 0, size()); @@ -107,7 +109,7 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@inheritDoc} */ - public boolean containsAll(Collection c) { + public boolean containsAll(Collection c) { return elements.containsAll(c); } @@ -121,7 +123,7 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@inheritDoc} */ - public Object get(int index) { + public T get(int index) { return elements.get(index); } @@ -149,7 +151,7 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@inheritDoc} */ - public Iterator iterator() { + public Iterator iterator() { return elements.iterator(); } @@ -163,21 +165,21 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@inheritDoc} */ - public ListIterator listIterator() { + public ListIterator listIterator() { return elements.listIterator(); } /** * {@inheritDoc} */ - public ListIterator listIterator(int index) { + public ListIterator 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); } @@ -193,7 +195,7 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@inheritDoc} */ - public boolean removeAll(Collection c) { + public boolean removeAll(Collection c) { fireContentsChanged(this, 0, size()); return elements.removeAll(c); } @@ -201,7 +203,7 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@inheritDoc} */ - public boolean retainAll(Collection c) { + public boolean retainAll(Collection c) { fireContentsChanged(this, 0, size()); return elements.retainAll(c); } @@ -209,8 +211,8 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@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; @@ -226,7 +228,7 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@inheritDoc} */ - public List subList(int fromIndex, int toIndex) { + public List subList(int fromIndex, int toIndex) { return elements.subList(fromIndex, toIndex); } @@ -240,7 +242,7 @@ public class SortedListModel extends AbstractListModel implements List { /** * {@inheritDoc} */ - public Object[] toArray(Object[] a) { + public U[] toArray(U[] a) { return elements.toArray(a); } -- 2.7.4