Skip to content

Commit a1d53a8

Browse files
committed
ListModel<E>
1 parent a7ea315 commit a1d53a8

File tree

7 files changed

+29
-30
lines changed

7 files changed

+29
-30
lines changed
-112 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/javax/swing/AbstractListModel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
*
5050
* @author Hans Muller
5151
*/
52-
public abstract class AbstractListModel implements ListModel
52+
public abstract class AbstractListModel<E> implements ListModel<E>
5353
{
5454
protected EventListenerList listenerList = new EventListenerList();
5555

@@ -96,7 +96,6 @@ public ListDataListener[] getListDataListeners() {
9696
ListDataListener.class);
9797
}
9898

99-
10099
/**
101100
* <code>AbstractListModel</code> subclasses must call this method
102101
* <b>after</b>

sources/net.sf.j2s.java.core/src/javax/swing/ComboBoxModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* @author Arnaud Weber
4040
*/
41-
public interface ComboBoxModel extends ListModel {
41+
public interface ComboBoxModel<E> extends ListModel<E> {
4242

4343
/**
4444
* Set the selected item. The implementation of this method should notify

sources/net.sf.j2s.java.core/src/javax/swing/DefaultComboBoxModel.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
*/
3838

3939
@SuppressWarnings({"rawtypes", "unchecked"})
40-
public class DefaultComboBoxModel extends AbstractListModel implements MutableComboBoxModel {
41-
Vector objects;
40+
public class DefaultComboBoxModel<E> extends AbstractListModel<E> implements MutableComboBoxModel<E> {
41+
Vector<E> objects;
4242
Object selectedObject;
4343

4444
/**
@@ -54,7 +54,7 @@ public DefaultComboBoxModel() {
5454
*
5555
* @param items an array of Object objects
5656
*/
57-
public DefaultComboBoxModel(final Object items[]) {
57+
public DefaultComboBoxModel(final E items[]) {
5858
objects = new Vector();
5959
objects.ensureCapacity( items.length );
6060

@@ -73,7 +73,7 @@ public DefaultComboBoxModel(final Object items[]) {
7373
*
7474
* @param v a Vector object ...
7575
*/
76-
public DefaultComboBoxModel(Vector<?> v) {
76+
public DefaultComboBoxModel(Vector<E> v) {
7777
objects = v;
7878

7979
if ( getSize() > 0 ) {
@@ -110,7 +110,7 @@ public int getSize() {
110110

111111
// implements javax.swing.ListModel
112112
@Override
113-
public Object getElementAt(int index) {
113+
public E getElementAt(int index) {
114114
if ( index >= 0 && index < objects.size() )
115115
return objects.elementAt(index);
116116
else
@@ -130,7 +130,7 @@ public int getIndexOf(Object anObject) {
130130

131131
// implements javax.swing.MutableComboBoxModel
132132
@Override
133-
public void addElement(Object anObject) {
133+
public void addElement(E anObject) {
134134
objects.addElement(anObject);
135135
fireIntervalAdded(this,objects.size()-1, objects.size()-1);
136136
if ( objects.size() == 1 && selectedObject == null && anObject != null ) {
@@ -140,7 +140,7 @@ public void addElement(Object anObject) {
140140

141141
// implements javax.swing.MutableComboBoxModel
142142
@Override
143-
public void insertElementAt(Object anObject,int index) {
143+
public void insertElementAt(E anObject,int index) {
144144
objects.insertElementAt(anObject,index);
145145
fireIntervalAdded(this, index, index);
146146
}

sources/net.sf.j2s.java.core/src/javax/swing/DefaultListModel.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
* @author Hans Muller
5353
*/
5454
@SuppressWarnings({"rawtypes", "unchecked"})
55-
public class DefaultListModel extends AbstractListModel
55+
public class DefaultListModel<E> extends AbstractListModel<E>
5656
{
57-
private Vector delegate = new Vector();
57+
private Vector<E> delegate = new Vector<>();
5858

5959
/**
6060
* Returns the number of components in this list.
@@ -87,7 +87,7 @@ public int getSize() {
8787
* @see #get(int)
8888
*/
8989
@Override
90-
public Object getElementAt(int index) {
90+
public E getElementAt(int index) {
9191
return delegate.elementAt(index);
9292
}
9393

@@ -264,7 +264,7 @@ public int lastIndexOf(Object elem, int index) {
264264
* @see #get(int)
265265
* @see Vector#elementAt(int)
266266
*/
267-
public Object elementAt(int index) {
267+
public E elementAt(int index) {
268268
return delegate.elementAt(index);
269269
}
270270

@@ -275,7 +275,7 @@ public Object elementAt(int index) {
275275
* @return the first component of this list
276276
* @see Vector#firstElement()
277277
*/
278-
public Object firstElement() {
278+
public E firstElement() {
279279
return delegate.firstElement();
280280
}
281281

@@ -287,7 +287,7 @@ public Object firstElement() {
287287
* @return the last component of the list
288288
* @see Vector#lastElement()
289289
*/
290-
public Object lastElement() {
290+
public E lastElement() {
291291
return delegate.lastElement();
292292
}
293293

@@ -309,7 +309,7 @@ public Object lastElement() {
309309
* @see #set(int,Object)
310310
* @see Vector#setElementAt(Object,int)
311311
*/
312-
public void setElementAt(Object obj, int index) {
312+
public void setElementAt(E obj, int index) {
313313
delegate.setElementAt(obj, index);
314314
fireContentsChanged(this, index, index);
315315
}
@@ -352,7 +352,7 @@ public void removeElementAt(int index) {
352352
* @see #add(int,Object)
353353
* @see Vector#insertElementAt(Object,int)
354354
*/
355-
public void insertElementAt(Object obj, int index) {
355+
public void insertElementAt(E obj, int index) {
356356
delegate.insertElementAt(obj, index);
357357
fireIntervalAdded(this, index, index);
358358
}
@@ -363,7 +363,7 @@ public void insertElementAt(Object obj, int index) {
363363
* @param obj the component to be added
364364
* @see Vector#addElement(Object)
365365
*/
366-
public void addElement(Object obj) {
366+
public void addElement(E obj) {
367367
int index = delegate.size();
368368
delegate.addElement(obj);
369369
fireIntervalAdded(this, index, index);
@@ -446,7 +446,7 @@ public Object[] toArray() {
446446
*
447447
* @param index index of element to return
448448
*/
449-
public Object get(int index) {
449+
public E get(int index) {
450450
return delegate.elementAt(index);
451451
}
452452

@@ -462,8 +462,8 @@ public Object get(int index) {
462462
* @param element element to be stored at the specified position
463463
* @return the element previously at the specified position
464464
*/
465-
public Object set(int index, Object element) {
466-
Object rv = delegate.elementAt(index);
465+
public E set(int index, E element) {
466+
E rv = delegate.elementAt(index);
467467
delegate.setElementAt(element, index);
468468
fireContentsChanged(this, index, index);
469469
return rv;
@@ -479,7 +479,7 @@ public Object set(int index, Object element) {
479479
* @param index index at which the specified element is to be inserted
480480
* @param element element to be inserted
481481
*/
482-
public void add(int index, Object element) {
482+
public void add(int index, E element) {
483483
delegate.insertElementAt(element, index);
484484
fireIntervalAdded(this, index, index);
485485
}
@@ -494,8 +494,8 @@ public void add(int index, Object element) {
494494
*
495495
* @param index the index of the element to removed
496496
*/
497-
public Object remove(int index) {
498-
Object rv = delegate.elementAt(index);
497+
public E remove(int index) {
498+
E rv = delegate.elementAt(index);
499499
delegate.removeElementAt(index);
500500
fireIntervalRemoved(this, index, index);
501501
return rv;

sources/net.sf.j2s.java.core/src/javax/swing/ListModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* @author Hans Muller
4242
* @see JList
4343
*/
44-
public interface ListModel
44+
public interface ListModel<E>
4545
{
4646
/**
4747
* Returns the length of the list.
@@ -54,7 +54,7 @@ public interface ListModel
5454
* @param index the requested index
5555
* @return the value at <code>index</code>
5656
*/
57-
Object getElementAt(int index);
57+
E getElementAt(int index);
5858

5959
/**
6060
* Adds a listener to the list that's notified each time a change

sources/net.sf.j2s.java.core/src/javax/swing/MutableComboBoxModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @author Tom Santos
3434
*/
3535

36-
public interface MutableComboBoxModel extends ComboBoxModel {
36+
public interface MutableComboBoxModel<E> extends ComboBoxModel<E> {
3737

3838
/**
3939
* Adds an item at the end of the model. The implementation of this method
@@ -42,7 +42,7 @@ public interface MutableComboBoxModel extends ComboBoxModel {
4242
*
4343
* @param obj the <code>Object</code> to be added
4444
*/
45-
public void addElement( Object obj );
45+
public void addElement(E obj );
4646

4747
/**
4848
* Removes an item from the model. The implementation of this method should
@@ -61,7 +61,7 @@ public interface MutableComboBoxModel extends ComboBoxModel {
6161
* @param obj the <code>Object</code> to be added
6262
* @param index location to add the object
6363
*/
64-
public void insertElementAt( Object obj, int index );
64+
public void insertElementAt(E obj, int index );
6565

6666
/**
6767
* Removes an item at a specific index. The implementation of this method

0 commit comments

Comments
 (0)