You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2005/03/25 01:33:03 UTC
DO NOT REPLY [Bug 34171] New: -
[PATCH]: LazyList: implement set(int index, Object element)
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=34171>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=34171
Summary: [PATCH]: LazyList: implement set(int index, Object
element)
Product: Commons
Version: Nightly Builds
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Collections
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: plegato@nks.net
This patch enhances LazyList so that it will automatically grow larger when
set(int index, Object element) is called if the underlying List supports it
(set() is an optional method in the List interface.) Previously, LazyList only
grew larger when get(int index) was called.
--- LazyList.java.orig 2005-03-24 18:45:20.000000000 -0500
+++ LazyList.java 2005-03-24 19:04:03.000000000 -0500
@@ -29,6 +29,10 @@
* object from the factory. Thus this list is unsuitable for storing null
* objects.
* <p>
+ * If {@link #set(int)} is called with an index greater than the size of the list,
+ * the list will automatically grow in size to the specified index, with the
gap filled
+ * by null.
+ * <p>
* For instance:
*
* <pre>
@@ -54,6 +58,7 @@
* @author Stephen Colebourne
* @author Arron Bates
* @author Paul Jack
+ * @author Paul Legato
*/
public class LazyList extends AbstractSerializableListDecorator {
@@ -127,6 +132,35 @@
}
}
+ //-----------------------------------------------------------------------
+ /**
+ * Decorate the set method to perform the lazy behaviour.
+ * <p>
+ * If the requested index is greater than the current size, the list will
+ * grow to the new size.
+ * Indexes in-between the old size and the requested size are left with a
+ * null placeholder that is replaced with a factory object when requested.
+ *
+ * @param index the index to set
+ * @param element the object to set at index
+ * @return Returns the object previously at that index (or null, if there
was nothing at that index)
+ * @throws UnsupportedOperationException if the underlying list doesn't
implement set()
+ * @throws ClassCastException if the underlying list doesn't like the class
ofelement
+ * @throws IllegalArgumentException if the underlying list doesn't like
some aspect of the specified element
+ */
+ public Object set(int index, Object element)
+ {
+ int size = getList().size();
+ if (index >= size) {
+ // we have to grow the list
+ for (int i = size; i <= index; i++) {
+ getList().add(null);
+ }
+ }
+
+ // set object at specified index and return value previously at that
location
+ return getList().set(index, element);
+ }
public List subList(int fromIndex, int toIndex) {
List sub = getList().subList(fromIndex, toIndex);
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org