author | lana |
Thu, 26 Dec 2013 12:04:16 -0800 | |
changeset 23010 | 6dadb192ad81 |
parent 16011 | 890a7ed97f6c |
permissions | -rw-r--r-- |
15311
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
16011
diff
changeset
|
2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
15311
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
4 |
* |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
8 |
* |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
13 |
* accompanied this code). |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
14 |
* |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
18 |
* |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
21 |
* questions. |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
22 |
*/ |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
23 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
24 |
import org.testng.annotations.Test; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
25 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
26 |
import java.util.Comparator; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
27 |
import java.util.function.BinaryOperator; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
28 |
import java.util.function.IntBinaryOperator; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
29 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
30 |
import static org.testng.Assert.assertEquals; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
31 |
import static org.testng.Assert.assertFalse; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
32 |
import static org.testng.Assert.assertTrue; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
33 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
34 |
import java.util.function.DoubleBinaryOperator; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
35 |
import java.util.function.LongBinaryOperator; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
36 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
37 |
/** |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
38 |
* @test |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
39 |
* @run testng PrimitiveSumMinMaxTest |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
40 |
* @summary test conversion of primitive wrapper sum, min, max, and compareTo methods to functional interfaces |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
41 |
* |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
42 |
* @author Brian Goetz |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
43 |
*/ |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
44 |
@Test |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
45 |
public class PrimitiveSumMinMaxTest { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
46 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
47 |
public void testBooleanMethods() { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
48 |
BinaryOperator<Boolean> and = Boolean::logicalAnd; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
49 |
BinaryOperator<Boolean> or = Boolean::logicalOr; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
50 |
BinaryOperator<Boolean> xor = Boolean::logicalXor; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
51 |
Comparator<Boolean> cmp = Boolean::compare; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
52 |
|
16011
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
53 |
assertTrue(and.apply(true, true)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
54 |
assertFalse(and.apply(true, false)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
55 |
assertFalse(and.apply(false, true)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
56 |
assertFalse(and.apply(false, false)); |
15311
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
57 |
|
16011
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
58 |
assertTrue(or.apply(true, true)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
59 |
assertTrue(or.apply(true, false)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
60 |
assertTrue(or.apply(false, true)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
61 |
assertFalse(or.apply(false, false)); |
15311
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
62 |
|
16011
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
63 |
assertFalse(xor.apply(true, true)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
64 |
assertTrue(xor.apply(true, false)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
65 |
assertTrue(xor.apply(false, true)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
66 |
assertFalse(xor.apply(false, false)); |
15311
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
67 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
68 |
assertEquals(Boolean.TRUE.compareTo(Boolean.TRUE), cmp.compare(true, true)); |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
69 |
assertEquals(Boolean.TRUE.compareTo(Boolean.FALSE), cmp.compare(true, false)); |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
70 |
assertEquals(Boolean.FALSE.compareTo(Boolean.TRUE), cmp.compare(false, true)); |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
71 |
assertEquals(Boolean.FALSE.compareTo(Boolean.FALSE), cmp.compare(false, false)); |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
72 |
}; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
73 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
74 |
public void testIntMethods() { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
75 |
BinaryOperator<Integer> sum1 = Integer::sum; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
76 |
IntBinaryOperator sum2 = Integer::sum; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
77 |
BinaryOperator<Integer> max1 = Integer::max; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
78 |
IntBinaryOperator max2 = Integer::max; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
79 |
BinaryOperator<Integer> min1 = Integer::min; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
80 |
IntBinaryOperator min2 = Integer::min; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
81 |
Comparator<Integer> cmp = Integer::compare; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
82 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
83 |
int[] numbers = { -1, 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE }; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
84 |
for (int i : numbers) { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
85 |
for (int j : numbers) { |
16011
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
86 |
assertEquals(i+j, (int) sum1.apply(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
87 |
assertEquals(i+j, sum2.applyAsInt(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
88 |
assertEquals(Math.max(i,j), (int) max1.apply(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
89 |
assertEquals(Math.max(i,j), max2.applyAsInt(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
90 |
assertEquals(Math.min(i,j), (int) min1.apply(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
91 |
assertEquals(Math.min(i,j), min2.applyAsInt(i, j)); |
15311
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
92 |
assertEquals(((Integer) i).compareTo(j), cmp.compare(i, j)); |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
93 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
94 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
95 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
96 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
97 |
public void testLongMethods() { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
98 |
BinaryOperator<Long> sum1 = Long::sum; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
99 |
LongBinaryOperator sum2 = Long::sum; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
100 |
BinaryOperator<Long> max1 = Long::max; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
101 |
LongBinaryOperator max2 = Long::max; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
102 |
BinaryOperator<Long> min1 = Long::min; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
103 |
LongBinaryOperator min2 = Long::min; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
104 |
Comparator<Long> cmp = Long::compare; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
105 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
106 |
long[] numbers = { -1, 0, 1, 100, Long.MAX_VALUE, Long.MIN_VALUE }; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
107 |
for (long i : numbers) { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
108 |
for (long j : numbers) { |
16011
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
109 |
assertEquals(i+j, (long) sum1.apply(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
110 |
assertEquals(i+j, sum2.applyAsLong(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
111 |
assertEquals(Math.max(i,j), (long) max1.apply(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
112 |
assertEquals(Math.max(i,j), max2.applyAsLong(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
113 |
assertEquals(Math.min(i,j), (long) min1.apply(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
114 |
assertEquals(Math.min(i,j), min2.applyAsLong(i, j)); |
15311
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
115 |
assertEquals(((Long) i).compareTo(j), cmp.compare(i, j)); |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
116 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
117 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
118 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
119 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
120 |
public void testFloatMethods() { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
121 |
BinaryOperator<Float> sum1 = Float::sum; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
122 |
BinaryOperator<Float> max1 = Float::max; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
123 |
BinaryOperator<Float> min1 = Float::min; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
124 |
Comparator<Float> cmp = Float::compare; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
125 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
126 |
float[] numbers = { -1, 0, 1, 100, Float.MAX_VALUE, Float.MIN_VALUE }; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
127 |
for (float i : numbers) { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
128 |
for (float j : numbers) { |
16011
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
129 |
assertEquals(i+j, (float) sum1.apply(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
130 |
assertEquals(Math.max(i,j), (float) max1.apply(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
131 |
assertEquals(Math.min(i,j), (float) min1.apply(i, j)); |
15311
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
132 |
assertEquals(((Float) i).compareTo(j), cmp.compare(i, j)); |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
133 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
134 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
135 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
136 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
137 |
public void testDoubleMethods() { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
138 |
BinaryOperator<Double> sum1 = Double::sum; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
139 |
DoubleBinaryOperator sum2 = Double::sum; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
140 |
BinaryOperator<Double> max1 = Double::max; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
141 |
DoubleBinaryOperator max2 = Double::max; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
142 |
BinaryOperator<Double> min1 = Double::min; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
143 |
DoubleBinaryOperator min2 = Double::min; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
144 |
Comparator<Double> cmp = Double::compare; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
145 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
146 |
double[] numbers = { -1, 0, 1, 100, Double.MAX_VALUE, Double.MIN_VALUE }; |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
147 |
for (double i : numbers) { |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
148 |
for (double j : numbers) { |
16011
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
149 |
assertEquals(i+j, (double) sum1.apply(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
150 |
assertEquals(i+j, sum2.applyAsDouble(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
151 |
assertEquals(Math.max(i,j), (double) max1.apply(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
152 |
assertEquals(Math.max(i,j), max2.applyAsDouble(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
153 |
assertEquals(Math.min(i,j), (double) min1.apply(i, j)); |
890a7ed97f6c
8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents:
15311
diff
changeset
|
154 |
assertEquals(Math.min(i,j), min2.applyAsDouble(i, j)); |
15311
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
155 |
assertEquals(((Double) i).compareTo(j), cmp.compare(i, j)); |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
156 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
157 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
158 |
} |
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
159 |
|
be0ff4a719bf
8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents:
diff
changeset
|
160 |
} |