< prev index next >

test/lib/testlibrary/jsr292/com/oracle/testlibrary/jsr292/Helper.java

Print this page




 298         if (dst == char.class || dst == Character.class) {
 299             return (char) (value);
 300         }
 301         if (dst == short.class || dst == Short.class) {
 302             return (short) (value);
 303         }
 304         if (dst == float.class || dst == Float.class) {
 305             return (float) (value);
 306         }
 307         if (dst == double.class || dst == Double.class) {
 308             return (double) (value);
 309         }
 310         if (dst == byte.class || dst == Byte.class) {
 311             return (byte) (value);
 312         }
 313         if (dst == boolean.class || dst == Boolean.class) {
 314             return ((value % 29) & 1) == 0;
 315         }
 316         return null;
 317     }





























 318 }


 298         if (dst == char.class || dst == Character.class) {
 299             return (char) (value);
 300         }
 301         if (dst == short.class || dst == Short.class) {
 302             return (short) (value);
 303         }
 304         if (dst == float.class || dst == Float.class) {
 305             return (float) (value);
 306         }
 307         if (dst == double.class || dst == Double.class) {
 308             return (double) (value);
 309         }
 310         if (dst == byte.class || dst == Byte.class) {
 311             return (byte) (value);
 312         }
 313         if (dst == boolean.class || dst == Boolean.class) {
 314             return ((value % 29) & 1) == 0;
 315         }
 316         return null;
 317     }
 318     
 319     /**
 320      * Routine used to obtain a randomly generated method type.
 321      *
 322      * @param arity Arity of returned method type.
 323      * @return MethodType generated randomly.
 324      */
 325     public static MethodType randomMethodTypeGenerator(int arity) {
 326         final Class<?>[] CLASSES = {
 327             Object.class,
 328             int.class,
 329             boolean.class,
 330             byte.class,
 331             short.class,
 332             char.class,
 333             long.class,
 334             float.class,
 335             double.class
 336         };
 337         if (arity > MAX_ARITY) {
 338             throw new IllegalArgumentException(
 339                     String.format("Arity should not exceed %d!", MAX_ARITY));
 340         }
 341         List<Class<?>> list = randomClasses(CLASSES, arity);
 342         list = getParams(list, false, arity);
 343         int i = RNG.nextInt(CLASSES.length + 1);
 344         Class<?> rtype = i == CLASSES.length ? void.class : CLASSES[i];
 345         return MethodType.methodType(rtype, list);
 346     }
 347 }
< prev index next >