35
35
* This is a lazy implementation of the FluentIterable interface. It evaluates all chained
36
36
* operations when a terminating operation is applied.
37
37
*
38
- * @param <TYPE > the type of the objects the iteration is about
38
+ * @param <E > the type of the objects the iteration is about
39
39
*/
40
- public class LazyFluentIterable <TYPE > implements FluentIterable <TYPE > {
40
+ public class LazyFluentIterable <E > implements FluentIterable <E > {
41
41
42
- private final Iterable <TYPE > iterable ;
42
+ private final Iterable <E > iterable ;
43
43
44
44
/**
45
45
* This constructor creates a new LazyFluentIterable. It wraps the given iterable.
46
46
*
47
47
* @param iterable the iterable this FluentIterable works on.
48
48
*/
49
- protected LazyFluentIterable (Iterable <TYPE > iterable ) {
49
+ protected LazyFluentIterable (Iterable <E > iterable ) {
50
50
this .iterable = iterable ;
51
51
}
52
52
@@ -66,15 +66,15 @@ protected LazyFluentIterable() {
66
66
* @return a new FluentIterable object that decorates the source iterable
67
67
*/
68
68
@ 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 >() {
71
71
@ 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 ()) {
74
74
@ Override
75
- public TYPE computeNext () {
75
+ public E computeNext () {
76
76
while (fromIterator .hasNext ()) {
77
- TYPE candidate = fromIterator .next ();
77
+ E candidate = fromIterator .next ();
78
78
if (predicate .test (candidate )) {
79
79
return candidate ;
80
80
}
@@ -93,8 +93,8 @@ public TYPE computeNext() {
93
93
* @return an Optional containing the first object of this Iterable
94
94
*/
95
95
@ 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 ();
98
98
return resultIterator .hasNext () ? Optional .of (resultIterator .next ()) : Optional .empty ();
99
99
}
100
100
@@ -106,17 +106,17 @@ public Optional<TYPE> first() {
106
106
* objects.
107
107
*/
108
108
@ 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 >() {
111
111
@ 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 ()) {
114
114
int currentIndex ;
115
115
116
116
@ Override
117
- public TYPE computeNext () {
117
+ public E computeNext () {
118
118
if (currentIndex < count && fromIterator .hasNext ()) {
119
- TYPE candidate = fromIterator .next ();
119
+ E candidate = fromIterator .next ();
120
120
currentIndex ++;
121
121
return candidate ;
122
122
}
@@ -133,8 +133,8 @@ public TYPE computeNext() {
133
133
* @return an Optional containing the last object of this Iterable
134
134
*/
135
135
@ 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 ();
138
138
return resultIterator .hasNext () ? Optional .of (resultIterator .next ()) : Optional .empty ();
139
139
}
140
140
@@ -148,21 +148,21 @@ public Optional<TYPE> last() {
148
148
* objects
149
149
*/
150
150
@ 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 >() {
153
153
@ 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 ()) {
156
156
private int stopIndex ;
157
157
private int totalElementsCount ;
158
- private List <TYPE > list ;
158
+ private List <E > list ;
159
159
private int currentIndex ;
160
160
161
161
@ Override
162
- public TYPE computeNext () {
162
+ public E computeNext () {
163
163
initialize ();
164
164
165
- TYPE candidate = null ;
165
+ E candidate = null ;
166
166
while (currentIndex < stopIndex && fromIterator .hasNext ()) {
167
167
currentIndex ++;
168
168
fromIterator .next ();
@@ -176,7 +176,7 @@ public TYPE computeNext() {
176
176
private void initialize () {
177
177
if (list == null ) {
178
178
list = new ArrayList <>();
179
- Iterator <TYPE > newIterator = iterable .iterator ();
179
+ Iterator <E > newIterator = iterable .iterator ();
180
180
while (newIterator .hasNext ()) {
181
181
list .add (newIterator .next ());
182
182
}
@@ -191,24 +191,24 @@ private void initialize() {
191
191
}
192
192
193
193
/**
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 .
195
195
*
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
198
198
* @return a new FluentIterable of the new type
199
199
*/
200
200
@ 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 >() {
203
203
@ 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 ();
207
207
208
208
@ Override
209
- public NEW_TYPE computeNext () {
209
+ public T computeNext () {
210
210
if (oldTypeIterator .hasNext ()) {
211
- TYPE candidate = oldTypeIterator .next ();
211
+ E candidate = oldTypeIterator .next ();
212
212
return function .apply (candidate );
213
213
} else {
214
214
return null ;
@@ -225,15 +225,15 @@ public NEW_TYPE computeNext() {
225
225
* @return a list with all remaining objects of this iteration
226
226
*/
227
227
@ Override
228
- public List <TYPE > asList () {
228
+ public List <E > asList () {
229
229
return FluentIterable .copyToList (iterable );
230
230
}
231
231
232
232
@ 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 ()) {
235
235
@ Override
236
- public TYPE computeNext () {
236
+ public E computeNext () {
237
237
return fromIterator .hasNext () ? fromIterator .next () : null ;
238
238
}
239
239
};
@@ -242,7 +242,7 @@ public TYPE computeNext() {
242
242
/**
243
243
* @return a FluentIterable from a given iterable. Calls the LazyFluentIterable constructor.
244
244
*/
245
- public static final <TYPE > FluentIterable <TYPE > from (Iterable <TYPE > iterable ) {
245
+ public static final <E > FluentIterable <E > from (Iterable <E > iterable ) {
246
246
return new LazyFluentIterable <>(iterable );
247
247
}
248
248
0 commit comments