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:net.sourceforge.pmd.typeresolution.ClassTypeResolverTest.java
@Test public void testLiterals() throws JaxenException { ASTCompilationUnit acu = parseAndTypeResolveForClass15(Literals.class); List<ASTLiteral> literals = convertList(acu.findChildNodesWithXPath("//Literal"), ASTLiteral.class); int index = 0; // String s = "s"; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(String.class, literals.get(index++).getType()); // boolean boolean1 = false; assertEquals(Boolean.TYPE, literals.get(index).getFirstDescendantOfType(ASTBooleanLiteral.class).getType()); assertEquals(Boolean.TYPE, literals.get(index++).getType()); // boolean boolean2 = true; assertEquals(Boolean.TYPE, literals.get(index).getFirstDescendantOfType(ASTBooleanLiteral.class).getType()); assertEquals(Boolean.TYPE, literals.get(index++).getType()); // Object obj = null; assertNull(literals.get(index).getFirstDescendantOfType(ASTNullLiteral.class).getType()); assertNull(literals.get(index++).getType()); // byte byte1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // byte byte2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // byte byte3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // short short1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // short short2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // short short3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char3 = 007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char4 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // int int1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // int int2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // int int3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // int int4 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // long long1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // long long2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // long long3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // long long4 = 0L; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Long.TYPE, literals.get(index++).getType()); // long long5 = 0x0Fl; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Long.TYPE, literals.get(index++).getType()); // long long6 = -007L; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Long.TYPE, literals.get(index++).getType()); // long long7 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // float float1 = 0.0f; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Float.TYPE, literals.get(index++).getType()); // float float2 = -10e+01f; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Float.TYPE, literals.get(index++).getType()); // float float3 = 0x08.08p3f; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Float.TYPE, literals.get(index++).getType()); // float float4 = 0xFF; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // float float5 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // double double1 = 0.0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Double.TYPE, literals.get(index++).getType()); // double double2 = -10e+01; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Double.TYPE, literals.get(index++).getType()); // double double3 = 0x08.08p3; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Double.TYPE, literals.get(index++).getType()); // double double4 = 0xFF; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // double double5 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // Make sure we got them all. assertEquals("All literals not tested", index, literals.size()); }
From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java
/** * Tests if obj is a String or a char//from ww w. j a va2 s .c o m */ public static boolean isString(Object obj) { if ((obj instanceof String) || (obj instanceof Character) || (obj != null && (obj.getClass() == Character.TYPE || String.class.isAssignableFrom(obj.getClass())))) { return true; } return false; }
From source file:org.cloudata.core.common.io.CObjectWritable.java
/** Read a {@link CWritable}, {@link String}, primitive type, or an array of * the preceding. */// w ww.ja v a 2 s .c om @SuppressWarnings("unchecked") public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf, boolean arrayComponent, Class componentClass) throws IOException { String className; if (arrayComponent) { className = componentClass.getName(); } else { className = CUTF8.readString(in); //SANGCHUL // System.out.println("SANGCHUL] className:" + className); } Class<?> declaredClass = PRIMITIVE_NAMES.get(className); if (declaredClass == null) { try { declaredClass = conf.getClassByName(className); } catch (ClassNotFoundException e) { //SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class[className=" + className + "]", e); } } Object instance; if (declaredClass.isPrimitive()) { // primitive types if (declaredClass == Boolean.TYPE) { // boolean instance = Boolean.valueOf(in.readBoolean()); } else if (declaredClass == Character.TYPE) { // char instance = Character.valueOf(in.readChar()); } else if (declaredClass == Byte.TYPE) { // byte instance = Byte.valueOf(in.readByte()); } else if (declaredClass == Short.TYPE) { // short instance = Short.valueOf(in.readShort()); } else if (declaredClass == Integer.TYPE) { // int instance = Integer.valueOf(in.readInt()); } else if (declaredClass == Long.TYPE) { // long instance = Long.valueOf(in.readLong()); } else if (declaredClass == Float.TYPE) { // float instance = Float.valueOf(in.readFloat()); } else if (declaredClass == Double.TYPE) { // double instance = Double.valueOf(in.readDouble()); } else if (declaredClass == Void.TYPE) { // void instance = null; } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isArray()) { // array //System.out.println("SANGCHUL] is array"); int length = in.readInt(); //System.out.println("SANGCHUL] array length : " + length); //System.out.println("Read:in.readInt():" + length); if (declaredClass.getComponentType() == Byte.TYPE) { byte[] bytes = new byte[length]; in.readFully(bytes); instance = bytes; } else if (declaredClass.getComponentType() == ColumnValue.class) { instance = readColumnValue(in, conf, declaredClass, length); } else { Class componentType = declaredClass.getComponentType(); // SANGCHUL //System.out.println("SANGCHUL] componentType : " + componentType.getName()); instance = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(), componentType); Array.set(instance, i, arrayComponentInstance); //Array.set(instance, i, readObject(in, conf)); } } } else if (declaredClass == String.class) { // String instance = CUTF8.readString(in); } else if (declaredClass.isEnum()) { // enum instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in)); } else if (declaredClass == ColumnValue.class) { //ColumnValue? ?? ?? ? ? ?. //? ? ? ? ? ? . Class instanceClass = null; try { short typeDiff = in.readShort(); if (typeDiff == TYPE_DIFF) { instanceClass = conf.getClassByName(CUTF8.readString(in)); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { throw new RuntimeException("readObject can't find class", e); } ColumnValue columnValue = new ColumnValue(); columnValue.readFields(in); instance = columnValue; } else { // Writable Class instanceClass = null; try { short typeDiff = in.readShort(); // SANGCHUL //System.out.println("SANGCHUL] typeDiff : " + typeDiff); //System.out.println("Read:in.readShort():" + typeDiff); if (typeDiff == TYPE_DIFF) { // SANGCHUL String classNameTemp = CUTF8.readString(in); //System.out.println("SANGCHUL] typeDiff : " + classNameTemp); instanceClass = conf.getClassByName(classNameTemp); //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass()); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { // SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class", e); } CWritable writable = CWritableFactories.newInstance(instanceClass, conf); writable.readFields(in); //System.out.println("Read:writable.readFields(in)"); instance = writable; if (instanceClass == NullInstance.class) { // null declaredClass = ((NullInstance) instance).declaredClass; instance = null; } } if (objectWritable != null) { // store values objectWritable.declaredClass = declaredClass; objectWritable.instance = instance; } return instance; }
From source file:com.mawujun.util.AnnotationUtils.java
/** * Helper method for generating a hash code for an array. * * @param componentType the component type of the array * @param o the array/*from w w w .java2 s. co m*/ * @return a hash code for the specified array */ private static int arrayMemberHash(Class<?> componentType, Object o) { if (componentType.equals(Byte.TYPE)) { return Arrays.hashCode((byte[]) o); } if (componentType.equals(Short.TYPE)) { return Arrays.hashCode((short[]) o); } if (componentType.equals(Integer.TYPE)) { return Arrays.hashCode((int[]) o); } if (componentType.equals(Character.TYPE)) { return Arrays.hashCode((char[]) o); } if (componentType.equals(Long.TYPE)) { return Arrays.hashCode((long[]) o); } if (componentType.equals(Float.TYPE)) { return Arrays.hashCode((float[]) o); } if (componentType.equals(Double.TYPE)) { return Arrays.hashCode((double[]) o); } if (componentType.equals(Boolean.TYPE)) { return Arrays.hashCode((boolean[]) o); } return Arrays.hashCode((Object[]) o); }
From source file:com.examples.with.different.packagename.testcarver.AbstractConverter.java
/** * Change primitve Class types to the associated wrapper class. * @param type The class type to check./* w w w . java 2 s .c om*/ * @return The converted type. */ Class primitive(Class type) { if (type == null || !type.isPrimitive()) { return type; } if (type == Integer.TYPE) { return Integer.class; } else if (type == Double.TYPE) { return Double.class; } else if (type == Long.TYPE) { return Long.class; } else if (type == Boolean.TYPE) { return Boolean.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; } else if (type == Character.TYPE) { return Character.class; } else { return type; } }
From source file:com.sun.faces.renderkit.html_basic.MenuRenderer.java
protected Object handleArrayCase(FacesContext context, UISelectMany uiSelectMany, Class arrayClass, String[] newValues) throws ConverterException { Object result = null;/* ww w . j av a 2 s . c om*/ Class elementType = null; Converter converter = null; int i = 0, len = (null != newValues ? newValues.length : 0); elementType = arrayClass.getComponentType(); // Optimization: If the elementType is String, we don't need // conversion. Just return newValues. if (elementType.equals(String.class)) { return newValues; } try { result = Array.newInstance(elementType, len); } catch (Exception e) { throw new ConverterException(e); } // bail out now if we have no new values, returning our // oh-so-useful zero-length array. if (null == newValues) { return result; } // obtain a converter. // attached converter takes priority if (null == (converter = uiSelectMany.getConverter())) { // Otherwise, look for a by-type converter if (null == (converter = Util.getConverterForClass(elementType, context))) { // if that fails, and the attached values are of Object type, // we don't need conversion. if (elementType.equals(Object.class)) { return newValues; } String valueStr = ""; for (i = 0; i < newValues.length; i++) { valueStr = valueStr + " " + newValues[i]; } Object[] params = { valueStr, "null Converter" }; throw new ConverterException(Util.getExceptionMessage(Util.CONVERSION_ERROR_MESSAGE_ID, params)); } } Util.doAssert(null != result); if (elementType.isPrimitive()) { for (i = 0; i < len; i++) { if (elementType.equals(Boolean.TYPE)) { Array.setBoolean(result, i, ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i])).booleanValue()); } else if (elementType.equals(Byte.TYPE)) { Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i])).byteValue()); } else if (elementType.equals(Double.TYPE)) { Array.setDouble(result, i, ((Double) converter.getAsObject(context, uiSelectMany, newValues[i])).doubleValue()); } else if (elementType.equals(Float.TYPE)) { Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i])).floatValue()); } else if (elementType.equals(Integer.TYPE)) { Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i])).intValue()); } else if (elementType.equals(Character.TYPE)) { Array.setChar(result, i, ((Character) converter.getAsObject(context, uiSelectMany, newValues[i])).charValue()); } else if (elementType.equals(Short.TYPE)) { Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i])).shortValue()); } else if (elementType.equals(Long.TYPE)) { Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i])).longValue()); } } } else { for (i = 0; i < len; i++) { if (log.isDebugEnabled()) { Object converted = converter.getAsObject(context, uiSelectMany, newValues[i]); log.debug("String value: " + newValues[i] + " converts to : " + converted.toString()); } Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i])); } } return result; }
From source file:android.reflect.ClazzLoader.java
/** * ????//from w w w. j a v a 2 s .c o m */ public static <O, V> void setFieldValue(O o, Field field, V v) { if (field != null) { try { field.setAccessible(true); if (v == null) { field.set(o, null); } else { Class<?> vType = v.getClass(); if (vType == Integer.TYPE) { field.setInt(o, (Integer) v); } else if (vType == Long.TYPE) { field.setLong(o, (Long) v); } else if (vType == Boolean.TYPE) { field.setBoolean(o, (Boolean) v); } else if (vType == Float.TYPE) { field.setFloat(o, (Float) v); } else if (vType == Short.TYPE) { field.setShort(o, (Short) v); } else if (vType == Byte.TYPE) { field.setByte(o, (Byte) v); } else if (vType == Double.TYPE) { field.setDouble(o, (Double) v); } else if (vType == Character.TYPE) { field.setChar(o, (Character) v); } else { field.set(o, v); } } } catch (Throwable t) { Log.e(TAG, t); } } }
From source file:org.xmlsh.util.JavaUtils.java
public static Class<?> fromPrimativeName(String name) { switch (name) { case "boolean": return java.lang.Boolean.TYPE; case "char": return java.lang.Character.TYPE; case "byte": return java.lang.Byte.TYPE; case "short": return java.lang.Short.TYPE; case "int": return java.lang.Integer.TYPE; case "long": return java.lang.Long.TYPE; case "float": return java.lang.Float.TYPE; case "double": return java.lang.Double.TYPE; case "void": return java.lang.Void.TYPE; default://from w w w . j a v a 2 s. c om return null; } }
From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * ResultSet.getObject() returns an Integer object for an INT column. The * setter method for the property might take an Integer or a primitive int. * This method returns true if the value can be successfully passed into * the setter method. Remember, Method.invoke() handles the unwrapping * of Integer into an int./*from w w w.ja va 2 s . c om*/ * * @param value The value to be passed into the setter method. * @param type The setter's parameter type (non-null) * @return boolean True if the value is compatible (null => true) */ private boolean isCompatibleType(Object value, Class<?> type) { // Do object check first, then primitives if (value == null || type.isInstance(value)) { return true; } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) { return true; } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) { return true; } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) { return true; } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) { return true; } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) { return true; } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) { return true; } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) { return true; } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) { return true; } return false; }
From source file:com.sun.faces.el.impl.Coercions.java
/** * Coerces the given value to the specified class. *//*from w w w .ja va 2 s . c o m*/ public static Object coerce(Object pValue, Class pClass) throws ElException { if (pClass == String.class) { return coerceToString(pValue); } else if (isNumberClass(pClass)) { return coerceToPrimitiveNumber(pValue, pClass); } else if (pClass == Character.class || pClass == Character.TYPE) { return coerceToCharacter(pValue); } else if (pClass == Boolean.class || pClass == Boolean.TYPE) { return coerceToBoolean(pValue); } else { return coerceToObject(pValue, pClass); } }