List of usage examples for java.lang Boolean TYPE
Class TYPE
To view the source code for java.lang Boolean TYPE.
Click Source Link
From source file:com.google.feedserver.util.BeanCliHelper.java
/** * Loop through each registered class and create and parse command line * options for fields decorated with {@link Flag}. *//*w w w . j a v a 2 s.c o m*/ private void populateBeansFromCommandLine() { // Go through all registered beans. for (Object bean : beans) { // Search for all fields in the bean with Flag decorator. for (Field field : bean.getClass().getDeclaredFields()) { Flag flag = field.getAnnotation(Flag.class); if (flag == null) { // not decorated, continue. continue; } String argName = field.getName(); // Boolean Flags if (field.getType().getName().equals(Boolean.class.getName()) || field.getType().getName().equals(Boolean.TYPE.getName())) { if (flags.hasOption(argName)) { setField(field, bean, new Boolean(true)); } else if (flags.hasOption("no" + argName)) { setField(field, bean, new Boolean(false)); } // Integer Flags } else if (field.getType().getName().equals(Integer.class.getName()) || field.getType().getName().equals(Integer.TYPE.getName())) { String argValue = flags.getOptionValue(argName, null); if (argValue != null) { try { setField(field, bean, Integer.valueOf(argValue)); } catch (NumberFormatException e) { throw new RuntimeException(e); } } // String Flag } else if (field.getType().getName().equals(String.class.getName())) { String argValue = flags.getOptionValue(argName, null); if (argValue != null) { setField(field, bean, argValue); } // Repeated String Flag } else if (field.getType().getName().equals(String[].class.getName())) { String[] argValues = flags.getOptionValues(argName); if (argValues != null) { setField(field, bean, argValues); } } } } }
From source file:nl.strohalm.cyclos.controls.customization.fields.EditCustomFieldAction.java
@SuppressWarnings("unchecked") public DataBinder<LoanGroupCustomField> getLoanGroupCustomFieldBinder() { final BeanBinder<LoanGroupCustomField> loanGroupFieldBinder = (BeanBinder<LoanGroupCustomField>) getBasicDataBinder( CustomField.Nature.LOAN_GROUP); loanGroupFieldBinder.registerBinder("showInSearch", PropertyBinder.instance(Boolean.TYPE, "showInSearch")); return loanGroupFieldBinder; }
From source file:jp.terasoluna.fw.web.struts.reset.ResetterImpl.java
/** * ANVtH?[wv?peBZbg?B//from w ww .j a v a2 s .c o 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.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 {//from w w w .java 2 s . c o m return false; } }
From source file:org.kuali.rice.krad.util.KRADUtils.java
/** * Attempt to coerce a String attribute value to the given propertyType. If the transformation can't be made, * either because the propertyType is null or because the transformation required exceeds this method's very small * bag of tricks, then null is returned. * * @param propertyType the Class to coerce the attributeValue to * @param attributeValue the String value to coerce * @return an instance of the propertyType class, or null the transformation can't be made. *///from w w w . j a va 2s.co m public static Object hydrateAttributeValue(Class<?> propertyType, String attributeValue) { Object attributeValueObject = null; if (propertyType != null && attributeValue != null) { if (String.class.equals(propertyType)) { // it's already a String attributeValueObject = attributeValue; } // KULRICE-6808: Kim Role Maintenance - Custom boolean role qualifier values are not being converted properly else if (Boolean.class.equals(propertyType) || Boolean.TYPE.equals(propertyType)) { attributeValueObject = Truth.strToBooleanIgnoreCase(attributeValue); } else { // try to create one with KRADUtils for other misc data types attributeValueObject = KRADUtils.createObject(propertyType, new Class[] { String.class }, new Object[] { attributeValue }); // if that didn't work, we'll get a null back } } return attributeValueObject; }
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 w w w .j a 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:org.robobinding.util.ClassUtils.java
/** * <p>/* w w w. j a va 2s . 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 w w . jav a 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; }/*ww w. j a v a 2s. c o 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; }
From source file:net.sf.ehcache.openjpa.datacache.TestEhCache.java
private void evictAllOfType(final Class<?> aClass, final boolean subClasses) { EntityManagerFactory emf = em.getEntityManagerFactory(); OpenJPAEntityManagerFactory openJPAEntityManagerFactory = OpenJPAPersistence.cast(emf); DataCache cache = ((StoreCacheImpl) openJPAEntityManagerFactory.getStoreCache()).getDelegate(); if (cache instanceof EhCacheDataCache) { EhCacheDataCache ehCache = (EhCacheDataCache) cache; try {//from ww w . ja v a 2 s.co m Method method = EhCacheDataCache.class.getDeclaredMethod("removeAllInternal", Class.class, Boolean.TYPE); method.setAccessible(true); method.invoke(ehCache, aClass, subClasses); } catch (Exception e) { e.printStackTrace(); } } }