KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > util > TransformingList


1 /*
2  * TransformingList.java
3  */

4 package polyglot.util;
5
6 import java.util.*;
7
8 /**
9  * This unmodifiable List supports performing an arbitrary transformation on
10  * the underlying list's elements. The transformation is applied on every
11  * access to the underlying members.
12  */

13 public class TransformingList extends java.util.AbstractList JavaDoc {
14     protected final Transformation trans;
15     protected final List underlying;
16     
17
18     public TransformingList(Collection underlying, Transformation trans) {
19     this(new ArrayList(underlying), trans);
20     }
21
22     public TransformingList(List underlying, Transformation trans) {
23       this.underlying = underlying;
24       this.trans = trans;
25     }
26
27     public int size() { return underlying.size(); }
28
29     public Object JavaDoc get(int index) {
30     return trans.transform(underlying.get(index));
31     }
32
33 }
34
35
Popular Tags