1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
package extra166y; |
35 |
|
return new Reducer<T>() { |
36 |
|
public T op(T a, T b) { |
37 |
|
return (a != null && |
38 |
< |
(b == null || a.compareTo(b) >= 0))? a : b; |
38 |
> |
(b == null || a.compareTo(b) >= 0)) ? a : b; |
39 |
|
} |
40 |
|
}; |
41 |
|
} |
49 |
|
return new Reducer<T>() { |
50 |
|
public T op(T a, T b) { |
51 |
|
return (a != null && |
52 |
< |
(b == null || a.compareTo(b) <= 0))? a : b; |
52 |
> |
(b == null || a.compareTo(b) <= 0)) ? a : b; |
53 |
|
} |
54 |
|
}; |
55 |
|
} |
64 |
|
return new Reducer<T>() { |
65 |
|
public T op(T a, T b) { |
66 |
|
return (a != null && |
67 |
< |
(b == null || comparator.compare(a, b) >= 0))? a : b; |
67 |
> |
(b == null || comparator.compare(a, b) >= 0)) ? a : b; |
68 |
|
} |
69 |
|
}; |
70 |
|
} |
79 |
|
return new Reducer<T>() { |
80 |
|
public T op(T a, T b) { |
81 |
|
return (a != null && |
82 |
< |
(b == null || comparator.compare(a, b) <= 0))? a : b; |
82 |
> |
(b == null || comparator.compare(a, b) <= 0)) ? a : b; |
83 |
|
} |
84 |
|
}; |
85 |
|
} |
112 |
|
public Object op(Object a, Object b) { |
113 |
|
return (a != null && |
114 |
|
(b == null || |
115 |
< |
((Comparable)a).compareTo((Comparable)b) >= 0))? a : b; |
115 |
> |
((Comparable)a).compareTo((Comparable)b) >= 0)) ? a : b; |
116 |
|
} |
117 |
|
} |
118 |
|
|
130 |
|
public Object op(Object a, Object b) { |
131 |
|
return (a != null && |
132 |
|
(b == null || |
133 |
< |
((Comparable)a).compareTo((Comparable)b) <= 0))? a : b; |
133 |
> |
((Comparable)a).compareTo((Comparable)b) <= 0)) ? a : b; |
134 |
|
} |
135 |
|
} |
136 |
|
|
187 |
|
(final DoubleComparator comparator) { |
188 |
|
return new DoubleReducer() { |
189 |
|
public double op(double a, double b) { |
190 |
< |
return (comparator.compare(a, b) >= 0)? a : b; |
190 |
> |
return (comparator.compare(a, b) >= 0) ? a : b; |
191 |
|
} |
192 |
|
}; |
193 |
|
} |
200 |
|
(final DoubleComparator comparator) { |
201 |
|
return new DoubleReducer() { |
202 |
|
public double op(double a, double b) { |
203 |
< |
return (comparator.compare(a, b) <= 0)? a : b; |
203 |
> |
return (comparator.compare(a, b) <= 0) ? a : b; |
204 |
|
} |
205 |
|
}; |
206 |
|
} |
216 |
|
static final NaturalLongComparator comparator = new |
217 |
|
NaturalLongComparator(); |
218 |
|
public int compare(long a, long b) { |
219 |
< |
return a < b? -1 : ((a > b)? 1 : 0); |
219 |
> |
return (a < b) ? -1 : ((a > b) ? 1 : 0); |
220 |
|
} |
221 |
|
} |
222 |
|
|
232 |
|
implements LongReducer { |
233 |
|
public static final NaturalLongMaxReducer max = |
234 |
|
new NaturalLongMaxReducer(); |
235 |
< |
public long op(long a, long b) { return a >= b? a : b; } |
235 |
> |
public long op(long a, long b) { return (a >= b) ? a : b; } |
236 |
|
} |
237 |
|
|
238 |
|
/** |
246 |
|
implements LongReducer { |
247 |
|
public static final NaturalLongMinReducer min = |
248 |
|
new NaturalLongMinReducer(); |
249 |
< |
public long op(long a, long b) { return a <= b? a : b; } |
249 |
> |
public long op(long a, long b) { return (a <= b) ? a : b; } |
250 |
|
} |
251 |
|
|
252 |
|
/** |
257 |
|
(final LongComparator comparator) { |
258 |
|
return new LongReducer() { |
259 |
|
public long op(long a, long b) { |
260 |
< |
return (comparator.compare(a, b) >= 0)? a : b; |
260 |
> |
return (comparator.compare(a, b) >= 0) ? a : b; |
261 |
|
} |
262 |
|
}; |
263 |
|
} |
270 |
|
(final LongComparator comparator) { |
271 |
|
return new LongReducer() { |
272 |
|
public long op(long a, long b) { |
273 |
< |
return (comparator.compare(a, b) <= 0)? a : b; |
273 |
> |
return (comparator.compare(a, b) <= 0) ? a : b; |
274 |
|
} |
275 |
|
}; |
276 |
|
} |
521 |
|
*/ |
522 |
|
public static <T> DoubleOp compoundOp |
523 |
|
(final DoubleToObject<? extends T> first, |
524 |
< |
final ObjectToDouble<? super T> second) { |
524 |
> |
final ObjectToDouble<? super T> second) { |
525 |
|
return new DoubleOp() { |
526 |
|
public final double op(double t) { return second.op(first.op(t)); } |
527 |
|
}; |
533 |
|
*/ |
534 |
|
public static <T> LongToDouble compoundOp |
535 |
|
(final LongToObject<? extends T> first, |
536 |
< |
final ObjectToDouble<? super T> second) { |
536 |
> |
final ObjectToDouble<? super T> second) { |
537 |
|
return new LongToDouble() { |
538 |
|
public final double op(long t) { return second.op(first.op(t)); } |
539 |
|
}; |
545 |
|
*/ |
546 |
|
public static <T> DoubleToLong compoundOp |
547 |
|
(final DoubleToObject<? extends T> first, |
548 |
< |
final ObjectToLong<? super T> second) { |
548 |
> |
final ObjectToLong<? super T> second) { |
549 |
|
return new DoubleToLong() { |
550 |
|
public final long op(double t) { return second.op(first.op(t)); } |
551 |
|
}; |
557 |
|
*/ |
558 |
|
public static <T> LongOp compoundOp |
559 |
|
(final LongToObject<? extends T> first, |
560 |
< |
final ObjectToLong<? super T> second) { |
560 |
> |
final ObjectToLong<? super T> second) { |
561 |
|
return new LongOp() { |
562 |
|
public final long op(long t) { return second.op(first.op(t)); } |
563 |
|
}; |
711 |
|
/** |
712 |
|
* Returns a predicate evaluating to true if its argument is non-null |
713 |
|
*/ |
714 |
< |
public static Predicate<Object> isNonNullPredicate() { |
714 |
> |
public static Predicate<Object> isNonNullPredicate() { |
715 |
|
return IsNonNullPredicate.predicate; |
716 |
|
} |
717 |
|
static final class IsNonNullPredicate implements Predicate<Object> { |
725 |
|
/** |
726 |
|
* Returns a predicate evaluating to true if its argument is null |
727 |
|
*/ |
728 |
< |
public static Predicate<Object> isNullPredicate() { |
728 |
> |
public static Predicate<Object> isNullPredicate() { |
729 |
|
return IsNullPredicate.predicate; |
730 |
|
} |
731 |
|
static final class IsNullPredicate implements Predicate<Object> { |