< prev index next >
src/java.desktop/share/classes/javax/swing/DefaultListModel.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -24,14 +24,13 @@
*/
package javax.swing;
import java.util.Vector;
+import java.util.Collection;
import java.util.Enumeration;
-import javax.swing.event.*;
-
/**
* This class loosely implements the <code>java.util.Vector</code>
* API, in that it implements the 1.1.x version of
* <code>java.util.Vector</code>, has no collection class support,
@@ -537,13 +536,46 @@
delegate.removeElementAt(i);
}
fireIntervalRemoved(this, fromIndex, toIndex);
}
- /*
- public void addAll(Collection c) {
+ /**
+ * Adds all of the elements present in the collection to the list.
+ *
+ * @param c the collection which contains the elements to add.
+ */
+ public void addAll(Collection<E> c) {
+ if (c.isEmpty()) {
+ return;
}
- public void addAll(int index, Collection c) {
+ int startIndex = getSize();
+
+ delegate.addAll(c);
+ fireIntervalAdded(this, startIndex, getSize() - 1);
}
+
+ /**
+ * Adds all of the elements present in the collection, starting
+ * from the index specified.
+ * <p>
+ * Throws as <code>IllegalArgumentException</code> if the
+ * index is invalid.
+ *
+ * @param index the index from which to start adding elements from.
+ * @param c the collection which contains the elements to add
+ * @exception IllegalArgumentException if <code>c</code> doesn't
+ * fall in the rang of the list.
*/
+ public void addAll(int index, Collection<E> c) {
+ if (index < 0 || index > getSize()) {
+ throw new IllegalArgumentException(
+ "index number must be >=0 and <= number of elements in the list.");
+ }
+ if(c.isEmpty()) {
+ return;
+ }
+
+ delegate.addAll(index, c);
+ fireIntervalAdded(this, index, index + c.size() - 1);
+ }
}
< prev index next >