1 16 package org.apache.commons.collections.list; 17 18 import java.util.ArrayList ; 19 import java.util.Collection ; 20 import java.util.Collections ; 21 import java.util.List ; 22 23 57 public class GrowthList extends AbstractSerializableListDecorator { 58 59 60 private static final long serialVersionUID = -3620001881672L; 61 62 68 public static List decorate(List list) { 69 return new GrowthList(list); 70 } 71 72 76 public GrowthList() { 77 super(new ArrayList ()); 78 } 79 80 86 public GrowthList(int initialSize) { 87 super(new ArrayList (initialSize)); 88 } 89 90 96 protected GrowthList(List list) { 97 super(list); 98 } 99 100 119 public void add(int index, Object element) { 120 int size = getList().size(); 121 if (index > size) { 122 getList().addAll(Collections.nCopies(index - size, null)); 123 } 124 getList().add(index, element); 125 } 126 127 147 public boolean addAll(int index, Collection coll) { 148 int size = getList().size(); 149 boolean result = false; 150 if (index > size) { 151 getList().addAll(Collections.nCopies(index - size, null)); 152 result = true; 153 } 154 return (getList().addAll(index, coll) | result); 155 } 156 157 177 public Object set(int index, Object element) { 178 int size = getList().size(); 179 if (index >= size) { 180 getList().addAll(Collections.nCopies((index - size) + 1, null)); 181 } 182 return getList().set(index, element); 183 } 184 185 } 186 | Popular Tags |