3535 * This is a lazy implementation of the FluentIterable interface. It evaluates all chained
3636 * operations when a terminating operation is applied.
3737 *
38- * @param <TYPE > the type of the objects the iteration is about
38+ * @param <E > the type of the objects the iteration is about
3939 */
40- public class LazyFluentIterable <TYPE > implements FluentIterable <TYPE > {
40+ public class LazyFluentIterable <E > implements FluentIterable <E > {
4141
42- private final Iterable <TYPE > iterable ;
42+ private final Iterable <E > iterable ;
4343
4444 /**
4545 * This constructor creates a new LazyFluentIterable. It wraps the given iterable.
4646 *
4747 * @param iterable the iterable this FluentIterable works on.
4848 */
49- protected LazyFluentIterable (Iterable <TYPE > iterable ) {
49+ protected LazyFluentIterable (Iterable <E > iterable ) {
5050 this .iterable = iterable ;
5151 }
5252
@@ -66,15 +66,15 @@ protected LazyFluentIterable() {
6666 * @return a new FluentIterable object that decorates the source iterable
6767 */
6868 @ Override
69- public FluentIterable <TYPE > filter (Predicate <? super TYPE > predicate ) {
70- return new LazyFluentIterable <TYPE >() {
69+ public FluentIterable <E > filter (Predicate <? super E > predicate ) {
70+ return new LazyFluentIterable <E >() {
7171 @ Override
72- public Iterator <TYPE > iterator () {
73- return new DecoratingIterator <TYPE >(iterable .iterator ()) {
72+ public Iterator <E > iterator () {
73+ return new DecoratingIterator <E >(iterable .iterator ()) {
7474 @ Override
75- public TYPE computeNext () {
75+ public E computeNext () {
7676 while (fromIterator .hasNext ()) {
77- TYPE candidate = fromIterator .next ();
77+ E candidate = fromIterator .next ();
7878 if (predicate .test (candidate )) {
7979 return candidate ;
8080 }
@@ -93,8 +93,8 @@ public TYPE computeNext() {
9393 * @return an Optional containing the first object of this Iterable
9494 */
9595 @ Override
96- public Optional <TYPE > first () {
97- Iterator <TYPE > resultIterator = first (1 ).iterator ();
96+ public Optional <E > first () {
97+ Iterator <E > resultIterator = first (1 ).iterator ();
9898 return resultIterator .hasNext () ? Optional .of (resultIterator .next ()) : Optional .empty ();
9999 }
100100
@@ -106,17 +106,17 @@ public Optional<TYPE> first() {
106106 * objects.
107107 */
108108 @ Override
109- public FluentIterable <TYPE > first (int count ) {
110- return new LazyFluentIterable <TYPE >() {
109+ public FluentIterable <E > first (int count ) {
110+ return new LazyFluentIterable <E >() {
111111 @ Override
112- public Iterator <TYPE > iterator () {
113- return new DecoratingIterator <TYPE >(iterable .iterator ()) {
112+ public Iterator <E > iterator () {
113+ return new DecoratingIterator <E >(iterable .iterator ()) {
114114 int currentIndex ;
115115
116116 @ Override
117- public TYPE computeNext () {
117+ public E computeNext () {
118118 if (currentIndex < count && fromIterator .hasNext ()) {
119- TYPE candidate = fromIterator .next ();
119+ E candidate = fromIterator .next ();
120120 currentIndex ++;
121121 return candidate ;
122122 }
@@ -133,8 +133,8 @@ public TYPE computeNext() {
133133 * @return an Optional containing the last object of this Iterable
134134 */
135135 @ Override
136- public Optional <TYPE > last () {
137- Iterator <TYPE > resultIterator = last (1 ).iterator ();
136+ public Optional <E > last () {
137+ Iterator <E > resultIterator = last (1 ).iterator ();
138138 return resultIterator .hasNext () ? Optional .of (resultIterator .next ()) : Optional .empty ();
139139 }
140140
@@ -148,21 +148,21 @@ public Optional<TYPE> last() {
148148 * objects
149149 */
150150 @ Override
151- public FluentIterable <TYPE > last (int count ) {
152- return new LazyFluentIterable <TYPE >() {
151+ public FluentIterable <E > last (int count ) {
152+ return new LazyFluentIterable <E >() {
153153 @ Override
154- public Iterator <TYPE > iterator () {
155- return new DecoratingIterator <TYPE >(iterable .iterator ()) {
154+ public Iterator <E > iterator () {
155+ return new DecoratingIterator <E >(iterable .iterator ()) {
156156 private int stopIndex ;
157157 private int totalElementsCount ;
158- private List <TYPE > list ;
158+ private List <E > list ;
159159 private int currentIndex ;
160160
161161 @ Override
162- public TYPE computeNext () {
162+ public E computeNext () {
163163 initialize ();
164164
165- TYPE candidate = null ;
165+ E candidate = null ;
166166 while (currentIndex < stopIndex && fromIterator .hasNext ()) {
167167 currentIndex ++;
168168 fromIterator .next ();
@@ -176,7 +176,7 @@ public TYPE computeNext() {
176176 private void initialize () {
177177 if (list == null ) {
178178 list = new ArrayList <>();
179- Iterator <TYPE > newIterator = iterable .iterator ();
179+ Iterator <E > newIterator = iterable .iterator ();
180180 while (newIterator .hasNext ()) {
181181 list .add (newIterator .next ());
182182 }
@@ -191,24 +191,24 @@ private void initialize() {
191191 }
192192
193193 /**
194- * Transforms this FluentIterable into a new one containing objects of the type NEW_TYPE .
194+ * Transforms this FluentIterable into a new one containing objects of the type T .
195195 *
196- * @param function a function that transforms an instance of TYPE into an instance of NEW_TYPE
197- * @param <NEW_TYPE > the target type of the transformation
196+ * @param function a function that transforms an instance of E into an instance of T
197+ * @param <T > the target type of the transformation
198198 * @return a new FluentIterable of the new type
199199 */
200200 @ Override
201- public <NEW_TYPE > FluentIterable <NEW_TYPE > map (Function <? super TYPE , NEW_TYPE > function ) {
202- return new LazyFluentIterable <NEW_TYPE >() {
201+ public <T > FluentIterable <T > map (Function <? super E , T > function ) {
202+ return new LazyFluentIterable <T >() {
203203 @ Override
204- public Iterator <NEW_TYPE > iterator () {
205- return new DecoratingIterator <NEW_TYPE >(null ) {
206- Iterator <TYPE > oldTypeIterator = iterable .iterator ();
204+ public Iterator <T > iterator () {
205+ return new DecoratingIterator <T >(null ) {
206+ Iterator <E > oldTypeIterator = iterable .iterator ();
207207
208208 @ Override
209- public NEW_TYPE computeNext () {
209+ public T computeNext () {
210210 if (oldTypeIterator .hasNext ()) {
211- TYPE candidate = oldTypeIterator .next ();
211+ E candidate = oldTypeIterator .next ();
212212 return function .apply (candidate );
213213 } else {
214214 return null ;
@@ -225,15 +225,15 @@ public NEW_TYPE computeNext() {
225225 * @return a list with all remaining objects of this iteration
226226 */
227227 @ Override
228- public List <TYPE > asList () {
228+ public List <E > asList () {
229229 return FluentIterable .copyToList (iterable );
230230 }
231231
232232 @ Override
233- public Iterator <TYPE > iterator () {
234- return new DecoratingIterator <TYPE >(iterable .iterator ()) {
233+ public Iterator <E > iterator () {
234+ return new DecoratingIterator <E >(iterable .iterator ()) {
235235 @ Override
236- public TYPE computeNext () {
236+ public E computeNext () {
237237 return fromIterator .hasNext () ? fromIterator .next () : null ;
238238 }
239239 };
@@ -242,7 +242,7 @@ public TYPE computeNext() {
242242 /**
243243 * @return a FluentIterable from a given iterable. Calls the LazyFluentIterable constructor.
244244 */
245- public static final <TYPE > FluentIterable <TYPE > from (Iterable <TYPE > iterable ) {
245+ public static final <E > FluentIterable <E > from (Iterable <E > iterable ) {
246246 return new LazyFluentIterable <>(iterable );
247247 }
248248
0 commit comments