/** * Factory method to create a growth list. * * @param list the list to decorate, must not be null * @throws IllegalArgumentException if list is null */ public static List decorate(List list) { return new GrowthList(list); }
/** * Decorate the add method to perform the growth behaviour. * <p> * If the requested index is greater than the current size, the list will * grow to the new size. Indices between the old size and the requested * size will be filled with <code>null</code>. * <p> * If the index is less than the current size, the value will be added to * the underlying list directly. * If the index is less than zero, the underlying list is called, which * will probably throw an IndexOutOfBoundsException. * * @param index the index to add at * @param element the object to add at the specified index * @throws UnsupportedOperationException if the underlying list doesn't implement set * @throws ClassCastException if the underlying list rejects the element * @throws IllegalArgumentException if the underlying list rejects the element */ public void add(int index, Object element) { int size = getList().size(); if (index > size) { getList().addAll(Collections.nCopies(index - size, null)); } getList().add(index, element); }
public void testGrowthSet2() { Integer one = new Integer(1); GrowthList grower = new GrowthList(); assertEquals(0, grower.size()); grower.set(0, one); assertEquals(1, grower.size()); assertEquals(one, grower.get(0)); }
public void testGrowthAddAll() { Integer one = new Integer(1); Integer two = new Integer(2); Collection coll = new ArrayList(); coll.add(one); coll.add(two); GrowthList grower = new GrowthList(); assertEquals(0, grower.size()); grower.addAll(1, coll); assertEquals(3, grower.size()); assertEquals(null, grower.get(0)); assertEquals(one, grower.get(1)); assertEquals(two, grower.get(2)); }
/** * Factory method to create a growth list. * * @param list the list to decorate, must not be null * @throws IllegalArgumentException if list is null */ public static List decorate(List list) { return new GrowthList(list); }
/** * Decorate the set method to perform the growth behaviour. * <p> * If the requested index is greater than the current size, the list will * grow to the new size. Indices between the old size and the requested * size will be filled with <code>null</code>. * <p> * If the index is less than the current size, the value will be set onto * the underlying list directly. * If the index is less than zero, the underlying list is called, which * will probably throw an IndexOutOfBoundsException. * * @param index the index to set * @param element the object to set at the specified index * @return the object previously at that index * @throws UnsupportedOperationException if the underlying list doesn't implement set * @throws ClassCastException if the underlying list rejects the element * @throws IllegalArgumentException if the underlying list rejects the element */ public Object set(int index, Object element) { int size = getList().size(); if (index >= size) { getList().addAll(Collections.nCopies((index - size) + 1, null)); } return getList().set(index, element); }
public List makeEmptyList() { return new GrowthList(); }
/** * Decorate the addAll method to perform the growth behaviour. * <p> * If the requested index is greater than the current size, the list will * grow to the new size. Indices between the old size and the requested * size will be filled with <code>null</code>. * <p> * If the index is less than the current size, the values will be added to * the underlying list directly. * If the index is less than zero, the underlying list is called, which * will probably throw an IndexOutOfBoundsException. * * @param index the index to add at * @param coll the collection to add at the specified index * @return true if the list changed * @throws UnsupportedOperationException if the underlying list doesn't implement set * @throws ClassCastException if the underlying list rejects the element * @throws IllegalArgumentException if the underlying list rejects the element */ public boolean addAll(int index, Collection coll) { int size = getList().size(); boolean result = false; if (index > size) { getList().addAll(Collections.nCopies(index - size, null)); result = true; } return (getList().addAll(index, coll) | result); }
/** * Factory method to create a growth list. * * @param list the list to decorate, must not be null * @throws IllegalArgumentException if list is null */ public static List decorate(List list) { return new GrowthList(list); }
/** * Decorate the set method to perform the growth behaviour. * <p> * If the requested index is greater than the current size, the list will * grow to the new size. Indices between the old size and the requested * size will be filled with <code>null</code>. * <p> * If the index is less than the current size, the value will be set onto * the underlying list directly. * If the index is less than zero, the underlying list is called, which * will probably throw an IndexOutOfBoundsException. * * @param index the index to set * @param element the object to set at the specified index * @return the object previously at that index * @throws UnsupportedOperationException if the underlying list doesn't implement set * @throws ClassCastException if the underlying list rejects the element * @throws IllegalArgumentException if the underlying list rejects the element */ public Object set(int index, Object element) { int size = getList().size(); if (index >= size) { getList().addAll(Collections.nCopies((index - size) + 1, null)); } return getList().set(index, element); }
/** * Factory method to create a growth list. * * @param list the list to decorate, must not be null * @throws IllegalArgumentException if list is null */ public static List decorate(List list) { return new GrowthList(list); }
/** * Decorate the add method to perform the growth behaviour. * <p> * If the requested index is greater than the current size, the list will * grow to the new size. Indices between the old size and the requested * size will be filled with <code>null</code>. * <p> * If the index is less than the current size, the value will be added to * the underlying list directly. * If the index is less than zero, the underlying list is called, which * will probably throw an IndexOutOfBoundsException. * * @param index the index to add at * @param element the object to add at the specified index * @throws UnsupportedOperationException if the underlying list doesn't implement set * @throws ClassCastException if the underlying list rejects the element * @throws IllegalArgumentException if the underlying list rejects the element */ public void add(int index, Object element) { int size = getList().size(); if (index > size) { getList().addAll(Collections.nCopies(index - size, null)); } getList().add(index, element); }
/** * Factory method to create a growth list. * * @param list the list to decorate, must not be null * @throws IllegalArgumentException if list is null */ public static List decorate(List list) { return new GrowthList(list); }
/** * Decorate the addAll method to perform the growth behaviour. * <p> * If the requested index is greater than the current size, the list will * grow to the new size. Indices between the old size and the requested * size will be filled with <code>null</code>. * <p> * If the index is less than the current size, the values will be added to * the underlying list directly. * If the index is less than zero, the underlying list is called, which * will probably throw an IndexOutOfBoundsException. * * @param index the index to add at * @param coll the collection to add at the specified index * @return true if the list changed * @throws UnsupportedOperationException if the underlying list doesn't implement set * @throws ClassCastException if the underlying list rejects the element * @throws IllegalArgumentException if the underlying list rejects the element */ public boolean addAll(int index, Collection coll) { int size = getList().size(); boolean result = false; if (index > size) { getList().addAll(Collections.nCopies(index - size, null)); result = true; } return (getList().addAll(index, coll) | result); }
/** * Factory method to create a growth list. * * @param list the list to decorate, must not be null * @throws IllegalArgumentException if list is null */ public static List decorate(List list) { return new GrowthList(list); }
/** * Decorate the addAll method to perform the growth behaviour. * <p> * If the requested index is greater than the current size, the list will * grow to the new size. Indices between the old size and the requested * size will be filled with <code>null</code>. * <p> * If the index is less than the current size, the values will be added to * the underlying list directly. * If the index is less than zero, the underlying list is called, which * will probably throw an IndexOutOfBoundsException. * * @param index the index to add at * @param coll the collection to add at the specified index * @return true if the list changed * @throws UnsupportedOperationException if the underlying list doesn't implement set * @throws ClassCastException if the underlying list rejects the element * @throws IllegalArgumentException if the underlying list rejects the element */ public boolean addAll(int index, Collection coll) { int size = getList().size(); boolean result = false; if (index > size) { getList().addAll(Collections.nCopies(index - size, null)); result = true; } return (getList().addAll(index, coll) | result); }
/** * Factory method to create a growth list. * * @param list the list to decorate, must not be null * @throws IllegalArgumentException if list is null */ public static List decorate(List list) { return new GrowthList(list); }
/** * Decorate the add method to perform the growth behaviour. * <p> * If the requested index is greater than the current size, the list will * grow to the new size. Indices between the old size and the requested * size will be filled with <code>null</code>. * <p> * If the index is less than the current size, the value will be added to * the underlying list directly. * If the index is less than zero, the underlying list is called, which * will probably throw an IndexOutOfBoundsException. * * @param index the index to add at * @param element the object to add at the specified index * @throws UnsupportedOperationException if the underlying list doesn't implement set * @throws ClassCastException if the underlying list rejects the element * @throws IllegalArgumentException if the underlying list rejects the element */ public void add(int index, Object element) { int size = getList().size(); if (index > size) { getList().addAll(Collections.nCopies(index - size, null)); } getList().add(index, element); }