Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/Jsr292/src/com/ibm/j9/jsr292/GuardTest.java
6007 views
1
/*******************************************************************************
2
* Copyright (c) 2014, 2018 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package com.ibm.j9.jsr292;
23
24
import org.testng.annotations.Test;
25
import org.testng.AssertJUnit;
26
import static java.lang.invoke.MethodType.methodType;
27
28
import java.lang.invoke.MethodHandle;
29
import java.lang.invoke.MethodHandles;
30
import java.lang.invoke.MethodType;
31
import java.lang.invoke.WrongMethodTypeException;
32
import java.util.Arrays;
33
34
/*
35
* Testing MethodHandles.guardWithTest(MethodHandle test, MethodHandle target, MethodHandle fallback).
36
*
37
* Tests guardWithTest with the following FieldTypes for (Parameter/Return Descriptors): B, S, C, I, F, J, D, Ljava/lang/Double;
38
*
39
* For each FieldType, guardWithTest is tested for boundary and intermediate conditions.
40
*
41
* Example:
42
*
43
* Let FieldType = D
44
*
45
* target method descriptor: (DDDDD)D
46
* fallback method descriptor: (DDDDD)D
47
*
48
* test method descriptor variants:
49
* ()Z
50
* (D)Z
51
* (DD)Z
52
* (DDD)Z
53
* (DDDD)Z
54
* (DDDDD)Z
55
*/
56
public class GuardTest {
57
private final static byte constByte1 = (byte) 11;
58
private final static byte constByte2 = (byte) -20;
59
private final static byte constByte3 = (byte) 116;
60
private final static byte constByte4 = (byte) 63;
61
private final static byte constByte5 = (byte) -80;
62
private final static short constShort1 = (short) 30845;
63
private final static short constShort2 = (short) -9542;
64
private final static short constShort3 = (short) 12208;
65
private final static short constShort4 = (short) -14948;
66
private final static short constShort5 = (short) 30753;
67
private final static char constCharacter1 = (char) 1263;
68
private final static char constCharacter2 = (char) 34205;
69
private final static char constCharacter3 = (char) 1967;
70
private final static char constCharacter4 = (char) 19093;
71
private final static char constCharacter5 = (char) 42319;
72
private final static int constInteger1 = (int) 1556086783;
73
private final static int constInteger2 = (int) 817758207;
74
private final static int constInteger3 = (int) 369491967;
75
private final static int constInteger4 = (int) -1745879040;
76
private final static int constInteger5 = (int) -716963840;
77
private final static long constLong1 = (long) -7.50299697919925e+018;
78
private final static long constLong2 = (long) 4.06337276379503e+018;
79
private final static long constLong3 = (long) -8.27592726524671e+018;
80
private final static long constLong4 = (long) 9.0629313001297e+018;
81
private final static long constLong5 = (long) -1.66126531254629e+018;
82
private final static float constFloat1 = (float) 2.40039871833801e+038F;
83
private final static float constFloat2 = (float) -2.79937478910828e+038F;
84
private final static float constFloat3 = (float) 2.48908314427185e+038F;
85
private final static float constFloat4 = (float) 3.37104664480591e+038F;
86
private final static float constFloat5 = (float) -1.21208971838379e+038F;
87
private final static double constDouble1 = (double) 4.22650998259866e+307;
88
private final static double constDouble2 = (double) -1.66772685567259e+308;
89
private final static double constDouble3 = (double) -6.05942403398263e+307;
90
private final static double constDouble4 = (double) 4.75482373042349e+307;
91
private final static double constDouble5 = (double) 1.21572509364468e+308;
92
93
/* Test guardWithTest: data-type -> byte */
94
@Test(groups = { "level.extended" })
95
public void test_guardWithTest_Byte() throws WrongMethodTypeException, Throwable {
96
MethodType mtTrueTarget = methodType(byte.class, byte.class, byte.class, byte.class, byte.class, byte.class);
97
MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetByte", mtTrueTarget);
98
99
MethodType mtFalseTarget = methodType(byte.class, byte.class, byte.class, byte.class, byte.class, byte.class);
100
MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetByte", mtFalseTarget);
101
102
MethodType mtTest = methodType(boolean.class);
103
MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);
104
MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
105
AssertJUnit.assertEquals(verifyGuardByte (0, constByte1, constByte2, constByte3, constByte4, Byte.MAX_VALUE),
106
(byte) mhGuard.invokeExact(constByte1, constByte2, constByte3, constByte4, Byte.MAX_VALUE));
107
108
mtTest = methodType(boolean.class, byte.class);
109
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);
110
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
111
AssertJUnit.assertEquals(verifyGuardByte (1, constByte2, constByte3, constByte4, Byte.MAX_VALUE, constByte5),
112
(byte) mhGuard.invokeExact(constByte2, constByte3, constByte4, Byte.MAX_VALUE, constByte5));
113
114
mtTest = methodType(boolean.class, byte.class, byte.class);
115
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);
116
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
117
AssertJUnit.assertEquals(verifyGuardByte (2, constByte2, constByte3, Byte.MIN_VALUE, constByte4, constByte1),
118
(byte) mhGuard.invokeExact(constByte2, constByte3, Byte.MIN_VALUE, constByte4, constByte1));
119
120
mtTest = methodType(boolean.class, byte.class, byte.class, byte.class);
121
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);
122
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
123
AssertJUnit.assertEquals(verifyGuardByte (3, Byte.MAX_VALUE, constByte3, Byte.MIN_VALUE, constByte4, constByte1),
124
(byte) mhGuard.invokeExact(Byte.MAX_VALUE, constByte3, Byte.MIN_VALUE, constByte4, constByte1));
125
126
mtTest = methodType(boolean.class, byte.class, byte.class, byte.class, byte.class);
127
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);
128
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
129
AssertJUnit.assertEquals(verifyGuardByte (4, constByte1, constByte2, constByte3, constByte4, constByte5),
130
(byte) mhGuard.invokeExact(constByte1, constByte2, constByte3, constByte4, constByte5));
131
132
mtTest = methodType(boolean.class, byte.class, byte.class, byte.class, byte.class, byte.class);
133
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);
134
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
135
AssertJUnit.assertEquals(verifyGuardByte (5, Byte.MIN_VALUE, constByte3, constByte5, constByte4, constByte1),
136
(byte) mhGuard.invokeExact(Byte.MIN_VALUE, constByte3, constByte5, constByte4, constByte1));
137
}
138
139
public static boolean testByte () {
140
return testByteGen ();
141
}
142
143
public static boolean testByte (byte a) {
144
return testByteGen (a);
145
}
146
147
public static boolean testByte (byte a, byte b) {
148
return testByteGen (a, b);
149
}
150
151
public static boolean testByte (byte a, byte b, byte c) {
152
return testByteGen (a, b, c);
153
}
154
155
public static boolean testByte (byte a, byte b, byte c, byte d) {
156
return testByteGen (a, b, c, d);
157
}
158
159
public static boolean testByte (byte a, byte b, byte c, byte d, byte e) {
160
return testByteGen (a, b, c, d, e);
161
}
162
163
public static byte trueTargetByte (byte a, byte b, byte c, byte d, byte e) {
164
return largestByte (a, b, c, d, e);
165
}
166
167
public static byte falseTargetByte (byte a, byte b, byte c, byte d, byte e) {
168
return smallestByte (a, b, c, d, e);
169
}
170
171
public static boolean testByteGen (byte... args) {
172
if (0 == args.length) {
173
return false;
174
} else {
175
byte last = args [args.length - 1];
176
for (int i = 0; i < (args.length - 1); i++) {
177
if (last < args [i]) {
178
return false;
179
}
180
}
181
return true;
182
}
183
}
184
185
public static byte smallestByte (byte... args) {
186
byte smallest = Byte.MAX_VALUE;
187
for(byte arg : args) {
188
if (smallest > arg) {
189
smallest = arg;
190
}
191
}
192
return smallest;
193
}
194
195
public static byte largestByte (byte... args) {
196
byte largest = Byte.MIN_VALUE;
197
for(byte arg : args) {
198
if (largest < arg) {
199
largest = arg;
200
}
201
}
202
return largest;
203
}
204
205
public static byte verifyGuardByte (int type, byte... args) {
206
byte[] testArgs;
207
208
if (0 == type) {
209
testArgs = null;
210
} else {
211
testArgs = Arrays.copyOfRange(args, 0, type);
212
}
213
214
if (null == testArgs) {
215
return smallestByte (args);
216
} else {
217
if (true == testByteGen(testArgs)) {
218
return largestByte (args);
219
} else {
220
return smallestByte (args);
221
}
222
}
223
}
224
/* Test guardWithTest: data-type -> short */
225
@Test(groups = { "level.extended" })
226
public void test_guardWithTest_Short() throws WrongMethodTypeException, Throwable {
227
MethodType mtTrueTarget = methodType(short.class, short.class, short.class, short.class, short.class, short.class);
228
MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetShort", mtTrueTarget);
229
230
MethodType mtFalseTarget = methodType(short.class, short.class, short.class, short.class, short.class, short.class);
231
MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetShort", mtFalseTarget);
232
233
MethodType mtTest = methodType(boolean.class);
234
MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);
235
MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
236
AssertJUnit.assertEquals(verifyGuardShort (0, constShort1, constShort2, constShort3, constShort4, Short.MAX_VALUE),
237
(short) mhGuard.invokeExact(constShort1, constShort2, constShort3, constShort4, Short.MAX_VALUE));
238
239
mtTest = methodType(boolean.class, short.class);
240
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);
241
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
242
AssertJUnit.assertEquals(verifyGuardShort (1, constShort2, constShort3, constShort4, Short.MAX_VALUE, constShort5),
243
(short) mhGuard.invokeExact(constShort2, constShort3, constShort4, Short.MAX_VALUE, constShort5));
244
245
mtTest = methodType(boolean.class, short.class, short.class);
246
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);
247
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
248
AssertJUnit.assertEquals(verifyGuardShort (2, constShort2, constShort3, Short.MIN_VALUE, constShort4, constShort1),
249
(short) mhGuard.invokeExact(constShort2, constShort3, Short.MIN_VALUE, constShort4, constShort1));
250
251
mtTest = methodType(boolean.class, short.class, short.class, short.class);
252
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);
253
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
254
AssertJUnit.assertEquals(verifyGuardShort (3, Short.MAX_VALUE, constShort3, Short.MIN_VALUE, constShort4, constShort1),
255
(short) mhGuard.invokeExact(Short.MAX_VALUE, constShort3, Short.MIN_VALUE, constShort4, constShort1));
256
257
mtTest = methodType(boolean.class, short.class, short.class, short.class, short.class);
258
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);
259
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
260
AssertJUnit.assertEquals(verifyGuardShort (4, constShort1, constShort2, constShort3, constShort4, constShort5),
261
(short) mhGuard.invokeExact(constShort1, constShort2, constShort3, constShort4, constShort5));
262
263
mtTest = methodType(boolean.class, short.class, short.class, short.class, short.class, short.class);
264
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);
265
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
266
AssertJUnit.assertEquals(verifyGuardShort (5, Short.MIN_VALUE, constShort3, constShort5, constShort4, constShort1),
267
(short) mhGuard.invokeExact(Short.MIN_VALUE, constShort3, constShort5, constShort4, constShort1));
268
}
269
270
public static boolean testShort () {
271
return testShortGen ();
272
}
273
274
public static boolean testShort (short a) {
275
return testShortGen (a);
276
}
277
278
public static boolean testShort (short a, short b) {
279
return testShortGen (a, b);
280
}
281
282
public static boolean testShort (short a, short b, short c) {
283
return testShortGen (a, b, c);
284
}
285
286
public static boolean testShort (short a, short b, short c, short d) {
287
return testShortGen (a, b, c, d);
288
}
289
290
public static boolean testShort (short a, short b, short c, short d, short e) {
291
return testShortGen (a, b, c, d, e);
292
}
293
294
public static short trueTargetShort (short a, short b, short c, short d, short e) {
295
return largestShort (a, b, c, d, e);
296
}
297
298
public static short falseTargetShort (short a, short b, short c, short d, short e) {
299
return smallestShort (a, b, c, d, e);
300
}
301
302
public static boolean testShortGen (short... args) {
303
if (0 == args.length) {
304
return false;
305
} else {
306
short last = args [args.length - 1];
307
for (int i = 0; i < (args.length - 1); i++) {
308
if (last < args [i]) {
309
return false;
310
}
311
}
312
return true;
313
}
314
}
315
316
public static short smallestShort (short... args) {
317
short smallest = Short.MAX_VALUE;
318
for(short arg : args) {
319
if (smallest > arg) {
320
smallest = arg;
321
}
322
}
323
return smallest;
324
}
325
326
public static short largestShort (short... args) {
327
short largest = Short.MIN_VALUE;
328
for(short arg : args) {
329
if (largest < arg) {
330
largest = arg;
331
}
332
}
333
return largest;
334
}
335
336
public static short verifyGuardShort (int type, short... args) {
337
short[] testArgs;
338
339
if (0 == type) {
340
testArgs = null;
341
} else {
342
testArgs = Arrays.copyOfRange(args, 0, type);
343
}
344
345
if (null == testArgs) {
346
return smallestShort (args);
347
} else {
348
if (true == testShortGen(testArgs)) {
349
return largestShort (args);
350
} else {
351
return smallestShort (args);
352
}
353
}
354
}
355
/* Test guardWithTest: data-type -> char */
356
@Test(groups = { "level.extended" })
357
public void test_guardWithTest_Character() throws WrongMethodTypeException, Throwable {
358
MethodType mtTrueTarget = methodType(char.class, char.class, char.class, char.class, char.class, char.class);
359
MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetCharacter", mtTrueTarget);
360
361
MethodType mtFalseTarget = methodType(char.class, char.class, char.class, char.class, char.class, char.class);
362
MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetCharacter", mtFalseTarget);
363
364
MethodType mtTest = methodType(boolean.class);
365
MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);
366
MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
367
AssertJUnit.assertEquals(verifyGuardCharacter (0, constCharacter1, constCharacter2, constCharacter3, constCharacter4, Character.MAX_VALUE),
368
(char) mhGuard.invokeExact(constCharacter1, constCharacter2, constCharacter3, constCharacter4, Character.MAX_VALUE));
369
370
mtTest = methodType(boolean.class, char.class);
371
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);
372
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
373
AssertJUnit.assertEquals(verifyGuardCharacter (1, constCharacter2, constCharacter3, constCharacter4, Character.MAX_VALUE, constCharacter5),
374
(char) mhGuard.invokeExact(constCharacter2, constCharacter3, constCharacter4, Character.MAX_VALUE, constCharacter5));
375
376
mtTest = methodType(boolean.class, char.class, char.class);
377
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);
378
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
379
AssertJUnit.assertEquals(verifyGuardCharacter (2, constCharacter2, constCharacter3, Character.MIN_VALUE, constCharacter4, constCharacter1),
380
(char) mhGuard.invokeExact(constCharacter2, constCharacter3, Character.MIN_VALUE, constCharacter4, constCharacter1));
381
382
mtTest = methodType(boolean.class, char.class, char.class, char.class);
383
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);
384
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
385
AssertJUnit.assertEquals(verifyGuardCharacter (3, Character.MAX_VALUE, constCharacter3, Character.MIN_VALUE, constCharacter4, constCharacter1),
386
(char) mhGuard.invokeExact(Character.MAX_VALUE, constCharacter3, Character.MIN_VALUE, constCharacter4, constCharacter1));
387
388
mtTest = methodType(boolean.class, char.class, char.class, char.class, char.class);
389
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);
390
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
391
AssertJUnit.assertEquals(verifyGuardCharacter (4, constCharacter1, constCharacter2, constCharacter3, constCharacter4, constCharacter5),
392
(char) mhGuard.invokeExact(constCharacter1, constCharacter2, constCharacter3, constCharacter4, constCharacter5));
393
394
mtTest = methodType(boolean.class, char.class, char.class, char.class, char.class, char.class);
395
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);
396
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
397
AssertJUnit.assertEquals(verifyGuardCharacter (5, Character.MIN_VALUE, constCharacter3, constCharacter5, constCharacter4, constCharacter1),
398
(char) mhGuard.invokeExact(Character.MIN_VALUE, constCharacter3, constCharacter5, constCharacter4, constCharacter1));
399
}
400
401
public static boolean testCharacter () {
402
return testCharacterGen ();
403
}
404
405
public static boolean testCharacter (char a) {
406
return testCharacterGen (a);
407
}
408
409
public static boolean testCharacter (char a, char b) {
410
return testCharacterGen (a, b);
411
}
412
413
public static boolean testCharacter (char a, char b, char c) {
414
return testCharacterGen (a, b, c);
415
}
416
417
public static boolean testCharacter (char a, char b, char c, char d) {
418
return testCharacterGen (a, b, c, d);
419
}
420
421
public static boolean testCharacter (char a, char b, char c, char d, char e) {
422
return testCharacterGen (a, b, c, d, e);
423
}
424
425
public static char trueTargetCharacter (char a, char b, char c, char d, char e) {
426
return largestCharacter (a, b, c, d, e);
427
}
428
429
public static char falseTargetCharacter (char a, char b, char c, char d, char e) {
430
return smallestCharacter (a, b, c, d, e);
431
}
432
433
public static boolean testCharacterGen (char... args) {
434
if (0 == args.length) {
435
return false;
436
} else {
437
char last = args [args.length - 1];
438
for (int i = 0; i < (args.length - 1); i++) {
439
if (last < args [i]) {
440
return false;
441
}
442
}
443
return true;
444
}
445
}
446
447
public static char smallestCharacter (char... args) {
448
char smallest = Character.MAX_VALUE;
449
for(char arg : args) {
450
if (smallest > arg) {
451
smallest = arg;
452
}
453
}
454
return smallest;
455
}
456
457
public static char largestCharacter (char... args) {
458
char largest = Character.MIN_VALUE;
459
for(char arg : args) {
460
if (largest < arg) {
461
largest = arg;
462
}
463
}
464
return largest;
465
}
466
467
public static char verifyGuardCharacter (int type, char... args) {
468
char[] testArgs;
469
470
if (0 == type) {
471
testArgs = null;
472
} else {
473
testArgs = Arrays.copyOfRange(args, 0, type);
474
}
475
476
if (null == testArgs) {
477
return smallestCharacter (args);
478
} else {
479
if (true == testCharacterGen(testArgs)) {
480
return largestCharacter (args);
481
} else {
482
return smallestCharacter (args);
483
}
484
}
485
}
486
/* Test guardWithTest: data-type -> int */
487
@Test(groups = { "level.extended" })
488
public void test_guardWithTest_Integer() throws WrongMethodTypeException, Throwable {
489
MethodType mtTrueTarget = methodType(int.class, int.class, int.class, int.class, int.class, int.class);
490
MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetInteger", mtTrueTarget);
491
492
MethodType mtFalseTarget = methodType(int.class, int.class, int.class, int.class, int.class, int.class);
493
MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetInteger", mtFalseTarget);
494
495
MethodType mtTest = methodType(boolean.class);
496
MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);
497
MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
498
AssertJUnit.assertEquals(verifyGuardInteger (0, constInteger1, constInteger2, constInteger3, constInteger4, Integer.MAX_VALUE),
499
(int) mhGuard.invokeExact(constInteger1, constInteger2, constInteger3, constInteger4, Integer.MAX_VALUE));
500
501
mtTest = methodType(boolean.class, int.class);
502
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);
503
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
504
AssertJUnit.assertEquals(verifyGuardInteger (1, constInteger2, constInteger3, constInteger4, Integer.MAX_VALUE, constInteger5),
505
(int) mhGuard.invokeExact(constInteger2, constInteger3, constInteger4, Integer.MAX_VALUE, constInteger5));
506
507
mtTest = methodType(boolean.class, int.class, int.class);
508
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);
509
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
510
AssertJUnit.assertEquals(verifyGuardInteger (2, constInteger2, constInteger3, Integer.MIN_VALUE, constInteger4, constInteger1),
511
(int) mhGuard.invokeExact(constInteger2, constInteger3, Integer.MIN_VALUE, constInteger4, constInteger1));
512
513
mtTest = methodType(boolean.class, int.class, int.class, int.class);
514
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);
515
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
516
AssertJUnit.assertEquals(verifyGuardInteger (3, Integer.MAX_VALUE, constInteger3, Integer.MIN_VALUE, constInteger4, constInteger1),
517
(int) mhGuard.invokeExact(Integer.MAX_VALUE, constInteger3, Integer.MIN_VALUE, constInteger4, constInteger1));
518
519
mtTest = methodType(boolean.class, int.class, int.class, int.class, int.class);
520
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);
521
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
522
AssertJUnit.assertEquals(verifyGuardInteger (4, constInteger1, constInteger2, constInteger3, constInteger4, constInteger5),
523
(int) mhGuard.invokeExact(constInteger1, constInteger2, constInteger3, constInteger4, constInteger5));
524
525
mtTest = methodType(boolean.class, int.class, int.class, int.class, int.class, int.class);
526
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);
527
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
528
AssertJUnit.assertEquals(verifyGuardInteger (5, Integer.MIN_VALUE, constInteger3, constInteger5, constInteger4, constInteger1),
529
(int) mhGuard.invokeExact(Integer.MIN_VALUE, constInteger3, constInteger5, constInteger4, constInteger1));
530
}
531
532
public static boolean testInteger () {
533
return testIntegerGen ();
534
}
535
536
public static boolean testInteger (int a) {
537
return testIntegerGen (a);
538
}
539
540
public static boolean testInteger (int a, int b) {
541
return testIntegerGen (a, b);
542
}
543
544
public static boolean testInteger (int a, int b, int c) {
545
return testIntegerGen (a, b, c);
546
}
547
548
public static boolean testInteger (int a, int b, int c, int d) {
549
return testIntegerGen (a, b, c, d);
550
}
551
552
public static boolean testInteger (int a, int b, int c, int d, int e) {
553
return testIntegerGen (a, b, c, d, e);
554
}
555
556
public static int trueTargetInteger (int a, int b, int c, int d, int e) {
557
return largestInteger (a, b, c, d, e);
558
}
559
560
public static int falseTargetInteger (int a, int b, int c, int d, int e) {
561
return smallestInteger (a, b, c, d, e);
562
}
563
564
public static boolean testIntegerGen (int... args) {
565
if (0 == args.length) {
566
return false;
567
} else {
568
int last = args [args.length - 1];
569
for (int i = 0; i < (args.length - 1); i++) {
570
if (last < args [i]) {
571
return false;
572
}
573
}
574
return true;
575
}
576
}
577
578
public static int smallestInteger (int... args) {
579
int smallest = Integer.MAX_VALUE;
580
for(int arg : args) {
581
if (smallest > arg) {
582
smallest = arg;
583
}
584
}
585
return smallest;
586
}
587
588
public static int largestInteger (int... args) {
589
int largest = Integer.MIN_VALUE;
590
for(int arg : args) {
591
if (largest < arg) {
592
largest = arg;
593
}
594
}
595
return largest;
596
}
597
598
public static int verifyGuardInteger (int type, int... args) {
599
int[] testArgs;
600
601
if (0 == type) {
602
testArgs = null;
603
} else {
604
testArgs = Arrays.copyOfRange(args, 0, type);
605
}
606
607
if (null == testArgs) {
608
return smallestInteger (args);
609
} else {
610
if (true == testIntegerGen(testArgs)) {
611
return largestInteger (args);
612
} else {
613
return smallestInteger (args);
614
}
615
}
616
}
617
/* Test guardWithTest: data-type -> long */
618
@Test(groups = { "level.extended" })
619
public void test_guardWithTest_Long() throws WrongMethodTypeException, Throwable {
620
MethodType mtTrueTarget = methodType(long.class, long.class, long.class, long.class, long.class, long.class);
621
MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetLong", mtTrueTarget);
622
623
MethodType mtFalseTarget = methodType(long.class, long.class, long.class, long.class, long.class, long.class);
624
MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetLong", mtFalseTarget);
625
626
MethodType mtTest = methodType(boolean.class);
627
MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);
628
MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
629
AssertJUnit.assertEquals(verifyGuardLong (0, constLong1, constLong2, constLong3, constLong4, Long.MAX_VALUE),
630
(long) mhGuard.invokeExact(constLong1, constLong2, constLong3, constLong4, Long.MAX_VALUE));
631
632
mtTest = methodType(boolean.class, long.class);
633
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);
634
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
635
AssertJUnit.assertEquals(verifyGuardLong (1, constLong2, constLong3, constLong4, Long.MAX_VALUE, constLong5),
636
(long) mhGuard.invokeExact(constLong2, constLong3, constLong4, Long.MAX_VALUE, constLong5));
637
638
mtTest = methodType(boolean.class, long.class, long.class);
639
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);
640
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
641
AssertJUnit.assertEquals(verifyGuardLong (2, constLong2, constLong3, Long.MIN_VALUE, constLong4, constLong1),
642
(long) mhGuard.invokeExact(constLong2, constLong3, Long.MIN_VALUE, constLong4, constLong1));
643
644
mtTest = methodType(boolean.class, long.class, long.class, long.class);
645
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);
646
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
647
AssertJUnit.assertEquals(verifyGuardLong (3, Long.MAX_VALUE, constLong3, Long.MIN_VALUE, constLong4, constLong1),
648
(long) mhGuard.invokeExact(Long.MAX_VALUE, constLong3, Long.MIN_VALUE, constLong4, constLong1));
649
650
mtTest = methodType(boolean.class, long.class, long.class, long.class, long.class);
651
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);
652
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
653
AssertJUnit.assertEquals(verifyGuardLong (4, constLong1, constLong2, constLong3, constLong4, constLong5),
654
(long) mhGuard.invokeExact(constLong1, constLong2, constLong3, constLong4, constLong5));
655
656
mtTest = methodType(boolean.class, long.class, long.class, long.class, long.class, long.class);
657
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);
658
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
659
AssertJUnit.assertEquals(verifyGuardLong (5, Long.MIN_VALUE, constLong3, constLong5, constLong4, constLong1),
660
(long) mhGuard.invokeExact(Long.MIN_VALUE, constLong3, constLong5, constLong4, constLong1));
661
}
662
663
public static boolean testLong () {
664
return testLongGen ();
665
}
666
667
public static boolean testLong (long a) {
668
return testLongGen (a);
669
}
670
671
public static boolean testLong (long a, long b) {
672
return testLongGen (a, b);
673
}
674
675
public static boolean testLong (long a, long b, long c) {
676
return testLongGen (a, b, c);
677
}
678
679
public static boolean testLong (long a, long b, long c, long d) {
680
return testLongGen (a, b, c, d);
681
}
682
683
public static boolean testLong (long a, long b, long c, long d, long e) {
684
return testLongGen (a, b, c, d, e);
685
}
686
687
public static long trueTargetLong (long a, long b, long c, long d, long e) {
688
return largestLong (a, b, c, d, e);
689
}
690
691
public static long falseTargetLong (long a, long b, long c, long d, long e) {
692
return smallestLong (a, b, c, d, e);
693
}
694
695
public static boolean testLongGen (long... args) {
696
if (0 == args.length) {
697
return false;
698
} else {
699
long last = args [args.length - 1];
700
for (int i = 0; i < (args.length - 1); i++) {
701
if (last < args [i]) {
702
return false;
703
}
704
}
705
return true;
706
}
707
}
708
709
public static long smallestLong (long... args) {
710
long smallest = Long.MAX_VALUE;
711
for(long arg : args) {
712
if (smallest > arg) {
713
smallest = arg;
714
}
715
}
716
return smallest;
717
}
718
719
public static long largestLong (long... args) {
720
long largest = Long.MIN_VALUE;
721
for(long arg : args) {
722
if (largest < arg) {
723
largest = arg;
724
}
725
}
726
return largest;
727
}
728
729
public static long verifyGuardLong (int type, long... args) {
730
long[] testArgs;
731
732
if (0 == type) {
733
testArgs = null;
734
} else {
735
testArgs = Arrays.copyOfRange(args, 0, type);
736
}
737
738
if (null == testArgs) {
739
return smallestLong (args);
740
} else {
741
if (true == testLongGen(testArgs)) {
742
return largestLong (args);
743
} else {
744
return smallestLong (args);
745
}
746
}
747
}
748
/* Test guardWithTest: data-type -> float */
749
@Test(groups = { "level.extended" })
750
public void test_guardWithTest_Float() throws WrongMethodTypeException, Throwable {
751
MethodType mtTrueTarget = methodType(float.class, float.class, float.class, float.class, float.class, float.class);
752
MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetFloat", mtTrueTarget);
753
754
MethodType mtFalseTarget = methodType(float.class, float.class, float.class, float.class, float.class, float.class);
755
MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetFloat", mtFalseTarget);
756
757
MethodType mtTest = methodType(boolean.class);
758
MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);
759
MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
760
AssertJUnit.assertEquals(verifyGuardFloat (0, constFloat1, constFloat2, constFloat3, constFloat4, Float.MAX_VALUE),
761
(float) mhGuard.invokeExact(constFloat1, constFloat2, constFloat3, constFloat4, Float.MAX_VALUE));
762
763
mtTest = methodType(boolean.class, float.class);
764
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);
765
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
766
AssertJUnit.assertEquals(verifyGuardFloat (1, constFloat2, constFloat3, constFloat4, Float.MAX_VALUE, constFloat5),
767
(float) mhGuard.invokeExact(constFloat2, constFloat3, constFloat4, Float.MAX_VALUE, constFloat5));
768
769
mtTest = methodType(boolean.class, float.class, float.class);
770
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);
771
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
772
AssertJUnit.assertEquals(verifyGuardFloat (2, constFloat2, constFloat3, Float.MIN_VALUE, constFloat4, constFloat1),
773
(float) mhGuard.invokeExact(constFloat2, constFloat3, Float.MIN_VALUE, constFloat4, constFloat1));
774
775
mtTest = methodType(boolean.class, float.class, float.class, float.class);
776
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);
777
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
778
AssertJUnit.assertEquals(verifyGuardFloat (3, Float.MAX_VALUE, constFloat3, Float.MIN_VALUE, constFloat4, constFloat1),
779
(float) mhGuard.invokeExact(Float.MAX_VALUE, constFloat3, Float.MIN_VALUE, constFloat4, constFloat1));
780
781
mtTest = methodType(boolean.class, float.class, float.class, float.class, float.class);
782
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);
783
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
784
AssertJUnit.assertEquals(verifyGuardFloat (4, constFloat1, constFloat2, constFloat3, constFloat4, constFloat5),
785
(float) mhGuard.invokeExact(constFloat1, constFloat2, constFloat3, constFloat4, constFloat5));
786
787
mtTest = methodType(boolean.class, float.class, float.class, float.class, float.class, float.class);
788
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);
789
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
790
AssertJUnit.assertEquals(verifyGuardFloat (5, Float.MIN_VALUE, constFloat3, constFloat5, constFloat4, constFloat1),
791
(float) mhGuard.invokeExact(Float.MIN_VALUE, constFloat3, constFloat5, constFloat4, constFloat1));
792
}
793
794
public static boolean testFloat () {
795
return testFloatGen ();
796
}
797
798
public static boolean testFloat (float a) {
799
return testFloatGen (a);
800
}
801
802
public static boolean testFloat (float a, float b) {
803
return testFloatGen (a, b);
804
}
805
806
public static boolean testFloat (float a, float b, float c) {
807
return testFloatGen (a, b, c);
808
}
809
810
public static boolean testFloat (float a, float b, float c, float d) {
811
return testFloatGen (a, b, c, d);
812
}
813
814
public static boolean testFloat (float a, float b, float c, float d, float e) {
815
return testFloatGen (a, b, c, d, e);
816
}
817
818
public static float trueTargetFloat (float a, float b, float c, float d, float e) {
819
return largestFloat (a, b, c, d, e);
820
}
821
822
public static float falseTargetFloat (float a, float b, float c, float d, float e) {
823
return smallestFloat (a, b, c, d, e);
824
}
825
826
public static boolean testFloatGen (float... args) {
827
if (0 == args.length) {
828
return false;
829
} else {
830
float last = args [args.length - 1];
831
for (int i = 0; i < (args.length - 1); i++) {
832
if (last < args [i]) {
833
return false;
834
}
835
}
836
return true;
837
}
838
}
839
840
public static float smallestFloat (float... args) {
841
float smallest = Float.MAX_VALUE;
842
for(float arg : args) {
843
if (smallest > arg) {
844
smallest = arg;
845
}
846
}
847
return smallest;
848
}
849
850
public static float largestFloat (float... args) {
851
float largest = Float.MIN_VALUE;
852
for(float arg : args) {
853
if (largest < arg) {
854
largest = arg;
855
}
856
}
857
return largest;
858
}
859
860
public static float verifyGuardFloat (int type, float... args) {
861
float[] testArgs;
862
863
if (0 == type) {
864
testArgs = null;
865
} else {
866
testArgs = Arrays.copyOfRange(args, 0, type);
867
}
868
869
if (null == testArgs) {
870
return smallestFloat (args);
871
} else {
872
if (true == testFloatGen(testArgs)) {
873
return largestFloat (args);
874
} else {
875
return smallestFloat (args);
876
}
877
}
878
}
879
/* Test guardWithTest: data-type -> double */
880
@Test(groups = { "level.extended" })
881
public void test_guardWithTest_Double() throws WrongMethodTypeException, Throwable {
882
MethodType mtTrueTarget = methodType(double.class, double.class, double.class, double.class, double.class, double.class);
883
MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetDouble", mtTrueTarget);
884
885
MethodType mtFalseTarget = methodType(double.class, double.class, double.class, double.class, double.class, double.class);
886
MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetDouble", mtFalseTarget);
887
888
MethodType mtTest = methodType(boolean.class);
889
MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);
890
MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
891
AssertJUnit.assertEquals(verifyGuardDouble (0, constDouble1, constDouble2, constDouble3, constDouble4, Double.MAX_VALUE),
892
(double) mhGuard.invokeExact(constDouble1, constDouble2, constDouble3, constDouble4, Double.MAX_VALUE));
893
894
mtTest = methodType(boolean.class, double.class);
895
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);
896
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
897
AssertJUnit.assertEquals(verifyGuardDouble (1, constDouble2, constDouble3, constDouble4, Double.MAX_VALUE, constDouble5),
898
(double) mhGuard.invokeExact(constDouble2, constDouble3, constDouble4, Double.MAX_VALUE, constDouble5));
899
900
mtTest = methodType(boolean.class, double.class, double.class);
901
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);
902
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
903
AssertJUnit.assertEquals(verifyGuardDouble (2, constDouble2, constDouble3, Double.MIN_VALUE, constDouble4, constDouble1),
904
(double) mhGuard.invokeExact(constDouble2, constDouble3, Double.MIN_VALUE, constDouble4, constDouble1));
905
906
mtTest = methodType(boolean.class, double.class, double.class, double.class);
907
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);
908
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
909
AssertJUnit.assertEquals(verifyGuardDouble (3, Double.MAX_VALUE, constDouble3, Double.MIN_VALUE, constDouble4, constDouble1),
910
(double) mhGuard.invokeExact(Double.MAX_VALUE, constDouble3, Double.MIN_VALUE, constDouble4, constDouble1));
911
912
mtTest = methodType(boolean.class, double.class, double.class, double.class, double.class);
913
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);
914
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
915
AssertJUnit.assertEquals(verifyGuardDouble (4, constDouble1, constDouble2, constDouble3, constDouble4, constDouble5),
916
(double) mhGuard.invokeExact(constDouble1, constDouble2, constDouble3, constDouble4, constDouble5));
917
918
mtTest = methodType(boolean.class, double.class, double.class, double.class, double.class, double.class);
919
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);
920
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
921
AssertJUnit.assertEquals(verifyGuardDouble (5, Double.MIN_VALUE, constDouble3, constDouble5, constDouble4, constDouble1),
922
(double) mhGuard.invokeExact(Double.MIN_VALUE, constDouble3, constDouble5, constDouble4, constDouble1));
923
}
924
925
public static boolean testDouble () {
926
return testDoubleGen ();
927
}
928
929
public static boolean testDouble (double a) {
930
return testDoubleGen (a);
931
}
932
933
public static boolean testDouble (double a, double b) {
934
return testDoubleGen (a, b);
935
}
936
937
public static boolean testDouble (double a, double b, double c) {
938
return testDoubleGen (a, b, c);
939
}
940
941
public static boolean testDouble (double a, double b, double c, double d) {
942
return testDoubleGen (a, b, c, d);
943
}
944
945
public static boolean testDouble (double a, double b, double c, double d, double e) {
946
return testDoubleGen (a, b, c, d, e);
947
}
948
949
public static double trueTargetDouble (double a, double b, double c, double d, double e) {
950
return largestDouble (a, b, c, d, e);
951
}
952
953
public static double falseTargetDouble (double a, double b, double c, double d, double e) {
954
return smallestDouble (a, b, c, d, e);
955
}
956
957
public static boolean testDoubleGen (double... args) {
958
if (0 == args.length) {
959
return false;
960
} else {
961
double last = args [args.length - 1];
962
for (int i = 0; i < (args.length - 1); i++) {
963
if (last < args [i]) {
964
return false;
965
}
966
}
967
return true;
968
}
969
}
970
971
public static double smallestDouble (double... args) {
972
double smallest = Double.MAX_VALUE;
973
for(double arg : args) {
974
if (smallest > arg) {
975
smallest = arg;
976
}
977
}
978
return smallest;
979
}
980
981
public static double largestDouble (double... args) {
982
double largest = Double.MIN_VALUE;
983
for(double arg : args) {
984
if (largest < arg) {
985
largest = arg;
986
}
987
}
988
return largest;
989
}
990
991
public static double verifyGuardDouble (int type, double... args) {
992
double[] testArgs;
993
994
if (0 == type) {
995
testArgs = null;
996
} else {
997
testArgs = Arrays.copyOfRange(args, 0, type);
998
}
999
1000
if (null == testArgs) {
1001
return smallestDouble (args);
1002
} else {
1003
if (true == testDoubleGen(testArgs)) {
1004
return largestDouble (args);
1005
} else {
1006
return smallestDouble (args);
1007
}
1008
}
1009
}
1010
1011
/* Test guardWithTest: Ljava/lang/Double */
1012
@Test(groups = { "level.extended" })
1013
public void test_guardWithTest_DoubleObject() throws WrongMethodTypeException, Throwable {
1014
MethodType mtTrueTarget = methodType(Double.class, Double.class, Double.class, Double.class, Double.class, Double.class);
1015
MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetDoubleObject", mtTrueTarget);
1016
1017
MethodType mtFalseTarget = methodType(Double.class, Double.class, Double.class, Double.class, Double.class, Double.class);
1018
MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetDoubleObject", mtFalseTarget);
1019
1020
Double d1 = new Double (constDouble1);
1021
Double d2 = new Double (constDouble2);
1022
Double d3 = new Double (constDouble3);
1023
Double d4 = new Double (constDouble4);
1024
Double d5 = new Double (constDouble5);
1025
Double dMax = new Double (Double.MAX_VALUE);
1026
Double dMin = new Double (Double.MIN_VALUE);
1027
1028
MethodType mtTest = methodType(boolean.class);
1029
MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);
1030
MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
1031
AssertJUnit.assertEquals(verifyGuardDouble (0, d1, d2, d3, d4, dMax), (Double) mhGuard.invokeExact(d1, d2, d3, d4, dMax));
1032
1033
mtTest = methodType(boolean.class, Double.class);
1034
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);
1035
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
1036
AssertJUnit.assertEquals(verifyGuardDouble (1, d2, d3, d4, dMax, d5), (Double) mhGuard.invokeExact(d2, d3, d4, dMax, d5));
1037
1038
mtTest = methodType(boolean.class, Double.class, Double.class);
1039
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);
1040
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
1041
AssertJUnit.assertEquals(verifyGuardDouble (2, d2, d3, dMin, d4, d1), (Double) mhGuard.invokeExact(d2, d3, dMin, d4, d1));
1042
1043
mtTest = methodType(boolean.class, Double.class, Double.class, Double.class);
1044
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);
1045
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
1046
AssertJUnit.assertEquals(verifyGuardDouble (3, dMax, d3, dMin, d4, d1), (Double) mhGuard.invokeExact(dMax, d3, dMin, d4, d1));
1047
1048
mtTest = methodType(boolean.class, Double.class, Double.class, Double.class, Double.class);
1049
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);
1050
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
1051
AssertJUnit.assertEquals(verifyGuardDouble (4, d1, d2, d3, d4, d5), (Double) mhGuard.invokeExact(d1, d2, d3, d4, d5));
1052
1053
mtTest = methodType(boolean.class, Double.class, Double.class, Double.class, Double.class, Double.class);
1054
mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);
1055
mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);
1056
AssertJUnit.assertEquals(verifyGuardDouble (5, dMin, d3, d5, d4, d1), (Double) mhGuard.invokeExact(dMin, d3, d5, d4, d1));
1057
}
1058
1059
public static boolean testDoubleObject () {
1060
return testDoubleObjectGen ();
1061
}
1062
1063
public static boolean testDoubleObject (Double a) {
1064
return testDoubleObjectGen (a);
1065
}
1066
1067
public static boolean testDoubleObject (Double a, Double b) {
1068
return testDoubleObjectGen (a, b);
1069
}
1070
1071
public static boolean testDoubleObject (Double a, Double b, Double c) {
1072
return testDoubleObjectGen (a, b, c);
1073
}
1074
1075
public static boolean testDoubleObject (Double a, Double b, Double c, Double d) {
1076
return testDoubleObjectGen (a, b, c, d);
1077
}
1078
1079
public static boolean testDoubleObject (Double a, Double b, Double c, Double d, Double e) {
1080
return testDoubleObjectGen (a, b, c, d, e);
1081
}
1082
1083
public static Double trueTargetDoubleObject (Double a, Double b, Double c, Double d, Double e) {
1084
return largestDoubleObject (a, b, c, d, e);
1085
}
1086
1087
public static Double falseTargetDoubleObject (Double a, Double b, Double c, Double d, Double e) {
1088
return smallestDoubleObject (a, b, c, d, e);
1089
}
1090
1091
public static boolean testDoubleObjectGen (Double... args) {
1092
if (0 == args.length) {
1093
return false;
1094
} else {
1095
Double last = args [args.length - 1];
1096
for (int i = 0; i < (args.length - 1); i++) {
1097
if (last.doubleValue() < args[i].doubleValue()) {
1098
return false;
1099
}
1100
}
1101
return true;
1102
}
1103
}
1104
1105
public static Double smallestDoubleObject (Double... args) {
1106
Double smallest = new Double (Double.MAX_VALUE);
1107
for(Double arg : args) {
1108
if (smallest.doubleValue() > arg.doubleValue()) {
1109
smallest = arg;
1110
}
1111
}
1112
return smallest;
1113
}
1114
1115
public static Double largestDoubleObject (Double... args) {
1116
Double largest = new Double (Double.MIN_VALUE);
1117
for(Double arg : args) {
1118
if (largest.doubleValue() < arg.doubleValue()) {
1119
largest = arg;
1120
}
1121
}
1122
return largest;
1123
}
1124
1125
public static Double verifyGuardDoubleObject (int type, Double... args) {
1126
Double[] testArgs;
1127
1128
if (0 == type) {
1129
testArgs = null;
1130
} else {
1131
testArgs = Arrays.copyOfRange(args, 0, type);
1132
}
1133
1134
if (null == testArgs) {
1135
return smallestDoubleObject (args);
1136
} else {
1137
if (true == testDoubleObjectGen(testArgs)) {
1138
return largestDoubleObject (args);
1139
} else {
1140
return smallestDoubleObject (args);
1141
}
1142
}
1143
}
1144
}
1145
1146