Example usage for java.lang Short TYPE

List of usage examples for java.lang Short TYPE

Introduction

In this page you can find the example usage for java.lang Short TYPE.

Prototype

Class TYPE

To view the source code for java.lang Short TYPE.

Click Source Link

Document

The Class instance representing the primitive type short .

Usage

From source file:org.spring4gwt.server.RpcHelper.java

private static String printTypeName(Class<?> type) {
    // Primitives
    ////from w  w w.  j  av a2 s. c  o  m
    if (type.equals(Integer.TYPE)) {
        return "int";
    } else if (type.equals(Long.TYPE)) {
        return "long";
    } else if (type.equals(Short.TYPE)) {
        return "short";
    } else if (type.equals(Byte.TYPE)) {
        return "byte";
    } else if (type.equals(Character.TYPE)) {
        return "char";
    } else if (type.equals(Boolean.TYPE)) {
        return "boolean";
    } else if (type.equals(Float.TYPE)) {
        return "float";
    } else if (type.equals(Double.TYPE)) {
        return "double";
    }

    // Arrays
    //
    if (type.isArray()) {
        Class<?> componentType = type.getComponentType();
        return printTypeName(componentType) + "[]";
    }

    // Everything else
    //
    return type.getName().replace('$', '.');
}

From source file:org.briljantframework.data.Na.java

/**
 * Returns the {@code NA} value for the class {@code T}. For reference types (excluding
 * {@link Complex} and {@link Logical}) {@code NA} is represented as {@code null}, but for
 * primitive types a special convention is used.
 *
 * <ul>//w  w w  . java  2  s . c o  m
 * <li>{@code double}: {@link Na#DOUBLE}</li>
 * <li>{@code int}: {@link Na#INT}</li>
 * <li>{@code long}: {@link Long#MAX_VALUE}</li>
 * <li>{@link Logical}: {@link Logical#NA}</li>
 * <li>{@link Complex}: {@link Na#COMPLEX}</li>
 * </ul>
 *
 * @param cls the class
 * @param <T> the type of {@code cls}
 * @return a {@code NA} value of type {@code T}
 */
@SuppressWarnings("unchecked")
public static <T> T of(Class<T> cls) {
    if (cls == null) {
        return null;
    } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) {
        return (T) BOXED_DOUBLE;
    } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) {
        return (T) BOXED_FLOAT;
    } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) {
        return (T) BOXED_LONG;
    } else if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) {
        return (T) BOXED_INT;
    } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) {
        return (T) BOXED_SHORT;
    } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) {
        return (T) BOXED_BYTE;
    } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) {
        return (T) BOXED_CHAR;
    } else if (Logical.class.equals(cls)) {
        return (T) Logical.NA;
    } else if (Complex.class.equals(cls)) {
        return (T) COMPLEX;
    } else {
        return null;
    }
}

From source file:net.sf.json.JSONDynaBean.java

/**
 * DOCUMENT ME!//from   w w  w . j  ava2 s  .  c  o m
 *
 * @param name DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
public Object get(String name) {
    Object value = dynaValues.get(name);

    if (value != null) {
        return value;
    }

    Class type = getDynaProperty(name).getType();

    if (type == null) {
        throw new NullPointerException("Unspecified property type for " + name);
    }

    if (!type.isPrimitive()) {
        return value;
    }

    if (type == Boolean.TYPE) {
        return Boolean.FALSE;
    } else if (type == Byte.TYPE) {
        return new Byte((byte) 0);
    } else if (type == Character.TYPE) {
        return new Character((char) 0);
    } else if (type == Short.TYPE) {
        return new Short((short) 0);
    } else if (type == Integer.TYPE) {
        return new Integer(0);
    } else if (type == Long.TYPE) {
        return new Long(0);
    } else if (type == Float.TYPE) {
        return new Float(0.0);
    } else if (type == Double.TYPE) {
        return new Double(0);
    }

    return null;
}

From source file:demo.config.PropertyConverter.java

/**
 * Converts the specified value to the target class. If the class is a
 * primitive type (Integer.TYPE, Boolean.TYPE, etc) the value returned will
 * use the wrapper type (Integer.class, Boolean.class, etc).
 * /*from  ww w  . j  a va 2s .com*/
 * @param cls
 *            the target class of the converted value
 * @param value
 *            the value to convert
 * @param params
 *            optional parameters used for the conversion
 * @return the converted value
 * @throws ConversionException
 *             if the value is not compatible with the requested type
 * 
 * @since 1.5
 */
static Object to(Class<?> cls, Object value, Object[] params) throws ConversionException {
    if (cls.isInstance(value)) {
        return value; // no conversion needed
    }

    if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) {
        return toBoolean(value);
    } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) {
        return toCharacter(value);
    } else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) {
        if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) {
            return toInteger(value);
        } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) {
            return toLong(value);
        } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) {
            return toByte(value);
        } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) {
            return toShort(value);
        } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) {
            return toFloat(value);
        } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) {
            return toDouble(value);
        } else if (BigInteger.class.equals(cls)) {
            return toBigInteger(value);
        } else if (BigDecimal.class.equals(cls)) {
            return toBigDecimal(value);
        }
    } else if (Date.class.equals(cls)) {
        return toDate(value, (String) params[0]);
    } else if (Calendar.class.equals(cls)) {
        return toCalendar(value, (String) params[0]);
    } else if (URL.class.equals(cls)) {
        return toURL(value);
    } else if (Locale.class.equals(cls)) {
        return toLocale(value);
    } else if (isEnum(cls)) {
        return convertToEnum(cls, value);
    } else if (Color.class.equals(cls)) {
        return toColor(value);
    } else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME)) {
        return toInternetAddress(value);
    } else if (InetAddress.class.isAssignableFrom(cls)) {
        return toInetAddress(value);
    }

    throw new ConversionException("The value '" + value + "' (" + value.getClass() + ")"
            + " can't be converted to a " + cls.getName() + " object");
}

From source file:com.l2jfree.config.L2Properties.java

@SuppressWarnings("unchecked")
public Object getProperty(Class<?> expectedType, ConfigProperty configProperty) {
    final String name = configProperty.name();
    final String defaultValue = configProperty.value();

    if (expectedType == Boolean.class || expectedType == Boolean.TYPE) {
        return getBool(name, defaultValue);
    } else if (expectedType == Long.class || expectedType == Long.TYPE) {
        return getLong(name, defaultValue);
    } else if (expectedType == Integer.class || expectedType == Integer.TYPE) {
        return getInteger(name, defaultValue);
    } else if (expectedType == Short.class || expectedType == Short.TYPE) {
        return getShort(name, defaultValue);
    } else if (expectedType == Byte.class || expectedType == Byte.TYPE) {
        return getByte(name, defaultValue);
    } else if (expectedType == Double.class || expectedType == Double.TYPE) {
        return getDouble(name, defaultValue);
    } else if (expectedType == Float.class || expectedType == Float.TYPE) {
        return getFloat(name, defaultValue);
    } else if (expectedType == String.class) {
        return getString(name, defaultValue);
    } else if (expectedType.isEnum()) {
        return getEnum(name, (Class<? extends Enum>) expectedType, defaultValue);
    } else {/*from  w  ww.jav  a2s.co m*/
        throw new IllegalStateException();
    }
}

From source file:org.evosuite.testcase.fm.MethodDescriptor.java

private String initMatchers(GenericMethod method, GenericClass retvalType) {

    String matchers = "";
    Type[] types = method.getParameterTypes();
    List<GenericClass> parameterClasses = method.getParameterClasses();
    for (int i = 0; i < types.length; i++) {
        if (i > 0) {
            matchers += " , ";
        }//  www. jav  a2 s. co m

        Type type = types[i];
        GenericClass genericParameter = parameterClasses.get(i);
        if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
            matchers += "anyInt()";
        } else if (type.equals(Long.TYPE) || type.equals(Long.class)) {
            matchers += "anyLong()";
        } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
            matchers += "anyBoolean()";
        } else if (type.equals(Double.TYPE) || type.equals(Double.class)) {
            matchers += "anyDouble()";
        } else if (type.equals(Float.TYPE) || type.equals(Float.class)) {
            matchers += "anyFloat()";
        } else if (type.equals(Short.TYPE) || type.equals(Short.class)) {
            matchers += "anyShort()";
        } else if (type.equals(Character.TYPE) || type.equals(Character.class)) {
            matchers += "anyChar()";
        } else if (type.equals(String.class)) {
            matchers += "anyString()";
        } else {
            if (type.getTypeName().equals(Object.class.getName())) {
                /*
                Ideally here we should use retvalType to understand if the target class
                is using generics and if this method parameters would need to be handled
                accordingly. However, doing it does not seem so trivial...
                so a current workaround is that, when a method takes an Object as input (which is
                that would happen in case of Generics T), we use the undetermined "any()"
                 */
                matchers += "any()";
            } else {
                if (type instanceof Class) {
                    matchers += "any(" + ((Class) type).getCanonicalName() + ".class)";
                } else {
                    //what to do here? is it even possible?
                    matchers += "any(" + genericParameter.getRawClass().getCanonicalName() + ".class)";
                    // matchers += "any(" + type.getTypeName() + ".class)";
                }
            }
        }
    }

    return matchers;
}

From source file:org.hyperic.hq.plugin.jboss.MBeanUtil.java

private static void initConverters() {
    addConverter(Object.class, new Converter() {
        public Object convert(String param) {
            return param;
        }//ww w .  j a v a2  s.c  om
    });

    addConverter(Short.class, new Converter() {
        public Object convert(String param) {
            return Short.valueOf(param);
        }
    });

    addConverter(Integer.class, new Converter() {
        public Object convert(String param) {
            return Integer.valueOf(param);
        }
    });

    addConverter(Long.class, new Converter() {
        public Object convert(String param) {
            return Long.valueOf(param);
        }
    });

    addConverter(Double.class, new Converter() {
        public Object convert(String param) {
            return Double.valueOf(param);
        }
    });

    addConverter(Boolean.class, new Converter() {
        public Object convert(String param) {
            return Boolean.valueOf(param);
        }
    });

    addConverter(File.class, new Converter() {
        public Object convert(String param) {
            return new File(param);
        }
    });

    addConverter(URL.class, new Converter() {
        public Object convert(String param) {
            try {
                return new URL(param);
            } catch (MalformedURLException e) {
                throw invalid(param, e);
            }
        }
    });

    addConverter(ObjectName.class, new Converter() {
        public Object convert(String param) {
            try {
                return new ObjectName(param);
            } catch (MalformedObjectNameException e) {
                throw invalid(param, e);
            }
        }
    });

    addConverter(List.class, new ListConverter() {
        public Object convert(String[] params) {
            return Arrays.asList(params);
        }
    });

    addConverter(String[].class, new ListConverter() {
        public Object convert(String[] params) {
            return params;
        }
    });

    Class[][] aliases = { { String.class, Object.class }, { Short.TYPE, Short.class },
            { Integer.TYPE, Integer.class }, { Long.TYPE, Long.class }, { Double.TYPE, Double.class },
            { Boolean.TYPE, Boolean.class }, };

    for (int i = 0; i < aliases.length; i++) {
        addConverter(aliases[i][0], aliases[i][1]);
    }
}

From source file:com.fjn.helper.common.io.file.common.FileUpAndDownloadUtil.java

/**
 * ???????/*w ww .java  2 s  . co m*/
 * @param klass   ???klass?Class
 * @param filepath   ?
 * @param sizeThreshold   ??
 * @param isFileNameBaseTime   ????
 * @return bean
 */
public static <T> Object upload(HttpServletRequest request, Class<T> klass, String filepath, int sizeThreshold,
        boolean isFileNameBaseTime) throws Exception {
    FileItemFactory fileItemFactory = null;
    if (sizeThreshold > 0) {
        File repository = new File(filepath);
        fileItemFactory = new DiskFileItemFactory(sizeThreshold, repository);
    } else {
        fileItemFactory = new DiskFileItemFactory();
    }
    ServletFileUpload upload = new ServletFileUpload(fileItemFactory);
    ServletRequestContext requestContext = new ServletRequestContext(request);
    T bean = null;
    if (klass != null) {
        bean = klass.newInstance();
    }
    // 
    if (ServletFileUpload.isMultipartContent(requestContext)) {
        File parentDir = new File(filepath);

        List<FileItem> fileItemList = upload.parseRequest(requestContext);
        for (int i = 0; i < fileItemList.size(); i++) {
            FileItem item = fileItemList.get(i);
            // ??
            if (item.isFormField()) {
                String paramName = item.getFieldName();
                String paramValue = item.getString("UTF-8");
                log.info("?" + paramName + "=" + paramValue);
                request.setAttribute(paramName, paramValue);
                // ?bean
                if (klass != null) {
                    Field field = null;
                    try {
                        field = klass.getDeclaredField(paramName);

                        if (field != null) {
                            field.setAccessible(true);
                            Class type = field.getType();
                            if (type == Integer.TYPE) {
                                field.setInt(bean, Integer.valueOf(paramValue));
                            } else if (type == Double.TYPE) {
                                field.setDouble(bean, Double.valueOf(paramValue));
                            } else if (type == Float.TYPE) {
                                field.setFloat(bean, Float.valueOf(paramValue));
                            } else if (type == Boolean.TYPE) {
                                field.setBoolean(bean, Boolean.valueOf(paramValue));
                            } else if (type == Character.TYPE) {
                                field.setChar(bean, paramValue.charAt(0));
                            } else if (type == Long.TYPE) {
                                field.setLong(bean, Long.valueOf(paramValue));
                            } else if (type == Short.TYPE) {
                                field.setShort(bean, Short.valueOf(paramValue));
                            } else {
                                field.set(bean, paramValue);
                            }
                        }
                    } catch (NoSuchFieldException e) {
                        log.info("" + klass.getName() + "?" + paramName);
                    }
                }
            }
            // 
            else {
                // <input type='file' name='xxx'> xxx
                String paramName = item.getFieldName();
                log.info("?" + item.getSize());

                if (sizeThreshold > 0) {
                    if (item.getSize() > sizeThreshold)
                        continue;
                }
                String clientFileName = item.getName();
                int index = -1;
                // ?IE?
                if ((index = clientFileName.lastIndexOf("\\")) != -1) {
                    clientFileName = clientFileName.substring(index + 1);
                }
                if (clientFileName == null || "".equals(clientFileName))
                    continue;

                String filename = null;
                log.info("" + paramName + "\t??" + clientFileName);
                if (isFileNameBaseTime) {
                    filename = buildFileName(clientFileName);
                } else
                    filename = clientFileName;

                request.setAttribute(paramName, filename);

                // ?bean
                if (klass != null) {
                    Field field = null;
                    try {
                        field = klass.getDeclaredField(paramName);
                        if (field != null) {
                            field.setAccessible(true);
                            field.set(bean, filename);
                        }
                    } catch (NoSuchFieldException e) {
                        log.info("" + klass.getName() + "?  " + paramName);
                        continue;
                    }
                }

                if (!parentDir.exists()) {
                    parentDir.mkdirs();
                }

                File newfile = new File(parentDir, filename);
                item.write(newfile);
                String serverPath = newfile.getPath();
                log.info("?" + serverPath);
            }
        }
    }
    return bean;
}

From source file:MethodHashing.java

static String getTypeString(Class cl) {
    if (cl == Byte.TYPE) {
        return "B";
    } else if (cl == Character.TYPE) {
        return "C";
    } else if (cl == Double.TYPE) {
        return "D";
    } else if (cl == Float.TYPE) {
        return "F";
    } else if (cl == Integer.TYPE) {
        return "I";
    } else if (cl == Long.TYPE) {
        return "J";
    } else if (cl == Short.TYPE) {
        return "S";
    } else if (cl == Boolean.TYPE) {
        return "Z";
    } else if (cl == Void.TYPE) {
        return "V";
    } else if (cl.isArray()) {
        return "[" + getTypeString(cl.getComponentType());
    } else {/*from  w  w  w .  jav  a2s . c  o m*/
        return "L" + cl.getName().replace('.', '/') + ";";
    }
}

From source file:org.apache.click.util.RequestTypeConverter.java

/**
 * Return the converted value for the given value object and target type.
 *
 * @param value the value object to convert
 * @param toType the target class type to convert the value to
 * @return a converted value into the specified type
 *///from   ww  w. j a  v  a2s  .  co  m
protected Object convertValue(Object value, Class<?> toType) {
    Object result = null;

    if (value != null) {

        // If array -> array then convert components of array individually
        if (value.getClass().isArray() && toType.isArray()) {
            Class<?> componentType = toType.getComponentType();

            result = Array.newInstance(componentType, Array.getLength(value));

            for (int i = 0, icount = Array.getLength(value); i < icount; i++) {
                Array.set(result, i, convertValue(Array.get(value, i), componentType));
            }

        } else {
            if ((toType == Integer.class) || (toType == Integer.TYPE)) {
                result = Integer.valueOf((int) OgnlOps.longValue(value));

            } else if ((toType == Double.class) || (toType == Double.TYPE)) {
                result = new Double(OgnlOps.doubleValue(value));

            } else if ((toType == Boolean.class) || (toType == Boolean.TYPE)) {
                result = Boolean.valueOf(value.toString());

            } else if ((toType == Byte.class) || (toType == Byte.TYPE)) {
                result = Byte.valueOf((byte) OgnlOps.longValue(value));

            } else if ((toType == Character.class) || (toType == Character.TYPE)) {
                result = Character.valueOf((char) OgnlOps.longValue(value));

            } else if ((toType == Short.class) || (toType == Short.TYPE)) {
                result = Short.valueOf((short) OgnlOps.longValue(value));

            } else if ((toType == Long.class) || (toType == Long.TYPE)) {
                result = Long.valueOf(OgnlOps.longValue(value));

            } else if ((toType == Float.class) || (toType == Float.TYPE)) {
                result = new Float(OgnlOps.doubleValue(value));

            } else if (toType == BigInteger.class) {
                result = OgnlOps.bigIntValue(value);

            } else if (toType == BigDecimal.class) {
                result = bigDecValue(value);

            } else if (toType == String.class) {
                result = OgnlOps.stringValue(value);

            } else if (toType == java.util.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.util.Date(time);
                }

            } else if (toType == java.sql.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Date(time);
                }

            } else if (toType == java.sql.Time.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Time(time);
                }

            } else if (toType == java.sql.Timestamp.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Timestamp(time);
                }
            }
        }

    } else {
        if (toType.isPrimitive()) {
            result = OgnlRuntime.getPrimitiveDefaultValue(toType);
        }
    }
    return result;
}