1 16 package org.apache.commons.collections.iterators; 17 18 import java.util.Iterator ; 19 20 import org.apache.commons.collections.Transformer; 21 22 31 public class TransformIterator implements Iterator { 32 33 34 private Iterator iterator; 35 36 private Transformer transformer; 37 38 44 public TransformIterator() { 45 super(); 46 } 47 48 54 public TransformIterator(Iterator iterator) { 55 super(); 56 this.iterator = iterator; 57 } 58 59 67 public TransformIterator(Iterator iterator, Transformer transformer) { 68 super(); 69 this.iterator = iterator; 70 this.transformer = transformer; 71 } 72 73 public boolean hasNext() { 75 return iterator.hasNext(); 76 } 77 78 86 public Object next() { 87 return transform(iterator.next()); 88 } 89 90 public void remove() { 91 iterator.remove(); 92 } 93 94 100 public Iterator getIterator() { 101 return iterator; 102 } 103 104 110 public void setIterator(Iterator iterator) { 111 this.iterator = iterator; 112 } 113 114 120 public Transformer getTransformer() { 121 return transformer; 122 } 123 124 130 public void setTransformer(Transformer transformer) { 131 this.transformer = transformer; 132 } 133 134 142 protected Object transform(Object source) { 143 if (transformer != null) { 144 return transformer.transform(source); 145 } 146 return source; 147 } 148 } 149 | Popular Tags |