1 4 package polyglot.util; 5 6 import java.util.*; 7 8 12 public class CachingTransformingList extends TransformingList { 13 ArrayList cache; 14 15 public CachingTransformingList(Collection underlying, 16 Transformation trans) 17 { 18 this(new ArrayList(underlying), trans); 19 } 20 21 public CachingTransformingList(List underlying, Transformation trans) { 22 super(underlying, trans); 23 cache = new ArrayList(Collections.nCopies(underlying.size(), null)); 24 } 25 26 public Object get(int index) { 27 Object o = cache.get(index); 28 if (o == null) { 29 o = trans.transform(underlying.get(index)); 30 cache.set(index, o); 31 } 32 return o; 33 } 34 } 35 | Popular Tags |