< prev index next >

src/java.base/share/classes/sun/invoke/util/Wrapper.java

Print this page
rev 47762 : 8187742: Minimal set of bootstrap methods for constant dynamic
Contributed-by: brian.goetz@oracle.com, john.r.rose@oracle.com, paul.sandoz@oracle.com
Reviewed-by: forax


 256 
 257     /** Produce a zero value for the given wrapper type T.
 258      *  The optional argument must a type compatible with this wrapper.
 259      *  Equivalent to {@code this.cast(this.zero(), type)}.
 260      */
 261     public <T> T zero(Class<T> type) { return convert(zero(), type); }
 262 
 263     /** Return the wrapper that wraps values of the given type.
 264      *  The type may be {@code Object}, meaning the {@code OBJECT} wrapper.
 265      *  Otherwise, the type must be a primitive.
 266      *  @throws IllegalArgumentException for unexpected types
 267      */
 268     public static Wrapper forPrimitiveType(Class<?> type) {
 269         Wrapper w = findPrimitiveType(type);
 270         if (w != null)  return w;
 271         if (type.isPrimitive())
 272             throw new InternalError(); // redo hash function
 273         throw newIllegalArgumentException("not primitive: "+type);
 274     }
 275 



















 276     static Wrapper findPrimitiveType(Class<?> type) {
 277         Wrapper w = FROM_PRIM[hashPrim(type)];
 278         if (w != null && w.primitiveType == type) {
 279             return w;
 280         }
 281         return null;
 282     }
 283 
 284     /** Return the wrapper that wraps values into the given wrapper type.
 285      *  If it is {@code Object}, return {@code OBJECT}.
 286      *  Otherwise, it must be a wrapper type.
 287      *  The type must not be a primitive type.
 288      *  @throws IllegalArgumentException for unexpected types
 289      */
 290     public static Wrapper forWrapperType(Class<?> type) {
 291         Wrapper w = findWrapperType(type);
 292         if (w != null)  return w;
 293         for (Wrapper x : values())
 294             if (x.wrapperType == type)
 295                 throw new InternalError(); // redo hash function




 256 
 257     /** Produce a zero value for the given wrapper type T.
 258      *  The optional argument must a type compatible with this wrapper.
 259      *  Equivalent to {@code this.cast(this.zero(), type)}.
 260      */
 261     public <T> T zero(Class<T> type) { return convert(zero(), type); }
 262 
 263     /** Return the wrapper that wraps values of the given type.
 264      *  The type may be {@code Object}, meaning the {@code OBJECT} wrapper.
 265      *  Otherwise, the type must be a primitive.
 266      *  @throws IllegalArgumentException for unexpected types
 267      */
 268     public static Wrapper forPrimitiveType(Class<?> type) {
 269         Wrapper w = findPrimitiveType(type);
 270         if (w != null)  return w;
 271         if (type.isPrimitive())
 272             throw new InternalError(); // redo hash function
 273         throw newIllegalArgumentException("not primitive: "+type);
 274     }
 275 
 276     /** Return the wrapper that corresponds to the provided basic type char.
 277      *  The basic type char must be for one of the eight primitive types, or void.
 278      *  @throws IllegalArgumentException for unexpected types
 279      */
 280     public static Wrapper forPrimitiveType(char basicTypeChar) {
 281         switch (basicTypeChar) {
 282             case 'I': return INT;
 283             case 'J': return LONG;
 284             case 'S': return SHORT;
 285             case 'B': return BYTE;
 286             case 'C': return CHAR;
 287             case 'F': return FLOAT;
 288             case 'D': return DOUBLE;
 289             case 'Z': return BOOLEAN;
 290             case 'V': return VOID;
 291             default: throw newIllegalArgumentException("not primitive: " + basicTypeChar);
 292         }
 293     }
 294 
 295     static Wrapper findPrimitiveType(Class<?> type) {
 296         Wrapper w = FROM_PRIM[hashPrim(type)];
 297         if (w != null && w.primitiveType == type) {
 298             return w;
 299         }
 300         return null;
 301     }
 302 
 303     /** Return the wrapper that wraps values into the given wrapper type.
 304      *  If it is {@code Object}, return {@code OBJECT}.
 305      *  Otherwise, it must be a wrapper type.
 306      *  The type must not be a primitive type.
 307      *  @throws IllegalArgumentException for unexpected types
 308      */
 309     public static Wrapper forWrapperType(Class<?> type) {
 310         Wrapper w = findWrapperType(type);
 311         if (w != null)  return w;
 312         for (Wrapper x : values())
 313             if (x.wrapperType == type)
 314                 throw new InternalError(); // redo hash function


< prev index next >