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:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java
private final Class<?> getClassForName(String type) { try {// w w w . j ava2s . c om if (type.equals("boolean") || type.equals("java.lang.Boolean")) { return Boolean.TYPE; } else if (type.equals("byte") || type.equals("java.lang.Byte")) { return Byte.TYPE; } else if (type.equals("char") || type.equals("java.lang.Character")) { return Character.TYPE; } else if (type.equals("double") || type.equals("java.lang.Double")) { return Double.TYPE; } else if (type.equals("float") || type.equals("java.lang.Float")) { return Float.TYPE; } else if (type.equals("int") || type.equals("java.lang.Integer")) { return Integer.TYPE; } else if (type.equals("long") || type.equals("java.lang.Long")) { return Long.TYPE; } else if (type.equals("short") || type.equals("java.lang.Short")) { return Short.TYPE; } else if (type.equals("String")) { return Class.forName("java.lang." + type, true, TestGenerationContext.getInstance().getClassLoaderForSUT()); } if (type.endsWith("[]")) { // see http://stackoverflow.com/questions/3442090/java-what-is-this-ljava-lang-object final StringBuilder arrayTypeNameBuilder = new StringBuilder(30); int index = 0; while ((index = type.indexOf('[', index)) != -1) { arrayTypeNameBuilder.append('['); index++; } arrayTypeNameBuilder.append('L'); // always needed for Object arrays // remove bracket from type name get array component type type = type.replace("[]", ""); arrayTypeNameBuilder.append(type); arrayTypeNameBuilder.append(';'); // finalize object array name return Class.forName(arrayTypeNameBuilder.toString(), true, TestGenerationContext.getInstance().getClassLoaderForSUT()); } else { return Class.forName(ResourceList.getClassNameFromResourcePath(type), true, TestGenerationContext.getInstance().getClassLoaderForSUT()); } } catch (final ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:wicket.util.lang.Objects.java
/** * Returns the value converted numerically to the given class type * /*from w ww . ja va2 s .co m*/ * This method also detects when arrays are being converted and converts the * components of one array to the type of the other. * * @param value * an object to be converted to the given type * @param toType * class type to be converted to * @return converted value of the type given, or value if the value cannot * be converted to the given type. */ public static 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 = new Integer((int) longValue(value)); } if ((toType == Double.class) || (toType == Double.TYPE)) { result = new Double(doubleValue(value)); } if ((toType == Boolean.class) || (toType == Boolean.TYPE)) { result = booleanValue(value) ? Boolean.TRUE : Boolean.FALSE; } if ((toType == Byte.class) || (toType == Byte.TYPE)) { result = new Byte((byte) longValue(value)); } if ((toType == Character.class) || (toType == Character.TYPE)) { result = new Character((char) longValue(value)); } if ((toType == Short.class) || (toType == Short.TYPE)) { result = new Short((short) longValue(value)); } if ((toType == Long.class) || (toType == Long.TYPE)) { result = new Long(longValue(value)); } if ((toType == Float.class) || (toType == Float.TYPE)) { result = new Float(doubleValue(value)); } if (toType == BigInteger.class) { result = bigIntValue(value); } if (toType == BigDecimal.class) { result = bigDecValue(value); } if (toType == String.class) { result = stringValue(value); } } } else { if (toType.isPrimitive()) { result = primitiveDefaults.get(toType); } } return result; }
From source file:org.apache.jasper.compiler.JspUtil.java
/** * Produces a String representing a call to the EL interpreter. * @param expression a String containing zero or more "${}" expressions * @param expectedType the expected type of the interpreted result * @param fnmapvar Variable pointing to a function map. * @param XmlEscape True if the result should do XML escaping * @return a String representing a call to the EL interpreter. *//* w w w . ja v a 2 s . c o m*/ public static String interpreterCall(boolean isTagFile, String expression, Class expectedType, String fnmapvar, boolean XmlEscape) { /* * Determine which context object to use. */ String jspCtxt = null; if (isTagFile) jspCtxt = "this.getJspContext()"; else jspCtxt = "pageContext"; /* * Determine whether to use the expected type's textual name * or, if it's a primitive, the name of its correspondent boxed * type. */ String targetType = expectedType.getName(); String primitiveConverterMethod = null; if (expectedType.isPrimitive()) { if (expectedType.equals(Boolean.TYPE)) { targetType = Boolean.class.getName(); primitiveConverterMethod = "booleanValue"; } else if (expectedType.equals(Byte.TYPE)) { targetType = Byte.class.getName(); primitiveConverterMethod = "byteValue"; } else if (expectedType.equals(Character.TYPE)) { targetType = Character.class.getName(); primitiveConverterMethod = "charValue"; } else if (expectedType.equals(Short.TYPE)) { targetType = Short.class.getName(); primitiveConverterMethod = "shortValue"; } else if (expectedType.equals(Integer.TYPE)) { targetType = Integer.class.getName(); primitiveConverterMethod = "intValue"; } else if (expectedType.equals(Long.TYPE)) { targetType = Long.class.getName(); primitiveConverterMethod = "longValue"; } else if (expectedType.equals(Float.TYPE)) { targetType = Float.class.getName(); primitiveConverterMethod = "floatValue"; } else if (expectedType.equals(Double.TYPE)) { targetType = Double.class.getName(); primitiveConverterMethod = "doubleValue"; } } if (primitiveConverterMethod != null) { XmlEscape = false; } /* * Build up the base call to the interpreter. */ // XXX - We use a proprietary call to the interpreter for now // as the current standard machinery is inefficient and requires // lots of wrappers and adapters. This should all clear up once // the EL interpreter moves out of JSTL and into its own project. // In the future, this should be replaced by code that calls // ExpressionEvaluator.parseExpression() and then cache the resulting // expression objects. The interpreterCall would simply select // one of the pre-cached expressions and evaluate it. // Note that PageContextImpl implements VariableResolver and // the generated Servlet/SimpleTag implements FunctionMapper, so // that machinery is already in place (mroth). targetType = toJavaSourceType(targetType); StringBuffer call = new StringBuffer( "(" + targetType + ") " + "org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate" + "(" + Generator.quote(expression) + ", " + targetType + ".class, " + "(PageContext)" + jspCtxt + ", " + fnmapvar + ", " + XmlEscape + ")"); /* * Add the primitive converter method if we need to. */ if (primitiveConverterMethod != null) { call.insert(0, "("); call.append(")." + primitiveConverterMethod + "()"); } return call.toString(); }
From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java
/** * Returns the virtual machine's Class object for the named primitive type.<br/> * If the type is not a primitive type, {@code null} is returned. * * @param name the name of the type/*from w ww. j a v a 2 s .c o m*/ * @return the Class instance representing the primitive type */ private static Class<?> getPrimitiveType(String name) { name = StringUtils.defaultIfEmpty(name, ""); if (name.equals("int")) return Integer.TYPE; if (name.equals("short")) return Short.TYPE; if (name.equals("long")) return Long.TYPE; if (name.equals("float")) return Float.TYPE; if (name.equals("double")) return Double.TYPE; if (name.equals("byte")) return Byte.TYPE; if (name.equals("char")) return Character.TYPE; if (name.equals("boolean")) return Boolean.TYPE; if (name.equals("void")) return Void.TYPE; return null; }
From source file:org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.java
public static Class<?> getTypeForPrimitive(Class<?> primitiveType) { if (primitiveType == Boolean.TYPE) { return Boolean.class; } else if (primitiveType == Integer.TYPE) { return Integer.class; } else if (primitiveType == Long.TYPE) { return Long.class; } else if (primitiveType == Float.TYPE) { return Float.class; } else if (primitiveType == Double.TYPE) { return Double.class; } else if (primitiveType == Character.TYPE) { return Character.class; } else if (primitiveType == Byte.TYPE) { return Byte.class; } else if (primitiveType == Short.TYPE) { return Short.class; }//from w w w. j a v a2 s . c o m return primitiveType; }
From source file:org.lunarray.model.descriptor.scanner.AnnotationMetaModelProcessor.java
/** * Copy array values./*w w w. j a va 2s . c om*/ * * @param values * The array values. * @param name * The property name. * @param obj * The object value. * @param type * The array type. * @param compType * The component type. * @throws MappingException * Thrown if the mapping was unsuccessful. */ private void extractNonFloats(final AnnotationMetaValues values, final String name, final Object obj, final Class<?> type, final Class<?> compType) throws MappingException { try { if (Boolean.TYPE.equals(compType)) { final boolean[] array = boolean[].class.cast(obj); for (final boolean a : array) { values.getMetaValueList(name).add(this.converterTool.convertToString(Boolean.TYPE, a)); } } else if (Character.TYPE.equals(compType)) { final char[] array = char[].class.cast(obj); for (final char a : array) { values.getMetaValueList(name).add(this.converterTool.convertToString(Character.TYPE, a)); } } else { this.copyObjectTypes(values, name, obj, type, compType); } } catch (final ConverterException e) { throw new MappingException(e); } }
From source file:org.evosuite.testcase.statements.FunctionalMockStatement.java
public void fillWithNullRefs() { for (int i = 0; i < parameters.size(); i++) { VariableReference ref = parameters.get(i); if (ref == null) { Class<?> expected = getExpectedParameterType(i); Object value = null;//from w ww .j a v a 2 s . co m if (expected.isPrimitive()) { //can't fill a primitive with null if (expected.equals(Integer.TYPE)) { value = 0; } else if (expected.equals(Float.TYPE)) { value = 0f; } else if (expected.equals(Double.TYPE)) { value = 0d; } else if (expected.equals(Long.TYPE)) { value = 0L; } else if (expected.equals(Boolean.TYPE)) { value = false; } else if (expected.equals(Short.TYPE)) { value = Short.valueOf("0"); } else if (expected.equals(Character.TYPE)) { value = 'a'; } } parameters.set(i, new ConstantValue(tc, new GenericClass(expected), value)); } } }
From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java
/** * Gets the bean size intern./* w w w . j a va 2s. c o m*/ * * @param bean the bean * @param clazz the clazz * @param m the m * @param classNameMatcher the class name matcher * @param fieldNameMatcher the field name matcher * @return the bean size intern */ public static int getBeanSizeIntern(Object bean, Class<?> clazz, IdentityHashMap<Object, Object> m, Matcher<String> classNameMatcher, Matcher<String> fieldNameMatcher) { if (classNameMatcher.match(clazz.getName()) == false) { return 0; } if (clazz.isArray() == true) { if (clazz == boolean[].class) { return (((boolean[]) bean).length * 4); } else if (clazz == char[].class) { return (((char[]) bean).length * 2); } else if (clazz == byte[].class) { return (((byte[]) bean).length * 1); } else if (clazz == short[].class) { return (((short[]) bean).length * 2); } else if (clazz == int[].class) { return (((int[]) bean).length * 4); } else if (clazz == long[].class) { return (((long[]) bean).length * 4); } else if (clazz == float[].class) { return (((float[]) bean).length * 4); } else if (clazz == double[].class) { return (((double[]) bean).length * 8); } else { int length = Array.getLength(bean); int ret = (length * 4); for (int i = 0; i < length; ++i) { ret += getBeanSize(Array.get(bean, i), m, classNameMatcher, fieldNameMatcher); } return ret; } } int ret = 0; try { for (Field f : clazz.getDeclaredFields()) { int mod = f.getModifiers(); if (Modifier.isStatic(mod) == true) { continue; } if (fieldNameMatcher.match(clazz.getName() + "." + f.getName()) == false) { continue; } if (f.getType() == Boolean.TYPE) { ret += 4; } else if (f.getType() == Character.TYPE) { ret += 2; } else if (f.getType() == Byte.TYPE) { ret += 1; } else if (f.getType() == Short.TYPE) { ret += 2; } else if (f.getType() == Integer.TYPE) { ret += 4; } else if (f.getType() == Long.TYPE) { ret += 8; } else if (f.getType() == Float.TYPE) { ret += 4; } else if (f.getType() == Double.TYPE) { ret += 8; } else { ret += 4; Object o = null; try { o = readField(bean, f); if (o == null) { continue; } } catch (NoClassDefFoundError ex) { // nothing continue; } int nestedsize = getBeanSize(o, o.getClass(), m, classNameMatcher, fieldNameMatcher); ret += nestedsize; } } } catch (NoClassDefFoundError ex) { // ignore here. } if (clazz == Object.class || clazz.getSuperclass() == null) { return ret; } ret += getBeanSizeIntern(bean, clazz.getSuperclass(), m, classNameMatcher, fieldNameMatcher); return ret; }
From source file:org.apache.syncope.core.provisioning.java.ConnectorFacadeProxy.java
private Object getPropertyValue(final String propType, final List<?> values) { Object value = null;/* w w w .ja va2s .c om*/ try { Class<?> propertySchemaClass = ClassUtils.forName(propType, ClassUtils.getDefaultClassLoader()); if (GuardedString.class.equals(propertySchemaClass)) { value = new GuardedString(values.get(0).toString().toCharArray()); } else if (GuardedByteArray.class.equals(propertySchemaClass)) { value = new GuardedByteArray((byte[]) values.get(0)); } else if (Character.class.equals(propertySchemaClass) || Character.TYPE.equals(propertySchemaClass)) { value = values.get(0) == null || values.get(0).toString().isEmpty() ? null : values.get(0).toString().charAt(0); } else if (Integer.class.equals(propertySchemaClass) || Integer.TYPE.equals(propertySchemaClass)) { value = Integer.parseInt(values.get(0).toString()); } else if (Long.class.equals(propertySchemaClass) || Long.TYPE.equals(propertySchemaClass)) { value = Long.parseLong(values.get(0).toString()); } else if (Float.class.equals(propertySchemaClass) || Float.TYPE.equals(propertySchemaClass)) { value = Float.parseFloat(values.get(0).toString()); } else if (Double.class.equals(propertySchemaClass) || Double.TYPE.equals(propertySchemaClass)) { value = Double.parseDouble(values.get(0).toString()); } else if (Boolean.class.equals(propertySchemaClass) || Boolean.TYPE.equals(propertySchemaClass)) { value = Boolean.parseBoolean(values.get(0).toString()); } else if (URI.class.equals(propertySchemaClass)) { value = URI.create(values.get(0).toString()); } else if (File.class.equals(propertySchemaClass)) { value = new File(values.get(0).toString()); } else if (String[].class.equals(propertySchemaClass)) { value = values.toArray(new String[] {}); } else { value = values.get(0) == null ? null : values.get(0).toString(); } } catch (Exception e) { LOG.error("Invalid ConnConfProperty specified: {} {}", propType, values, e); } return value; }
From source file:org.seedstack.seed.core.internal.application.ConfigurationMembersInjectorTest.java
public org.apache.commons.configuration.Configuration mockConfiguration(Field field, boolean isInconfig) { if (field == null) { return null; }/*from w w w . j a va 2 s .c o m*/ org.apache.commons.configuration.Configuration configuration = mock( org.apache.commons.configuration.Configuration.class); when(configuration.containsKey(field.getName())).thenReturn(isInconfig); if (isInconfig) { Class<?> type = field.getType(); String configParamName = field.getAnnotation(Configuration.class).value(); if (type.isArray()) { type = type.getComponentType(); if (type == Integer.TYPE || type == Integer.class) { when(configuration.getStringArray(configParamName)) .thenReturn(new String[] { String.valueOf(Integer.MAX_VALUE) }); } else if (type == Boolean.TYPE || type == Boolean.class) { when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "true" }); } else if (type == Short.TYPE || type == Short.class) { when(configuration.getStringArray(configParamName)) .thenReturn(new String[] { String.valueOf(Short.MAX_VALUE) }); } else if (type == Byte.TYPE || type == Byte.class) { when(configuration.getStringArray(configParamName)) .thenReturn(new String[] { String.valueOf(Byte.MAX_VALUE) }); } else if (type == Long.TYPE || type == Long.class) { when(configuration.getStringArray(configParamName)) .thenReturn(new String[] { String.valueOf(Long.MAX_VALUE) }); } else if (type == Float.TYPE || type == Float.class) { when(configuration.getStringArray(configParamName)) .thenReturn(new String[] { String.valueOf(Float.MAX_VALUE) }); } else if (type == Double.TYPE || type == Double.class) { when(configuration.getStringArray(configParamName)) .thenReturn(new String[] { String.valueOf(Double.MAX_VALUE) }); } else if (type == Character.TYPE || type == Character.class) { when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "t" }); } else if (type == String.class) { when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "test" }); } else throw new IllegalArgumentException("Type " + type + " cannot be mocked"); } else { if (type == Integer.TYPE || type == Integer.class) { when(configuration.getString(configParamName)).thenReturn(String.valueOf(Integer.MAX_VALUE)); } else if (type == Boolean.TYPE || type == Boolean.class) { when(configuration.getString(configParamName)).thenReturn("true"); } else if (type == Short.TYPE || type == Short.class) { when(configuration.getString(configParamName)).thenReturn(String.valueOf(Short.MAX_VALUE)); } else if (type == Byte.TYPE || type == Byte.class) { when(configuration.getString(configParamName)).thenReturn(String.valueOf(Byte.MAX_VALUE)); } else if (type == Long.TYPE || type == Long.class) { when(configuration.getString(configParamName)).thenReturn(String.valueOf(Long.MAX_VALUE)); } else if (type == Float.TYPE || type == Float.class) { when(configuration.getString(configParamName)).thenReturn(String.valueOf(Float.MAX_VALUE)); } else if (type == Double.TYPE || type == Double.class) { when(configuration.getString(configParamName)).thenReturn(String.valueOf(Double.MAX_VALUE)); } else if (type == Character.TYPE || type == Character.class) { when(configuration.getString(configParamName)).thenReturn("t"); } else if (type == String.class) { when(configuration.getString(configParamName)).thenReturn("test"); } else throw new IllegalArgumentException("Type " + type + " cannot be mocked"); } } return configuration; }