Path: blob/master/test/functional/Jsr292/src/com/ibm/j9/jsr292/GuardTest.java
6007 views
/*******************************************************************************1* Copyright (c) 2014, 2018 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/21package com.ibm.j9.jsr292;2223import org.testng.annotations.Test;24import org.testng.AssertJUnit;25import static java.lang.invoke.MethodType.methodType;2627import java.lang.invoke.MethodHandle;28import java.lang.invoke.MethodHandles;29import java.lang.invoke.MethodType;30import java.lang.invoke.WrongMethodTypeException;31import java.util.Arrays;3233/*34* Testing MethodHandles.guardWithTest(MethodHandle test, MethodHandle target, MethodHandle fallback).35*36* Tests guardWithTest with the following FieldTypes for (Parameter/Return Descriptors): B, S, C, I, F, J, D, Ljava/lang/Double;37*38* For each FieldType, guardWithTest is tested for boundary and intermediate conditions.39*40* Example:41*42* Let FieldType = D43*44* target method descriptor: (DDDDD)D45* fallback method descriptor: (DDDDD)D46*47* test method descriptor variants:48* ()Z49* (D)Z50* (DD)Z51* (DDD)Z52* (DDDD)Z53* (DDDDD)Z54*/55public class GuardTest {56private final static byte constByte1 = (byte) 11;57private final static byte constByte2 = (byte) -20;58private final static byte constByte3 = (byte) 116;59private final static byte constByte4 = (byte) 63;60private final static byte constByte5 = (byte) -80;61private final static short constShort1 = (short) 30845;62private final static short constShort2 = (short) -9542;63private final static short constShort3 = (short) 12208;64private final static short constShort4 = (short) -14948;65private final static short constShort5 = (short) 30753;66private final static char constCharacter1 = (char) 1263;67private final static char constCharacter2 = (char) 34205;68private final static char constCharacter3 = (char) 1967;69private final static char constCharacter4 = (char) 19093;70private final static char constCharacter5 = (char) 42319;71private final static int constInteger1 = (int) 1556086783;72private final static int constInteger2 = (int) 817758207;73private final static int constInteger3 = (int) 369491967;74private final static int constInteger4 = (int) -1745879040;75private final static int constInteger5 = (int) -716963840;76private final static long constLong1 = (long) -7.50299697919925e+018;77private final static long constLong2 = (long) 4.06337276379503e+018;78private final static long constLong3 = (long) -8.27592726524671e+018;79private final static long constLong4 = (long) 9.0629313001297e+018;80private final static long constLong5 = (long) -1.66126531254629e+018;81private final static float constFloat1 = (float) 2.40039871833801e+038F;82private final static float constFloat2 = (float) -2.79937478910828e+038F;83private final static float constFloat3 = (float) 2.48908314427185e+038F;84private final static float constFloat4 = (float) 3.37104664480591e+038F;85private final static float constFloat5 = (float) -1.21208971838379e+038F;86private final static double constDouble1 = (double) 4.22650998259866e+307;87private final static double constDouble2 = (double) -1.66772685567259e+308;88private final static double constDouble3 = (double) -6.05942403398263e+307;89private final static double constDouble4 = (double) 4.75482373042349e+307;90private final static double constDouble5 = (double) 1.21572509364468e+308;9192/* Test guardWithTest: data-type -> byte */93@Test(groups = { "level.extended" })94public void test_guardWithTest_Byte() throws WrongMethodTypeException, Throwable {95MethodType mtTrueTarget = methodType(byte.class, byte.class, byte.class, byte.class, byte.class, byte.class);96MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetByte", mtTrueTarget);9798MethodType mtFalseTarget = methodType(byte.class, byte.class, byte.class, byte.class, byte.class, byte.class);99MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetByte", mtFalseTarget);100101MethodType mtTest = methodType(boolean.class);102MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);103MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);104AssertJUnit.assertEquals(verifyGuardByte (0, constByte1, constByte2, constByte3, constByte4, Byte.MAX_VALUE),105(byte) mhGuard.invokeExact(constByte1, constByte2, constByte3, constByte4, Byte.MAX_VALUE));106107mtTest = methodType(boolean.class, byte.class);108mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);109mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);110AssertJUnit.assertEquals(verifyGuardByte (1, constByte2, constByte3, constByte4, Byte.MAX_VALUE, constByte5),111(byte) mhGuard.invokeExact(constByte2, constByte3, constByte4, Byte.MAX_VALUE, constByte5));112113mtTest = methodType(boolean.class, byte.class, byte.class);114mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);115mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);116AssertJUnit.assertEquals(verifyGuardByte (2, constByte2, constByte3, Byte.MIN_VALUE, constByte4, constByte1),117(byte) mhGuard.invokeExact(constByte2, constByte3, Byte.MIN_VALUE, constByte4, constByte1));118119mtTest = methodType(boolean.class, byte.class, byte.class, byte.class);120mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);121mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);122AssertJUnit.assertEquals(verifyGuardByte (3, Byte.MAX_VALUE, constByte3, Byte.MIN_VALUE, constByte4, constByte1),123(byte) mhGuard.invokeExact(Byte.MAX_VALUE, constByte3, Byte.MIN_VALUE, constByte4, constByte1));124125mtTest = methodType(boolean.class, byte.class, byte.class, byte.class, byte.class);126mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);127mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);128AssertJUnit.assertEquals(verifyGuardByte (4, constByte1, constByte2, constByte3, constByte4, constByte5),129(byte) mhGuard.invokeExact(constByte1, constByte2, constByte3, constByte4, constByte5));130131mtTest = methodType(boolean.class, byte.class, byte.class, byte.class, byte.class, byte.class);132mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testByte", mtTest);133mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);134AssertJUnit.assertEquals(verifyGuardByte (5, Byte.MIN_VALUE, constByte3, constByte5, constByte4, constByte1),135(byte) mhGuard.invokeExact(Byte.MIN_VALUE, constByte3, constByte5, constByte4, constByte1));136}137138public static boolean testByte () {139return testByteGen ();140}141142public static boolean testByte (byte a) {143return testByteGen (a);144}145146public static boolean testByte (byte a, byte b) {147return testByteGen (a, b);148}149150public static boolean testByte (byte a, byte b, byte c) {151return testByteGen (a, b, c);152}153154public static boolean testByte (byte a, byte b, byte c, byte d) {155return testByteGen (a, b, c, d);156}157158public static boolean testByte (byte a, byte b, byte c, byte d, byte e) {159return testByteGen (a, b, c, d, e);160}161162public static byte trueTargetByte (byte a, byte b, byte c, byte d, byte e) {163return largestByte (a, b, c, d, e);164}165166public static byte falseTargetByte (byte a, byte b, byte c, byte d, byte e) {167return smallestByte (a, b, c, d, e);168}169170public static boolean testByteGen (byte... args) {171if (0 == args.length) {172return false;173} else {174byte last = args [args.length - 1];175for (int i = 0; i < (args.length - 1); i++) {176if (last < args [i]) {177return false;178}179}180return true;181}182}183184public static byte smallestByte (byte... args) {185byte smallest = Byte.MAX_VALUE;186for(byte arg : args) {187if (smallest > arg) {188smallest = arg;189}190}191return smallest;192}193194public static byte largestByte (byte... args) {195byte largest = Byte.MIN_VALUE;196for(byte arg : args) {197if (largest < arg) {198largest = arg;199}200}201return largest;202}203204public static byte verifyGuardByte (int type, byte... args) {205byte[] testArgs;206207if (0 == type) {208testArgs = null;209} else {210testArgs = Arrays.copyOfRange(args, 0, type);211}212213if (null == testArgs) {214return smallestByte (args);215} else {216if (true == testByteGen(testArgs)) {217return largestByte (args);218} else {219return smallestByte (args);220}221}222}223/* Test guardWithTest: data-type -> short */224@Test(groups = { "level.extended" })225public void test_guardWithTest_Short() throws WrongMethodTypeException, Throwable {226MethodType mtTrueTarget = methodType(short.class, short.class, short.class, short.class, short.class, short.class);227MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetShort", mtTrueTarget);228229MethodType mtFalseTarget = methodType(short.class, short.class, short.class, short.class, short.class, short.class);230MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetShort", mtFalseTarget);231232MethodType mtTest = methodType(boolean.class);233MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);234MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);235AssertJUnit.assertEquals(verifyGuardShort (0, constShort1, constShort2, constShort3, constShort4, Short.MAX_VALUE),236(short) mhGuard.invokeExact(constShort1, constShort2, constShort3, constShort4, Short.MAX_VALUE));237238mtTest = methodType(boolean.class, short.class);239mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);240mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);241AssertJUnit.assertEquals(verifyGuardShort (1, constShort2, constShort3, constShort4, Short.MAX_VALUE, constShort5),242(short) mhGuard.invokeExact(constShort2, constShort3, constShort4, Short.MAX_VALUE, constShort5));243244mtTest = methodType(boolean.class, short.class, short.class);245mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);246mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);247AssertJUnit.assertEquals(verifyGuardShort (2, constShort2, constShort3, Short.MIN_VALUE, constShort4, constShort1),248(short) mhGuard.invokeExact(constShort2, constShort3, Short.MIN_VALUE, constShort4, constShort1));249250mtTest = methodType(boolean.class, short.class, short.class, short.class);251mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);252mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);253AssertJUnit.assertEquals(verifyGuardShort (3, Short.MAX_VALUE, constShort3, Short.MIN_VALUE, constShort4, constShort1),254(short) mhGuard.invokeExact(Short.MAX_VALUE, constShort3, Short.MIN_VALUE, constShort4, constShort1));255256mtTest = methodType(boolean.class, short.class, short.class, short.class, short.class);257mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);258mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);259AssertJUnit.assertEquals(verifyGuardShort (4, constShort1, constShort2, constShort3, constShort4, constShort5),260(short) mhGuard.invokeExact(constShort1, constShort2, constShort3, constShort4, constShort5));261262mtTest = methodType(boolean.class, short.class, short.class, short.class, short.class, short.class);263mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testShort", mtTest);264mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);265AssertJUnit.assertEquals(verifyGuardShort (5, Short.MIN_VALUE, constShort3, constShort5, constShort4, constShort1),266(short) mhGuard.invokeExact(Short.MIN_VALUE, constShort3, constShort5, constShort4, constShort1));267}268269public static boolean testShort () {270return testShortGen ();271}272273public static boolean testShort (short a) {274return testShortGen (a);275}276277public static boolean testShort (short a, short b) {278return testShortGen (a, b);279}280281public static boolean testShort (short a, short b, short c) {282return testShortGen (a, b, c);283}284285public static boolean testShort (short a, short b, short c, short d) {286return testShortGen (a, b, c, d);287}288289public static boolean testShort (short a, short b, short c, short d, short e) {290return testShortGen (a, b, c, d, e);291}292293public static short trueTargetShort (short a, short b, short c, short d, short e) {294return largestShort (a, b, c, d, e);295}296297public static short falseTargetShort (short a, short b, short c, short d, short e) {298return smallestShort (a, b, c, d, e);299}300301public static boolean testShortGen (short... args) {302if (0 == args.length) {303return false;304} else {305short last = args [args.length - 1];306for (int i = 0; i < (args.length - 1); i++) {307if (last < args [i]) {308return false;309}310}311return true;312}313}314315public static short smallestShort (short... args) {316short smallest = Short.MAX_VALUE;317for(short arg : args) {318if (smallest > arg) {319smallest = arg;320}321}322return smallest;323}324325public static short largestShort (short... args) {326short largest = Short.MIN_VALUE;327for(short arg : args) {328if (largest < arg) {329largest = arg;330}331}332return largest;333}334335public static short verifyGuardShort (int type, short... args) {336short[] testArgs;337338if (0 == type) {339testArgs = null;340} else {341testArgs = Arrays.copyOfRange(args, 0, type);342}343344if (null == testArgs) {345return smallestShort (args);346} else {347if (true == testShortGen(testArgs)) {348return largestShort (args);349} else {350return smallestShort (args);351}352}353}354/* Test guardWithTest: data-type -> char */355@Test(groups = { "level.extended" })356public void test_guardWithTest_Character() throws WrongMethodTypeException, Throwable {357MethodType mtTrueTarget = methodType(char.class, char.class, char.class, char.class, char.class, char.class);358MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetCharacter", mtTrueTarget);359360MethodType mtFalseTarget = methodType(char.class, char.class, char.class, char.class, char.class, char.class);361MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetCharacter", mtFalseTarget);362363MethodType mtTest = methodType(boolean.class);364MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);365MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);366AssertJUnit.assertEquals(verifyGuardCharacter (0, constCharacter1, constCharacter2, constCharacter3, constCharacter4, Character.MAX_VALUE),367(char) mhGuard.invokeExact(constCharacter1, constCharacter2, constCharacter3, constCharacter4, Character.MAX_VALUE));368369mtTest = methodType(boolean.class, char.class);370mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);371mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);372AssertJUnit.assertEquals(verifyGuardCharacter (1, constCharacter2, constCharacter3, constCharacter4, Character.MAX_VALUE, constCharacter5),373(char) mhGuard.invokeExact(constCharacter2, constCharacter3, constCharacter4, Character.MAX_VALUE, constCharacter5));374375mtTest = methodType(boolean.class, char.class, char.class);376mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);377mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);378AssertJUnit.assertEquals(verifyGuardCharacter (2, constCharacter2, constCharacter3, Character.MIN_VALUE, constCharacter4, constCharacter1),379(char) mhGuard.invokeExact(constCharacter2, constCharacter3, Character.MIN_VALUE, constCharacter4, constCharacter1));380381mtTest = methodType(boolean.class, char.class, char.class, char.class);382mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);383mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);384AssertJUnit.assertEquals(verifyGuardCharacter (3, Character.MAX_VALUE, constCharacter3, Character.MIN_VALUE, constCharacter4, constCharacter1),385(char) mhGuard.invokeExact(Character.MAX_VALUE, constCharacter3, Character.MIN_VALUE, constCharacter4, constCharacter1));386387mtTest = methodType(boolean.class, char.class, char.class, char.class, char.class);388mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);389mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);390AssertJUnit.assertEquals(verifyGuardCharacter (4, constCharacter1, constCharacter2, constCharacter3, constCharacter4, constCharacter5),391(char) mhGuard.invokeExact(constCharacter1, constCharacter2, constCharacter3, constCharacter4, constCharacter5));392393mtTest = methodType(boolean.class, char.class, char.class, char.class, char.class, char.class);394mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testCharacter", mtTest);395mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);396AssertJUnit.assertEquals(verifyGuardCharacter (5, Character.MIN_VALUE, constCharacter3, constCharacter5, constCharacter4, constCharacter1),397(char) mhGuard.invokeExact(Character.MIN_VALUE, constCharacter3, constCharacter5, constCharacter4, constCharacter1));398}399400public static boolean testCharacter () {401return testCharacterGen ();402}403404public static boolean testCharacter (char a) {405return testCharacterGen (a);406}407408public static boolean testCharacter (char a, char b) {409return testCharacterGen (a, b);410}411412public static boolean testCharacter (char a, char b, char c) {413return testCharacterGen (a, b, c);414}415416public static boolean testCharacter (char a, char b, char c, char d) {417return testCharacterGen (a, b, c, d);418}419420public static boolean testCharacter (char a, char b, char c, char d, char e) {421return testCharacterGen (a, b, c, d, e);422}423424public static char trueTargetCharacter (char a, char b, char c, char d, char e) {425return largestCharacter (a, b, c, d, e);426}427428public static char falseTargetCharacter (char a, char b, char c, char d, char e) {429return smallestCharacter (a, b, c, d, e);430}431432public static boolean testCharacterGen (char... args) {433if (0 == args.length) {434return false;435} else {436char last = args [args.length - 1];437for (int i = 0; i < (args.length - 1); i++) {438if (last < args [i]) {439return false;440}441}442return true;443}444}445446public static char smallestCharacter (char... args) {447char smallest = Character.MAX_VALUE;448for(char arg : args) {449if (smallest > arg) {450smallest = arg;451}452}453return smallest;454}455456public static char largestCharacter (char... args) {457char largest = Character.MIN_VALUE;458for(char arg : args) {459if (largest < arg) {460largest = arg;461}462}463return largest;464}465466public static char verifyGuardCharacter (int type, char... args) {467char[] testArgs;468469if (0 == type) {470testArgs = null;471} else {472testArgs = Arrays.copyOfRange(args, 0, type);473}474475if (null == testArgs) {476return smallestCharacter (args);477} else {478if (true == testCharacterGen(testArgs)) {479return largestCharacter (args);480} else {481return smallestCharacter (args);482}483}484}485/* Test guardWithTest: data-type -> int */486@Test(groups = { "level.extended" })487public void test_guardWithTest_Integer() throws WrongMethodTypeException, Throwable {488MethodType mtTrueTarget = methodType(int.class, int.class, int.class, int.class, int.class, int.class);489MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetInteger", mtTrueTarget);490491MethodType mtFalseTarget = methodType(int.class, int.class, int.class, int.class, int.class, int.class);492MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetInteger", mtFalseTarget);493494MethodType mtTest = methodType(boolean.class);495MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);496MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);497AssertJUnit.assertEquals(verifyGuardInteger (0, constInteger1, constInteger2, constInteger3, constInteger4, Integer.MAX_VALUE),498(int) mhGuard.invokeExact(constInteger1, constInteger2, constInteger3, constInteger4, Integer.MAX_VALUE));499500mtTest = methodType(boolean.class, int.class);501mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);502mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);503AssertJUnit.assertEquals(verifyGuardInteger (1, constInteger2, constInteger3, constInteger4, Integer.MAX_VALUE, constInteger5),504(int) mhGuard.invokeExact(constInteger2, constInteger3, constInteger4, Integer.MAX_VALUE, constInteger5));505506mtTest = methodType(boolean.class, int.class, int.class);507mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);508mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);509AssertJUnit.assertEquals(verifyGuardInteger (2, constInteger2, constInteger3, Integer.MIN_VALUE, constInteger4, constInteger1),510(int) mhGuard.invokeExact(constInteger2, constInteger3, Integer.MIN_VALUE, constInteger4, constInteger1));511512mtTest = methodType(boolean.class, int.class, int.class, int.class);513mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);514mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);515AssertJUnit.assertEquals(verifyGuardInteger (3, Integer.MAX_VALUE, constInteger3, Integer.MIN_VALUE, constInteger4, constInteger1),516(int) mhGuard.invokeExact(Integer.MAX_VALUE, constInteger3, Integer.MIN_VALUE, constInteger4, constInteger1));517518mtTest = methodType(boolean.class, int.class, int.class, int.class, int.class);519mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);520mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);521AssertJUnit.assertEquals(verifyGuardInteger (4, constInteger1, constInteger2, constInteger3, constInteger4, constInteger5),522(int) mhGuard.invokeExact(constInteger1, constInteger2, constInteger3, constInteger4, constInteger5));523524mtTest = methodType(boolean.class, int.class, int.class, int.class, int.class, int.class);525mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testInteger", mtTest);526mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);527AssertJUnit.assertEquals(verifyGuardInteger (5, Integer.MIN_VALUE, constInteger3, constInteger5, constInteger4, constInteger1),528(int) mhGuard.invokeExact(Integer.MIN_VALUE, constInteger3, constInteger5, constInteger4, constInteger1));529}530531public static boolean testInteger () {532return testIntegerGen ();533}534535public static boolean testInteger (int a) {536return testIntegerGen (a);537}538539public static boolean testInteger (int a, int b) {540return testIntegerGen (a, b);541}542543public static boolean testInteger (int a, int b, int c) {544return testIntegerGen (a, b, c);545}546547public static boolean testInteger (int a, int b, int c, int d) {548return testIntegerGen (a, b, c, d);549}550551public static boolean testInteger (int a, int b, int c, int d, int e) {552return testIntegerGen (a, b, c, d, e);553}554555public static int trueTargetInteger (int a, int b, int c, int d, int e) {556return largestInteger (a, b, c, d, e);557}558559public static int falseTargetInteger (int a, int b, int c, int d, int e) {560return smallestInteger (a, b, c, d, e);561}562563public static boolean testIntegerGen (int... args) {564if (0 == args.length) {565return false;566} else {567int last = args [args.length - 1];568for (int i = 0; i < (args.length - 1); i++) {569if (last < args [i]) {570return false;571}572}573return true;574}575}576577public static int smallestInteger (int... args) {578int smallest = Integer.MAX_VALUE;579for(int arg : args) {580if (smallest > arg) {581smallest = arg;582}583}584return smallest;585}586587public static int largestInteger (int... args) {588int largest = Integer.MIN_VALUE;589for(int arg : args) {590if (largest < arg) {591largest = arg;592}593}594return largest;595}596597public static int verifyGuardInteger (int type, int... args) {598int[] testArgs;599600if (0 == type) {601testArgs = null;602} else {603testArgs = Arrays.copyOfRange(args, 0, type);604}605606if (null == testArgs) {607return smallestInteger (args);608} else {609if (true == testIntegerGen(testArgs)) {610return largestInteger (args);611} else {612return smallestInteger (args);613}614}615}616/* Test guardWithTest: data-type -> long */617@Test(groups = { "level.extended" })618public void test_guardWithTest_Long() throws WrongMethodTypeException, Throwable {619MethodType mtTrueTarget = methodType(long.class, long.class, long.class, long.class, long.class, long.class);620MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetLong", mtTrueTarget);621622MethodType mtFalseTarget = methodType(long.class, long.class, long.class, long.class, long.class, long.class);623MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetLong", mtFalseTarget);624625MethodType mtTest = methodType(boolean.class);626MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);627MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);628AssertJUnit.assertEquals(verifyGuardLong (0, constLong1, constLong2, constLong3, constLong4, Long.MAX_VALUE),629(long) mhGuard.invokeExact(constLong1, constLong2, constLong3, constLong4, Long.MAX_VALUE));630631mtTest = methodType(boolean.class, long.class);632mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);633mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);634AssertJUnit.assertEquals(verifyGuardLong (1, constLong2, constLong3, constLong4, Long.MAX_VALUE, constLong5),635(long) mhGuard.invokeExact(constLong2, constLong3, constLong4, Long.MAX_VALUE, constLong5));636637mtTest = methodType(boolean.class, long.class, long.class);638mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);639mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);640AssertJUnit.assertEquals(verifyGuardLong (2, constLong2, constLong3, Long.MIN_VALUE, constLong4, constLong1),641(long) mhGuard.invokeExact(constLong2, constLong3, Long.MIN_VALUE, constLong4, constLong1));642643mtTest = methodType(boolean.class, long.class, long.class, long.class);644mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);645mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);646AssertJUnit.assertEquals(verifyGuardLong (3, Long.MAX_VALUE, constLong3, Long.MIN_VALUE, constLong4, constLong1),647(long) mhGuard.invokeExact(Long.MAX_VALUE, constLong3, Long.MIN_VALUE, constLong4, constLong1));648649mtTest = methodType(boolean.class, long.class, long.class, long.class, long.class);650mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);651mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);652AssertJUnit.assertEquals(verifyGuardLong (4, constLong1, constLong2, constLong3, constLong4, constLong5),653(long) mhGuard.invokeExact(constLong1, constLong2, constLong3, constLong4, constLong5));654655mtTest = methodType(boolean.class, long.class, long.class, long.class, long.class, long.class);656mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testLong", mtTest);657mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);658AssertJUnit.assertEquals(verifyGuardLong (5, Long.MIN_VALUE, constLong3, constLong5, constLong4, constLong1),659(long) mhGuard.invokeExact(Long.MIN_VALUE, constLong3, constLong5, constLong4, constLong1));660}661662public static boolean testLong () {663return testLongGen ();664}665666public static boolean testLong (long a) {667return testLongGen (a);668}669670public static boolean testLong (long a, long b) {671return testLongGen (a, b);672}673674public static boolean testLong (long a, long b, long c) {675return testLongGen (a, b, c);676}677678public static boolean testLong (long a, long b, long c, long d) {679return testLongGen (a, b, c, d);680}681682public static boolean testLong (long a, long b, long c, long d, long e) {683return testLongGen (a, b, c, d, e);684}685686public static long trueTargetLong (long a, long b, long c, long d, long e) {687return largestLong (a, b, c, d, e);688}689690public static long falseTargetLong (long a, long b, long c, long d, long e) {691return smallestLong (a, b, c, d, e);692}693694public static boolean testLongGen (long... args) {695if (0 == args.length) {696return false;697} else {698long last = args [args.length - 1];699for (int i = 0; i < (args.length - 1); i++) {700if (last < args [i]) {701return false;702}703}704return true;705}706}707708public static long smallestLong (long... args) {709long smallest = Long.MAX_VALUE;710for(long arg : args) {711if (smallest > arg) {712smallest = arg;713}714}715return smallest;716}717718public static long largestLong (long... args) {719long largest = Long.MIN_VALUE;720for(long arg : args) {721if (largest < arg) {722largest = arg;723}724}725return largest;726}727728public static long verifyGuardLong (int type, long... args) {729long[] testArgs;730731if (0 == type) {732testArgs = null;733} else {734testArgs = Arrays.copyOfRange(args, 0, type);735}736737if (null == testArgs) {738return smallestLong (args);739} else {740if (true == testLongGen(testArgs)) {741return largestLong (args);742} else {743return smallestLong (args);744}745}746}747/* Test guardWithTest: data-type -> float */748@Test(groups = { "level.extended" })749public void test_guardWithTest_Float() throws WrongMethodTypeException, Throwable {750MethodType mtTrueTarget = methodType(float.class, float.class, float.class, float.class, float.class, float.class);751MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetFloat", mtTrueTarget);752753MethodType mtFalseTarget = methodType(float.class, float.class, float.class, float.class, float.class, float.class);754MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetFloat", mtFalseTarget);755756MethodType mtTest = methodType(boolean.class);757MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);758MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);759AssertJUnit.assertEquals(verifyGuardFloat (0, constFloat1, constFloat2, constFloat3, constFloat4, Float.MAX_VALUE),760(float) mhGuard.invokeExact(constFloat1, constFloat2, constFloat3, constFloat4, Float.MAX_VALUE));761762mtTest = methodType(boolean.class, float.class);763mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);764mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);765AssertJUnit.assertEquals(verifyGuardFloat (1, constFloat2, constFloat3, constFloat4, Float.MAX_VALUE, constFloat5),766(float) mhGuard.invokeExact(constFloat2, constFloat3, constFloat4, Float.MAX_VALUE, constFloat5));767768mtTest = methodType(boolean.class, float.class, float.class);769mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);770mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);771AssertJUnit.assertEquals(verifyGuardFloat (2, constFloat2, constFloat3, Float.MIN_VALUE, constFloat4, constFloat1),772(float) mhGuard.invokeExact(constFloat2, constFloat3, Float.MIN_VALUE, constFloat4, constFloat1));773774mtTest = methodType(boolean.class, float.class, float.class, float.class);775mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);776mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);777AssertJUnit.assertEquals(verifyGuardFloat (3, Float.MAX_VALUE, constFloat3, Float.MIN_VALUE, constFloat4, constFloat1),778(float) mhGuard.invokeExact(Float.MAX_VALUE, constFloat3, Float.MIN_VALUE, constFloat4, constFloat1));779780mtTest = methodType(boolean.class, float.class, float.class, float.class, float.class);781mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);782mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);783AssertJUnit.assertEquals(verifyGuardFloat (4, constFloat1, constFloat2, constFloat3, constFloat4, constFloat5),784(float) mhGuard.invokeExact(constFloat1, constFloat2, constFloat3, constFloat4, constFloat5));785786mtTest = methodType(boolean.class, float.class, float.class, float.class, float.class, float.class);787mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testFloat", mtTest);788mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);789AssertJUnit.assertEquals(verifyGuardFloat (5, Float.MIN_VALUE, constFloat3, constFloat5, constFloat4, constFloat1),790(float) mhGuard.invokeExact(Float.MIN_VALUE, constFloat3, constFloat5, constFloat4, constFloat1));791}792793public static boolean testFloat () {794return testFloatGen ();795}796797public static boolean testFloat (float a) {798return testFloatGen (a);799}800801public static boolean testFloat (float a, float b) {802return testFloatGen (a, b);803}804805public static boolean testFloat (float a, float b, float c) {806return testFloatGen (a, b, c);807}808809public static boolean testFloat (float a, float b, float c, float d) {810return testFloatGen (a, b, c, d);811}812813public static boolean testFloat (float a, float b, float c, float d, float e) {814return testFloatGen (a, b, c, d, e);815}816817public static float trueTargetFloat (float a, float b, float c, float d, float e) {818return largestFloat (a, b, c, d, e);819}820821public static float falseTargetFloat (float a, float b, float c, float d, float e) {822return smallestFloat (a, b, c, d, e);823}824825public static boolean testFloatGen (float... args) {826if (0 == args.length) {827return false;828} else {829float last = args [args.length - 1];830for (int i = 0; i < (args.length - 1); i++) {831if (last < args [i]) {832return false;833}834}835return true;836}837}838839public static float smallestFloat (float... args) {840float smallest = Float.MAX_VALUE;841for(float arg : args) {842if (smallest > arg) {843smallest = arg;844}845}846return smallest;847}848849public static float largestFloat (float... args) {850float largest = Float.MIN_VALUE;851for(float arg : args) {852if (largest < arg) {853largest = arg;854}855}856return largest;857}858859public static float verifyGuardFloat (int type, float... args) {860float[] testArgs;861862if (0 == type) {863testArgs = null;864} else {865testArgs = Arrays.copyOfRange(args, 0, type);866}867868if (null == testArgs) {869return smallestFloat (args);870} else {871if (true == testFloatGen(testArgs)) {872return largestFloat (args);873} else {874return smallestFloat (args);875}876}877}878/* Test guardWithTest: data-type -> double */879@Test(groups = { "level.extended" })880public void test_guardWithTest_Double() throws WrongMethodTypeException, Throwable {881MethodType mtTrueTarget = methodType(double.class, double.class, double.class, double.class, double.class, double.class);882MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetDouble", mtTrueTarget);883884MethodType mtFalseTarget = methodType(double.class, double.class, double.class, double.class, double.class, double.class);885MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetDouble", mtFalseTarget);886887MethodType mtTest = methodType(boolean.class);888MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);889MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);890AssertJUnit.assertEquals(verifyGuardDouble (0, constDouble1, constDouble2, constDouble3, constDouble4, Double.MAX_VALUE),891(double) mhGuard.invokeExact(constDouble1, constDouble2, constDouble3, constDouble4, Double.MAX_VALUE));892893mtTest = methodType(boolean.class, double.class);894mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);895mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);896AssertJUnit.assertEquals(verifyGuardDouble (1, constDouble2, constDouble3, constDouble4, Double.MAX_VALUE, constDouble5),897(double) mhGuard.invokeExact(constDouble2, constDouble3, constDouble4, Double.MAX_VALUE, constDouble5));898899mtTest = methodType(boolean.class, double.class, double.class);900mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);901mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);902AssertJUnit.assertEquals(verifyGuardDouble (2, constDouble2, constDouble3, Double.MIN_VALUE, constDouble4, constDouble1),903(double) mhGuard.invokeExact(constDouble2, constDouble3, Double.MIN_VALUE, constDouble4, constDouble1));904905mtTest = methodType(boolean.class, double.class, double.class, double.class);906mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);907mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);908AssertJUnit.assertEquals(verifyGuardDouble (3, Double.MAX_VALUE, constDouble3, Double.MIN_VALUE, constDouble4, constDouble1),909(double) mhGuard.invokeExact(Double.MAX_VALUE, constDouble3, Double.MIN_VALUE, constDouble4, constDouble1));910911mtTest = methodType(boolean.class, double.class, double.class, double.class, double.class);912mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);913mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);914AssertJUnit.assertEquals(verifyGuardDouble (4, constDouble1, constDouble2, constDouble3, constDouble4, constDouble5),915(double) mhGuard.invokeExact(constDouble1, constDouble2, constDouble3, constDouble4, constDouble5));916917mtTest = methodType(boolean.class, double.class, double.class, double.class, double.class, double.class);918mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDouble", mtTest);919mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);920AssertJUnit.assertEquals(verifyGuardDouble (5, Double.MIN_VALUE, constDouble3, constDouble5, constDouble4, constDouble1),921(double) mhGuard.invokeExact(Double.MIN_VALUE, constDouble3, constDouble5, constDouble4, constDouble1));922}923924public static boolean testDouble () {925return testDoubleGen ();926}927928public static boolean testDouble (double a) {929return testDoubleGen (a);930}931932public static boolean testDouble (double a, double b) {933return testDoubleGen (a, b);934}935936public static boolean testDouble (double a, double b, double c) {937return testDoubleGen (a, b, c);938}939940public static boolean testDouble (double a, double b, double c, double d) {941return testDoubleGen (a, b, c, d);942}943944public static boolean testDouble (double a, double b, double c, double d, double e) {945return testDoubleGen (a, b, c, d, e);946}947948public static double trueTargetDouble (double a, double b, double c, double d, double e) {949return largestDouble (a, b, c, d, e);950}951952public static double falseTargetDouble (double a, double b, double c, double d, double e) {953return smallestDouble (a, b, c, d, e);954}955956public static boolean testDoubleGen (double... args) {957if (0 == args.length) {958return false;959} else {960double last = args [args.length - 1];961for (int i = 0; i < (args.length - 1); i++) {962if (last < args [i]) {963return false;964}965}966return true;967}968}969970public static double smallestDouble (double... args) {971double smallest = Double.MAX_VALUE;972for(double arg : args) {973if (smallest > arg) {974smallest = arg;975}976}977return smallest;978}979980public static double largestDouble (double... args) {981double largest = Double.MIN_VALUE;982for(double arg : args) {983if (largest < arg) {984largest = arg;985}986}987return largest;988}989990public static double verifyGuardDouble (int type, double... args) {991double[] testArgs;992993if (0 == type) {994testArgs = null;995} else {996testArgs = Arrays.copyOfRange(args, 0, type);997}998999if (null == testArgs) {1000return smallestDouble (args);1001} else {1002if (true == testDoubleGen(testArgs)) {1003return largestDouble (args);1004} else {1005return smallestDouble (args);1006}1007}1008}10091010/* Test guardWithTest: Ljava/lang/Double */1011@Test(groups = { "level.extended" })1012public void test_guardWithTest_DoubleObject() throws WrongMethodTypeException, Throwable {1013MethodType mtTrueTarget = methodType(Double.class, Double.class, Double.class, Double.class, Double.class, Double.class);1014MethodHandle mhTrueTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "trueTargetDoubleObject", mtTrueTarget);10151016MethodType mtFalseTarget = methodType(Double.class, Double.class, Double.class, Double.class, Double.class, Double.class);1017MethodHandle mhFalseTarget = MethodHandles.publicLookup().findStatic(GuardTest.class, "falseTargetDoubleObject", mtFalseTarget);10181019Double d1 = new Double (constDouble1);1020Double d2 = new Double (constDouble2);1021Double d3 = new Double (constDouble3);1022Double d4 = new Double (constDouble4);1023Double d5 = new Double (constDouble5);1024Double dMax = new Double (Double.MAX_VALUE);1025Double dMin = new Double (Double.MIN_VALUE);10261027MethodType mtTest = methodType(boolean.class);1028MethodHandle mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);1029MethodHandle mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);1030AssertJUnit.assertEquals(verifyGuardDouble (0, d1, d2, d3, d4, dMax), (Double) mhGuard.invokeExact(d1, d2, d3, d4, dMax));10311032mtTest = methodType(boolean.class, Double.class);1033mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);1034mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);1035AssertJUnit.assertEquals(verifyGuardDouble (1, d2, d3, d4, dMax, d5), (Double) mhGuard.invokeExact(d2, d3, d4, dMax, d5));10361037mtTest = methodType(boolean.class, Double.class, Double.class);1038mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);1039mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);1040AssertJUnit.assertEquals(verifyGuardDouble (2, d2, d3, dMin, d4, d1), (Double) mhGuard.invokeExact(d2, d3, dMin, d4, d1));10411042mtTest = methodType(boolean.class, Double.class, Double.class, Double.class);1043mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);1044mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);1045AssertJUnit.assertEquals(verifyGuardDouble (3, dMax, d3, dMin, d4, d1), (Double) mhGuard.invokeExact(dMax, d3, dMin, d4, d1));10461047mtTest = methodType(boolean.class, Double.class, Double.class, Double.class, Double.class);1048mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);1049mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);1050AssertJUnit.assertEquals(verifyGuardDouble (4, d1, d2, d3, d4, d5), (Double) mhGuard.invokeExact(d1, d2, d3, d4, d5));10511052mtTest = methodType(boolean.class, Double.class, Double.class, Double.class, Double.class, Double.class);1053mhTest = MethodHandles.publicLookup().findStatic(GuardTest.class, "testDoubleObject", mtTest);1054mhGuard = MethodHandles.guardWithTest(mhTest, mhTrueTarget, mhFalseTarget);1055AssertJUnit.assertEquals(verifyGuardDouble (5, dMin, d3, d5, d4, d1), (Double) mhGuard.invokeExact(dMin, d3, d5, d4, d1));1056}10571058public static boolean testDoubleObject () {1059return testDoubleObjectGen ();1060}10611062public static boolean testDoubleObject (Double a) {1063return testDoubleObjectGen (a);1064}10651066public static boolean testDoubleObject (Double a, Double b) {1067return testDoubleObjectGen (a, b);1068}10691070public static boolean testDoubleObject (Double a, Double b, Double c) {1071return testDoubleObjectGen (a, b, c);1072}10731074public static boolean testDoubleObject (Double a, Double b, Double c, Double d) {1075return testDoubleObjectGen (a, b, c, d);1076}10771078public static boolean testDoubleObject (Double a, Double b, Double c, Double d, Double e) {1079return testDoubleObjectGen (a, b, c, d, e);1080}10811082public static Double trueTargetDoubleObject (Double a, Double b, Double c, Double d, Double e) {1083return largestDoubleObject (a, b, c, d, e);1084}10851086public static Double falseTargetDoubleObject (Double a, Double b, Double c, Double d, Double e) {1087return smallestDoubleObject (a, b, c, d, e);1088}10891090public static boolean testDoubleObjectGen (Double... args) {1091if (0 == args.length) {1092return false;1093} else {1094Double last = args [args.length - 1];1095for (int i = 0; i < (args.length - 1); i++) {1096if (last.doubleValue() < args[i].doubleValue()) {1097return false;1098}1099}1100return true;1101}1102}11031104public static Double smallestDoubleObject (Double... args) {1105Double smallest = new Double (Double.MAX_VALUE);1106for(Double arg : args) {1107if (smallest.doubleValue() > arg.doubleValue()) {1108smallest = arg;1109}1110}1111return smallest;1112}11131114public static Double largestDoubleObject (Double... args) {1115Double largest = new Double (Double.MIN_VALUE);1116for(Double arg : args) {1117if (largest.doubleValue() < arg.doubleValue()) {1118largest = arg;1119}1120}1121return largest;1122}11231124public static Double verifyGuardDoubleObject (int type, Double... args) {1125Double[] testArgs;11261127if (0 == type) {1128testArgs = null;1129} else {1130testArgs = Arrays.copyOfRange(args, 0, type);1131}11321133if (null == testArgs) {1134return smallestDoubleObject (args);1135} else {1136if (true == testDoubleObjectGen(testArgs)) {1137return largestDoubleObject (args);1138} else {1139return smallestDoubleObject (args);1140}1141}1142}1143}114411451146