19
19
import static com .google .common .base .Preconditions .checkNotNull ;
20
20
21
21
import com .google .common .annotations .VisibleForTesting ;
22
- import com .google .common .base .Function ;
23
- import com .google .common .base .Optional ;
24
- import com .google .common .base .Predicate ;
25
22
import com .google .common .collect .Iterables ;
26
23
import com .google .common .collect .Iterators ;
27
24
import com .google .errorprone .annotations .CanIgnoreReturnValue ;
28
25
import com .google .errorprone .annotations .ForOverride ;
29
26
import java .util .Collection ;
30
27
import java .util .Collections ;
31
28
import java .util .Iterator ;
29
+ import java .util .Optional ;
30
+ import java .util .function .Function ;
31
+ import java .util .function .Predicate ;
32
32
33
33
/**
34
34
* A representation of a choice with zero or more options, which may be evaluated lazily or
@@ -113,7 +113,7 @@ public Optional<T> findFirst() {
113
113
114
114
@ Override
115
115
public Choice <T > filter (Predicate <? super T > predicate ) {
116
- return predicate .apply (t ) ? this : Choice .<T >none ();
116
+ return predicate .test (t ) ? this : Choice .<T >none ();
117
117
}
118
118
119
119
@ Override
@@ -190,7 +190,7 @@ public String toString() {
190
190
/** Returns the first valid option from this {@code Choice}. */
191
191
public Optional <T > findFirst () {
192
192
Iterator <T > itr = iterator ();
193
- return itr .hasNext () ? Optional .of (itr .next ()) : Optional .<T >absent ();
193
+ return itr .hasNext () ? Optional .of (itr .next ()) : Optional .<T >empty ();
194
194
}
195
195
196
196
/**
@@ -229,7 +229,11 @@ public <R> Choice<R> mapIfPresent(Function<? super T, Optional<R>> function) {
229
229
return new Choice <R >() {
230
230
@ Override
231
231
protected Iterator <R > iterator () {
232
- return Optional .presentInstances (Iterables .transform (thisChoice .asIterable (), function ))
232
+ return Iterables .transform (
233
+ Iterables .filter (
234
+ Iterables .transform (thisChoice .asIterable (), function ::apply ),
235
+ Optional ::isPresent ),
236
+ Optional ::get )
233
237
.iterator ();
234
238
}
235
239
};
@@ -242,7 +246,7 @@ public <R> Choice<R> map(Function<? super T, R> function) {
242
246
return new Choice <R >() {
243
247
@ Override
244
248
protected Iterator <R > iterator () {
245
- return Iterators .transform (thisChoice .iterator (), function );
249
+ return Iterators .transform (thisChoice .iterator (), function :: apply );
246
250
}
247
251
};
248
252
}
@@ -275,7 +279,7 @@ public Choice<T> filter(Predicate<? super T> predicate) {
275
279
return new Choice <T >() {
276
280
@ Override
277
281
protected Iterator <T > iterator () {
278
- return Iterators .filter (thisChoice .iterator (), predicate );
282
+ return Iterators .filter (thisChoice .iterator (), predicate :: test );
279
283
}
280
284
281
285
@ Override
0 commit comments