1 16 package org.apache.commons.collections.list; 17 18 import java.util.Collection ; 19 import java.util.List ; 20 import java.util.ListIterator ; 21 22 import org.apache.commons.collections.Transformer; 23 import org.apache.commons.collections.collection.TransformedCollection; 24 import org.apache.commons.collections.iterators.AbstractListIteratorDecorator; 25 26 41 public class TransformedList extends TransformedCollection implements List { 42 43 44 private static final long serialVersionUID = 1077193035000013141L; 45 46 56 public static List decorate(List list, Transformer transformer) { 57 return new TransformedList(list, transformer); 58 } 59 60 71 protected TransformedList(List list, Transformer transformer) { 72 super(list, transformer); 73 } 74 75 80 protected List getList() { 81 return (List ) collection; 82 } 83 84 public Object get(int index) { 86 return getList().get(index); 87 } 88 89 public int indexOf(Object object) { 90 return getList().indexOf(object); 91 } 92 93 public int lastIndexOf(Object object) { 94 return getList().lastIndexOf(object); 95 } 96 97 public Object remove(int index) { 98 return getList().remove(index); 99 } 100 101 public void add(int index, Object object) { 103 object = transform(object); 104 getList().add(index, object); 105 } 106 107 public boolean addAll(int index, Collection coll) { 108 coll = transform(coll); 109 return getList().addAll(index, coll); 110 } 111 112 public ListIterator listIterator() { 113 return listIterator(0); 114 } 115 116 public ListIterator listIterator(int i) { 117 return new TransformedListIterator(getList().listIterator(i)); 118 } 119 120 public Object set(int index, Object object) { 121 object = transform(object); 122 return getList().set(index, object); 123 } 124 125 public List subList(int fromIndex, int toIndex) { 126 List sub = getList().subList(fromIndex, toIndex); 127 return new TransformedList(sub, transformer); 128 } 129 130 133 protected class TransformedListIterator extends AbstractListIteratorDecorator { 134 135 protected TransformedListIterator(ListIterator iterator) { 136 super(iterator); 137 } 138 139 public void add(Object object) { 140 object = transform(object); 141 iterator.add(object); 142 } 143 144 public void set(Object object) { 145 object = transform(object); 146 iterator.set(object); 147 } 148 } 149 150 } 151 | Popular Tags |