List of usage examples for java.lang Character TYPE
Class TYPE
To view the source code for java.lang Character TYPE.
Click Source Link
From source file:com.github.jknack.handlebars.helper.MethodHelper.java
/** * Wrap (if possible) a primitive type to their wrapper. * * @param type The candidate type.// w w w . j a v a2 s . co m * @return A wrapper for the primitive type or the original type. */ private static Class<?> wrap(final Class<?> type) { if (type.isPrimitive()) { if (type == Integer.TYPE) { return Integer.class; } else if (type == Boolean.TYPE) { return Boolean.class; } else if (type == Character.TYPE) { return Character.class; } else if (type == Double.TYPE) { return Double.class; } else if (type == Long.TYPE) { return Long.class; } else if (type == Float.TYPE) { return Float.class; } else if (type == Short.TYPE) { return Short.class; } else if (type == Byte.TYPE) { return Byte.class; } } return type; }
From source file:de.micromata.genome.util.strings.converter.StandardStringConverter.java
@Override public char getTypeChar(Object value) { if (value == null) { return ConvertedStringTypes.NULL.getShortType(); }/*from ww w . ja v a 2 s. c om*/ Class<?> cls = value.getClass(); if (value instanceof String) { return ConvertedStringTypes.STRING.getShortType(); } Class<?> vclass = value.getClass(); if (value instanceof Boolean || vclass == Boolean.TYPE) { return ConvertedStringTypes.BOOLEAN.getShortType(); } if (value instanceof Byte || vclass == Byte.TYPE) { return ConvertedStringTypes.BYTE.getShortType(); } if (value instanceof Short || vclass == Short.TYPE) { return ConvertedStringTypes.SHORT.getShortType(); } if (value instanceof Integer || vclass == Integer.TYPE) { return ConvertedStringTypes.INTEGER.getShortType(); } if (value instanceof Long || vclass == Long.TYPE) { return ConvertedStringTypes.LONG.getShortType(); } if (value instanceof Float || vclass == Float.TYPE) { return ConvertedStringTypes.FLOAT.getShortType(); } if (value instanceof Double || vclass == Double.TYPE) { return ConvertedStringTypes.DOUBLE.getShortType(); } if (value instanceof Character || vclass == Character.TYPE) { return ConvertedStringTypes.CHAR.getShortType(); } if (value instanceof Date) { return ConvertedStringTypes.DATE.getShortType(); } if (value instanceof BigDecimal) { return ConvertedStringTypes.BIGDECIMAL.getShortType(); } if (value instanceof Character) { return ConvertedStringTypes.CHAR.getShortType(); } if (value instanceof byte[]) { return ConvertedStringTypes.BYTEARRAY.getShortType(); } if (value instanceof String[]) { return ConvertedStringTypes.STRINGARRAY.getShortType(); } if (value instanceof Long[]) { return ConvertedStringTypes.LONGARRAY.getShortType(); } // if (value instanceof Serializable) // return ConvertedStringTypes.XMLOBJECT; return ConvertedStringTypes.CUSTOM.getShortType(); }
From source file:org.romaframework.core.schema.SchemaClassElement.java
@SuppressWarnings({ "rawtypes", "unchecked" }) protected Object convertValue(Object iFieldValue, SchemaClassDefinition expectedType) { if (expectedType == null || expectedType.getSchemaClass().isArray()) return iFieldValue; SchemaClass typeClass = expectedType.getSchemaClass(); if (typeClass.equals(Roma.schema().getSchemaClass(iFieldValue))) return iFieldValue; String textValue = null;/* w w w.jav a 2 s . c o m*/ if (iFieldValue instanceof String) { textValue = (String) iFieldValue; } else if (iFieldValue != null) { textValue = iFieldValue.toString(); } Object value = null; if (textValue != null) { // TRY A SOFT CONVERSION if (typeClass.isOfType(Integer.class) || typeClass.isOfType(Integer.TYPE)) { try { value = textValue.equals("") ? null : Integer.parseInt(textValue); } catch (Exception e) { value = textValue.equals("") ? null : Double.valueOf(textValue).intValue(); } } else if (typeClass.isOfType(Long.class) || typeClass.isOfType(Long.TYPE)) { value = textValue.equals("") ? null : Long.parseLong(textValue); } else if (typeClass.isOfType(Short.class) || typeClass.isOfType(Short.TYPE)) { value = textValue.equals("") ? null : Short.parseShort(textValue); } else if (typeClass.isOfType(Byte.class) || typeClass.isOfType(Byte.TYPE)) { value = textValue.equals("") ? null : Byte.parseByte(textValue); } else if (typeClass.isOfType(Character.class) || typeClass.isOfType(Character.TYPE)) { if (textValue.length() > 0) { value = new Character(textValue.charAt(0)); } } else if (typeClass.isOfType(Float.class) || typeClass.isOfType(Float.TYPE)) { value = textValue.equals("") ? null : Float.parseFloat(textValue); } else if (typeClass.isOfType(Double.class) || typeClass.isOfType(Double.TYPE)) { value = textValue.equals("") ? null : Double.parseDouble(textValue); } else if (typeClass.isOfType(BigDecimal.class)) { value = textValue.equals("") ? null : new BigDecimal(textValue); } else if (iFieldValue != null && !typeClass.isArray() && iFieldValue.getClass().isArray()) { // DESTINATION VALUE IS NOT AN ARRAY: ASSIGN THE FIRST ONE ELEMENT value = ((Object[]) iFieldValue)[0]; } else if (typeClass.isEnum()) { value = Enum.valueOf((Class) typeClass.getLanguageType(), textValue.toUpperCase()); } else { value = iFieldValue; } } if (value != null) { // TODO is this the right place to do this...? Class<?> valueClass = value.getClass(); // SUCH A MONSTER!!! MOVE THIS LOGIC IN SchemaClass.isAssignableFrom... if (value instanceof VirtualObject && !(typeClass.getLanguageType() instanceof Class<?> && ((Class<?>) typeClass.getLanguageType()).isAssignableFrom(VirtualObject.class)) && ((VirtualObject) value).getSuperClassObject() != null) { if (ComposedEntity.class .isAssignableFrom(((VirtualObject) value).getSuperClassObject().getClass())) { value = ((VirtualObject) value).getSuperClassObject(); valueClass = value.getClass(); } } if (value instanceof ComposedEntity<?> && !typeClass.isAssignableFrom(valueClass)) { value = ((ComposedEntity<?>) value).getEntity(); } } if (value == null && typeClass.isPrimitive()) { log.warn("Cannot set the field value to null for primitive types! Field: " + getEntity() + "." + name + " of class " + expectedType.getName() + ". Setting value to 0."); // SET THE VALUE TO 0 value = SchemaHelper.assignDefaultValueToLiteral(typeClass); } return value; }
From source file:net.sf.json.JSONDynaBean.java
/** * DOCUMENT ME!// w w w .java 2s . 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:com.fjn.helper.common.io.file.common.FileUpAndDownloadUtil.java
/** * ???????/*from w w w.j av a2 s .c o 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 {// www . ja v a2 s .c o m return "L" + cl.getName().replace('.', '/') + ";"; } }
From source file:org.eclipse.gyrex.monitoring.internal.mbeans.MetricSetMBean.java
private OpenType detectType(final Class type) { if ((Long.class == type) || (Long.TYPE == type)) { return SimpleType.LONG; } else if ((Integer.class == type) || (Integer.TYPE == type)) { return SimpleType.INTEGER; } else if ((Double.class == type) || (Double.TYPE == type)) { return SimpleType.DOUBLE; } else if ((Float.class == type) || (Float.TYPE == type)) { return SimpleType.FLOAT; } else if ((Byte.class == type) || (Byte.TYPE == type)) { return SimpleType.BYTE; } else if ((Short.class == type) || (Short.TYPE == type)) { return SimpleType.SHORT; } else if ((Boolean.class == type) || (Boolean.TYPE == type)) { return SimpleType.BOOLEAN; } else if (BigDecimal.class == type) { return SimpleType.BIGDECIMAL; } else if (BigInteger.class == type) { return SimpleType.BIGINTEGER; } else if ((Character.class == type) || (Character.TYPE == type)) { return SimpleType.CHARACTER; }/* w ww . j a v a 2 s .c om*/ // last fallback to strings if (isConvertibleToString(type)) { return SimpleType.STRING; } // give up return null; }
From source file:org.openflexo.antar.binding.TypeUtils.java
public static Class toPrimitive(Class<?> aClass) { if (isDouble(aClass)) { return Double.TYPE; }//w w w .ja v a 2s . c o m if (isFloat(aClass)) { return Float.TYPE; } if (isLong(aClass)) { return Long.TYPE; } if (isInteger(aClass)) { return Integer.TYPE; } if (isShort(aClass)) { return Short.TYPE; } if (isByte(aClass)) { return Byte.TYPE; } if (isBoolean(aClass)) { return Boolean.TYPE; } if (isChar(aClass)) { return Character.TYPE; } return aClass; }
From source file:org.spring4gwt.server.RpcHelper.java
private static String printTypeName(Class<?> type) { // Primitives ////from w ww . 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>//from w w w . ja va 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; } }