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.testcase.fm.MethodDescriptor.java
public Object executeMatcher(int i) throws IllegalArgumentException { if (i < 0 || i >= getNumberOfInputParameters()) { throw new IllegalArgumentException("Invalid index: " + i); }/*w w w . j a v a 2 s.co m*/ Type[] types = method.getParameterTypes(); Type type = types[i]; try { if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return Mockito.anyInt(); } else if (type.equals(Long.TYPE) || type.equals(Long.class)) { return Mockito.anyLong(); } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) { return Mockito.anyBoolean(); } else if (type.equals(Double.TYPE) || type.equals(Double.class)) { return Mockito.anyDouble(); } else if (type.equals(Float.TYPE) || type.equals(Float.class)) { return Mockito.anyFloat(); } else if (type.equals(Short.TYPE) || type.equals(Short.class)) { return Mockito.anyShort(); } else if (type.equals(Character.TYPE) || type.equals(Character.class)) { return Mockito.anyChar(); } else if (type.equals(String.class)) { return Mockito.anyString(); } else { return Mockito.any(type.getClass()); } } catch (Exception e) { logger.error("Failed to executed Mockito matcher n{} of type {} in {}.{}: {}", i, type, className, methodName, e.getMessage()); throw new EvosuiteError(e); } }
From source file:org.romaframework.core.schema.SchemaField.java
protected Object convertValue(Object iFieldValue) { if (type == null || isArray()) return iFieldValue; SchemaClass typeClass = getType().getSchemaClass(); if (typeClass.equals(Roma.schema().getSchemaClass(iFieldValue))) return iFieldValue; String textValue = null;//from w ww . j a v a2 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 { 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 " + getType().getName() + ". Setting value to 0."); // SET THE VALUE TO 0 value = SchemaHelper.assignDefaultValueToLiteral(typeClass); } return value; }
From source file:org.evosuite.testcase.statements.FunctionalMockStatementTest.java
@Test public void testConfirmCast() { //note: TypeUtils can give different results because it takes autoboxing into account assertTrue(TypeUtils.isAssignable(Integer.class, Integer.TYPE)); assertTrue(TypeUtils.isAssignable(Integer.TYPE, Integer.class)); assertFalse(Integer.TYPE.isAssignableFrom(Integer.class)); assertFalse(Integer.class.isAssignableFrom(Integer.TYPE)); assertFalse(Integer.TYPE.isAssignableFrom(Character.TYPE)); assertFalse(TypeUtils.isAssignable(Integer.TYPE, Character.TYPE)); assertFalse(Character.TYPE.isAssignableFrom(Integer.TYPE)); assertTrue(TypeUtils.isAssignable(Character.TYPE, Integer.TYPE)); //DIFFERENT assertFalse(Character.class.isAssignableFrom(Integer.TYPE)); assertTrue(TypeUtils.isAssignable(Character.class, Integer.TYPE)); //DIFFERENT assertFalse(Character.class.isAssignableFrom(Integer.class)); assertFalse(TypeUtils.isAssignable(Character.class, Integer.class)); assertTrue(Integer.TYPE.isPrimitive()); assertFalse(Integer.class.isPrimitive()); char c = 'c'; //99 int i = c;//from w w w.j a va2 s . c o m assertEquals(99, i); Object aInt = i; Object aInteger = Integer.valueOf(7); Assert.assertTrue(aInt.getClass().equals(Integer.class)); Assert.assertTrue(aInt.getClass().equals(aInteger.getClass())); Object aChar = c; Assert.assertTrue(aChar.getClass().equals(Character.class)); //just recall the two diverge assertTrue(TypeUtils.isAssignable(aChar.getClass(), Integer.TYPE)); assertFalse(Integer.TYPE.isAssignableFrom(aChar.getClass())); Object casted = null; try { casted = Integer.TYPE.cast(aChar); fail(); } catch (Exception e) { //expected: cannot do direct cast from "Character" to "int" } try { casted = Integer.TYPE.cast(((Character) aChar).charValue()); fail(); } catch (Exception e) { //expected: "cast" takes an Object as input, so it does autoboxing :( } casted = (int) ((Character) aChar).charValue(); assertTrue(casted.getClass().equals(Integer.class)); }
From source file:org.opoo.util.ClassUtils.java
public static 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; } else {/* w w w .j av a 2 s . c o m*/ return false; } }
From source file:org.kordamp.ezmorph.bean.MorphDynaBean.java
protected boolean isDynaAssignable(Class dest, Class src) { boolean assignable = dest.isAssignableFrom(src); if (assignable) { return true; }/*from w w w . j a v a 2 s . c o m*/ assignable = (dest == Boolean.TYPE && src == Boolean.class) || assignable; assignable = (dest == Byte.TYPE && src == Byte.class) || assignable; assignable = (dest == Character.TYPE && src == Character.class) || assignable; assignable = (dest == Short.TYPE && src == Short.class) || assignable; assignable = (dest == Integer.TYPE && src == Integer.class) || assignable; assignable = (dest == Long.TYPE && src == Long.class) || assignable; assignable = (dest == Float.TYPE && src == Float.class) || assignable; assignable = (dest == Double.TYPE && src == Double.class) || assignable; if (src == Double.TYPE || Double.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) || assignable; } if (src == Float.TYPE || Float.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) || assignable; } if (src == Long.TYPE || Long.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) || assignable; } if (src == Integer.TYPE || Integer.class.isAssignableFrom(src)) assignable = (isByte(dest) || isShort(dest)) || assignable; if (src == Short.TYPE || Short.class.isAssignableFrom(src)) { assignable = (isByte(dest)) || assignable; } return assignable; }
From source file:org.apache.struts.action.DynaActionForm.java
/** * <p>Return the value of a simple property with the specified name.</p> * * @param name Name of the property whose value is to be retrieved * @return The value of a simple property with the specified name. * @throws IllegalArgumentException if there is no property of the * specified name * @throws NullPointerException if the type specified for the property * is invalid *//*from www .ja va 2 s. c o m*/ public Object get(String name) { // Return any non-null value for the specified property Object value = dynaValues.get(name); if (value != null) { return (value); } // Return a null value for a non-primitive property Class type = getDynaProperty(name).getType(); if (type == null) { throw new NullPointerException("The type for property " + name + " is invalid"); } if (!type.isPrimitive()) { return (value); } // Manufacture default values for primitive properties 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 == Double.TYPE) { return (new Double(0.0)); } else if (type == Float.TYPE) { return (new Float((float) 0.0)); } else if (type == Integer.TYPE) { return (new Integer(0)); } else if (type == Long.TYPE) { return (new Long(0)); } else if (type == Short.TYPE) { return (new Short((short) 0)); } else { return (null); } }
From source file:jp.terasoluna.fw.web.struts.reset.ResetterImpl.java
/** * ANVtH?[wv?peBZbg?B/*from w ww . java 2 s . co m*/ * v?peB^boolean^?ABoolean^??false??B * v~eBu^bp?[^???A0??B * v?peB^bp?[^OObject^??null??B<br> * ??A?entrynulln?B * * @param form ?NGXggpANVtH?[ * @param entry Zbg?v?peB?lGg * @throws PropertyAccessException v?peBl?s?? */ protected void resetValue(FormEx form, Entry<String, Object> entry) { if (log.isDebugEnabled()) { log.debug("resetValue(" + form + ", " + entry.getKey() + ") called."); } String propName = entry.getKey(); try { Object value = entry.getValue(); if (value == null) { return; } Class type = null; type = value.getClass(); if (type != null) { // ^???B if (type == Boolean.TYPE || type == Boolean.class) { BeanUtil.setBeanProperty(form, propName, Boolean.FALSE); } else if (type == Byte.TYPE || type == Byte.class) { BeanUtil.setBeanProperty(form, propName, new Byte((byte) 0)); } else if (type == Character.TYPE || type == Character.class) { BeanUtil.setBeanProperty(form, propName, new Character((char) 0)); } else if (type == Double.TYPE || type == Double.class) { BeanUtil.setBeanProperty(form, propName, new Double(0.0)); } else if (type == Float.TYPE || type == Float.class) { BeanUtil.setBeanProperty(form, propName, new Float((float) 0.0)); } else if (type == Integer.TYPE || type == Integer.class) { BeanUtil.setBeanProperty(form, propName, new Integer(0)); } else if (type == Long.TYPE || type == Long.class) { BeanUtil.setBeanProperty(form, propName, new Long(0)); } else if (type == Short.TYPE || type == Short.class) { BeanUtil.setBeanProperty(form, propName, new Short((short) 0)); } else { // v~eBu^?Abp?[^??null? BeanUtil.setBeanProperty(form, propName, null); } } } catch (PropertyAccessException e) { log.error("cannot access property " + form + "." + propName, e); } }
From source file:org.robobinding.util.ClassUtils.java
/** * <p>/*from www .j a v a2 s.c o m*/ * Checks if one {@code Class} can be assigned to a variable of another * {@code Class}. * </p> * * <p> * Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method, this * method takes into account widenings of primitive classes and {@code null} * s. * </p> * * <p> * Primitive widenings allow an int to be assigned to a long, float or * double. This method returns the correct result for these cases. * </p> * * <p> * {@code Null} may be assigned to any reference type. This method will * return {@code true} if {@code null} is passed in and the toClass is * non-primitive. * </p> * * <p> * Specifically, this method tests whether the type represented by the * specified {@code Class} parameter can be converted to the type * represented by this {@code Class} object via an identity conversion * widening primitive or widening reference conversion. See * <em><a href="http://docs.oracle.com/javase/specs/">The Java Language Specification</a></em> * , sections 5.1.1, 5.1.2 and 5.1.4 for details. * </p> * * @param cls * the Class to check, may be null * @param toClass * the Class to try to assign into, returns false if null * @param autoboxing * whether to use implicit autoboxing/unboxing between primitives * and wrappers * @return {@code true} if assignment possible */ public static boolean isAssignable(Class<?> cls, final Class<?> toClass, final boolean autoboxing) { if (toClass == null) { return false; } // have to check for null, as isAssignableFrom doesn't if (cls == null) { return !toClass.isPrimitive(); } // autoboxing: if (autoboxing) { if (cls.isPrimitive() && !toClass.isPrimitive()) { cls = primitiveToWrapper(cls); if (cls == null) { return false; } } if (toClass.isPrimitive() && !cls.isPrimitive()) { cls = wrapperToPrimitive(cls); if (cls == null) { return false; } } } if (cls.equals(toClass)) { return true; } if (cls.isPrimitive()) { if (toClass.isPrimitive() == false) { return false; } if (Integer.TYPE.equals(cls)) { return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Long.TYPE.equals(cls)) { return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Boolean.TYPE.equals(cls)) { return false; } if (Double.TYPE.equals(cls)) { return false; } if (Float.TYPE.equals(cls)) { return Double.TYPE.equals(toClass); } if (Character.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Short.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Byte.TYPE.equals(cls)) { return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } // should never get here return false; } return toClass.isAssignableFrom(cls); }
From source file:org.jdto.util.ClassUtils.java
/** * <p>Checks if one/*from w ww.j a va 2 s . c om*/ * <code>Class</code> can be assigned to a variable of another * <code>Class</code>.</p> * * <p>Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method, * this method takes into account widenings of primitive classes and * <code>null</code>s.</p> * * <p>Primitive widenings allow an int to be assigned to a long, float or * double. This method returns the correct result for these cases.</p> * * <p><code>Null</code> may be assigned to any reference type. This method * will return * <code>true</code> if * <code>null</code> is passed in and the toClass is non-primitive.</p> * * <p>Specifically, this method tests whether the type represented by the * specified * <code>Class</code> parameter can be converted to the type represented by * this * <code>Class</code> object via an identity conversion widening primitive * or widening reference conversion. See <em><a * href="http://java.sun.com/docs/books/jls/">The Java Language * Specification</a></em>, sections 5.1.1, 5.1.2 and 5.1.4 for details.</p> * * @param cls the Class to check, may be null * @param toClass the Class to try to assign into, returns false if null * @param autoboxing whether to use implicit autoboxing/unboxing between * primitives and wrappers * @return * <code>true</code> if assignment possible * @since 2.5 */ public static boolean isAssignable(Class cls, Class toClass, boolean autoboxing) { if (toClass == null) { return false; } // have to check for null, as isAssignableFrom doesn't if (cls == null) { return !(toClass.isPrimitive()); } //autoboxing: if (autoboxing) { if (cls.isPrimitive() && !toClass.isPrimitive()) { cls = primitiveToWrapper(cls); if (cls == null) { return false; } } if (toClass.isPrimitive() && !cls.isPrimitive()) { cls = wrapperToPrimitive(cls); if (cls == null) { return false; } } } if (cls.equals(toClass)) { return true; } if (cls.isPrimitive()) { if (toClass.isPrimitive() == false) { return false; } if (Integer.TYPE.equals(cls)) { return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Long.TYPE.equals(cls)) { return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Boolean.TYPE.equals(cls)) { return false; } if (Double.TYPE.equals(cls)) { return false; } if (Float.TYPE.equals(cls)) { return Double.TYPE.equals(toClass); } if (Character.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Short.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Byte.TYPE.equals(cls)) { return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } // should never get here return false; } return toClass.isAssignableFrom(cls); }
From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.bean.MorphDynaBean.java
protected boolean isDynaAssignable(Class dest, Class src) { boolean assignable = dest.isAssignableFrom(src); if (assignable) { return true; }/*from ww w . j ava2 s. co m*/ assignable = (dest == Boolean.TYPE && src == Boolean.class) ? true : assignable; assignable = (dest == Byte.TYPE && src == Byte.class) ? true : assignable; assignable = (dest == Character.TYPE && src == Character.class) ? true : assignable; assignable = (dest == Short.TYPE && src == Short.class) ? true : assignable; assignable = (dest == Integer.TYPE && src == Integer.class) ? true : assignable; assignable = (dest == Long.TYPE && src == Long.class) ? true : assignable; assignable = (dest == Float.TYPE && src == Float.class) ? true : assignable; assignable = (dest == Double.TYPE && src == Double.class) ? true : assignable; if (src == Double.TYPE || Double.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true : assignable; } if (src == Float.TYPE || Float.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable; } if (src == Long.TYPE || Long.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable; } if (src == Integer.TYPE || Integer.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest)) ? true : assignable; } if (src == Short.TYPE || Short.class.isAssignableFrom(src)) { assignable = (isByte(dest)) ? true : assignable; } return assignable; }