Example usage for java.lang Boolean TYPE

List of usage examples for java.lang Boolean TYPE

Introduction

In this page you can find the example usage for java.lang Boolean TYPE.

Prototype

Class TYPE

To view the source code for java.lang Boolean TYPE.

Click Source Link

Document

The Class object representing the primitive type boolean.

Usage

From source file:javadz.beanutils.ConvertUtilsBean.java

/**
 * Register the converters for primitive types.
 * </p>//  w w w.  j  av a  2s.  co m
 * This method registers the following converters:
 * <ul>
 *     <li><code>Boolean.TYPE</code> - {@link BooleanConverter}</li>
 *     <li><code>Byte.TYPE</code> - {@link ByteConverter}</li>
 *     <li><code>Character.TYPE</code> - {@link CharacterConverter}</li>
 *     <li><code>Double.TYPE</code> - {@link DoubleConverter}</li>
 *     <li><code>Float.TYPE</code> - {@link FloatConverter}</li>
 *     <li><code>Integer.TYPE</code> - {@link IntegerConverter}</li>
 *     <li><code>Long.TYPE</code> - {@link LongConverter}</li>
 *     <li><code>Short.TYPE</code> - {@link ShortConverter}</li>
 * </ul>
 * @param throwException <code>true</code> if the converters should
 * throw an exception when a conversion error occurs, otherwise <code>
 * <code>false</code> if a default value should be used.
 */
private void registerPrimitives(boolean throwException) {
    register(Boolean.TYPE, throwException ? new BooleanConverter() : new BooleanConverter(Boolean.FALSE));
    register(Byte.TYPE, throwException ? new ByteConverter() : new ByteConverter(ZERO));
    register(Character.TYPE, throwException ? new CharacterConverter() : new CharacterConverter(SPACE));
    register(Double.TYPE, throwException ? new DoubleConverter() : new DoubleConverter(ZERO));
    register(Float.TYPE, throwException ? new FloatConverter() : new FloatConverter(ZERO));
    register(Integer.TYPE, throwException ? new IntegerConverter() : new IntegerConverter(ZERO));
    register(Long.TYPE, throwException ? new LongConverter() : new LongConverter(ZERO));
    register(Short.TYPE, throwException ? new ShortConverter() : new ShortConverter(ZERO));
}

From source file:org.apache.struts.action.DynaActionForm.java

/**
 * <p>Indicates if an object of the source class is assignable to the
 * destination class.</p>//from  w  w  w. j  a  v a  2  s.  c  o m
 *
 * @param dest   Destination class
 * @param source Source class
 * @return <code>true</code> if the source is assignable to the
 *         destination; <code>false</code> otherwise.
 */
protected boolean isDynaAssignable(Class dest, Class source) {
    if (dest.isAssignableFrom(source) || ((dest == Boolean.TYPE) && (source == Boolean.class))
            || ((dest == Byte.TYPE) && (source == Byte.class))
            || ((dest == Character.TYPE) && (source == Character.class))
            || ((dest == Double.TYPE) && (source == Double.class))
            || ((dest == Float.TYPE) && (source == Float.class))
            || ((dest == Integer.TYPE) && (source == Integer.class))
            || ((dest == Long.TYPE) && (source == Long.class))
            || ((dest == Short.TYPE) && (source == Short.class))) {
        return (true);
    } else {
        return (false);
    }
}

From source file:nl.strohalm.cyclos.controls.groups.EditGroupAction.java

private void initBasic(final BeanBinder<? extends Group> groupBinder,
        final BeanBinder<? extends BasicGroupSettings> basicSettingsBinder) {
    groupBinder.registerBinder("basicSettings", basicSettingsBinder);

    groupBinder.registerBinder("id", PropertyBinder.instance(Long.class, "id", IdConverter.instance()));
    groupBinder.registerBinder("name", PropertyBinder.instance(String.class, "name"));
    groupBinder.registerBinder("description", PropertyBinder.instance(String.class, "description"));
    groupBinder.registerBinder("status", PropertyBinder.instance(Group.Status.class, "status"));

    basicSettingsBinder.registerBinder("passwordLength",
            DataBinderHelper.rangeConstraintBinder("passwordLength"));
    basicSettingsBinder.registerBinder("passwordPolicy",
            PropertyBinder.instance(PasswordPolicy.class, "passwordPolicy"));
    basicSettingsBinder.registerBinder("maxPasswordWrongTries",
            PropertyBinder.instance(Integer.TYPE, "maxPasswordWrongTries"));
    basicSettingsBinder.registerBinder("deactivationAfterMaxPasswordTries",
            DataBinderHelper.timePeriodBinder("deactivationAfterMaxPasswordTries"));
    basicSettingsBinder.registerBinder("passwordExpiresAfter",
            DataBinderHelper.timePeriodBinder("passwordExpiresAfter"));
    basicSettingsBinder.registerBinder("transactionPassword",
            PropertyBinder.instance(TransactionPassword.class, "transactionPassword"));
    basicSettingsBinder.registerBinder("transactionPasswordLength",
            PropertyBinder.instance(Integer.TYPE, "transactionPasswordLength"));
    basicSettingsBinder.registerBinder("maxTransactionPasswordWrongTries",
            PropertyBinder.instance(Integer.TYPE, "maxTransactionPasswordWrongTries"));
    basicSettingsBinder.registerBinder("hideCurrencyOnPayments",
            PropertyBinder.instance(Boolean.TYPE, "hideCurrencyOnPayments"));
}

From source file:com.sun.faces.config.ManagedBeanFactory.java

/**
 * <li><p> Call the property getter, if it exists.</p></li>
 * <p/>/*from   w  w w.  j ava  2  s  .co  m*/
 * <li><p>If the getter returns null or doesn't exist, create a
 * java.util.ArrayList(), otherwise use the returned Object (an array or
 * a java.util.List).</p></li>
 * <p/>
 * <li><p>If a List was returned or created in step 2), add all
 * elements defined by nested &lt;value&gt; elements in the order
 * they are listed, converting values defined by nested
 * &lt;value&gt; elements to the type defined by
 * &lt;value-class&gt;. If a &lt;value-class&gt; is not defined, use
 * the value as-is (i.e., as a java.lang.String). Add null for each
 * &lt;null-value&gt; element.</p></li>
 * <p/>
 * <li><p> If an array was returned in step 2), create a
 * java.util.ArrayList and copy all elements from the returned array to
 * the new List, auto-boxing elements of a primitive type. Add all
 * elements defined by nested &lt;value&gt; elements as described in step
 * 3).</p></li>
 * <p/>
 * <li><p> If a new java.util.List was created in step 2) and the
 * property is of type List, set the property by calling the setter
 * method, or log an error if there is no setter method.</p></li>
 * <p/>
 * <li><p> If a new java.util.List was created in step 4), convert
 * the * List to array of the same type as the property and set the
 * property by * calling the setter method, or log an error if there
 * is no setter * method.</p></li>
 */

private void setArrayOrListPropertiesIntoBean(Object bean, ManagedPropertyBean property) throws Exception {
    Object result = null;
    boolean getterIsNull = true, getterIsArray = false;
    List valuesForBean = null;
    Class valueType = java.lang.String.class, propertyType = null;

    String propertyName = property.getPropertyName();

    try {
        // see if there is a getter
        result = PropertyUtils.getProperty(bean, propertyName);
        getterIsNull = (null == result) ? true : false;

        propertyType = PropertyUtils.getPropertyType(bean, propertyName);
        getterIsArray = propertyType.isArray();

    } catch (NoSuchMethodException nsme) {
        // it's valid to not have a getter.
    }

    // the property has to be either a List or Array
    if (!getterIsArray) {
        if (null != propertyType && !java.util.List.class.isAssignableFrom(propertyType)) {
            throw new FacesException(
                    Util.getExceptionMessageString(Util.MANAGED_BEAN_CANNOT_SET_LIST_ARRAY_PROPERTY_ID,
                            new Object[] { propertyName, managedBean.getManagedBeanName() }));
        }
    }

    //
    // Deal with the possibility of the getter returning existing
    // values.
    //

    // if the getter returned non-null
    if (!getterIsNull) {
        // if what it returned was an array
        if (getterIsArray) {
            valuesForBean = new ArrayList();
            for (int i = 0, len = Array.getLength(result); i < len; i++) {
                // add the existing values
                valuesForBean.add(Array.get(result, i));
            }
        } else {
            // if what it returned was not a List
            if (!(result instanceof List)) {
                // throw an exception                    
                throw new FacesException(
                        Util.getExceptionMessageString(Util.MANAGED_BEAN_EXISTING_VALUE_NOT_LIST_ID,
                                new Object[] { propertyName, managedBean.getManagedBeanName() }));
            }
            valuesForBean = (List) result;
        }
    } else {

        // getter returned null
        result = valuesForBean = new ArrayList();
    }

    // at this point valuesForBean contains the existing values from
    // the bean, or no values if the bean had no values.  In any
    // case, we can proceed to add values from the config file.
    valueType = copyListEntriesFromConfigToList(property.getListEntries(), valuesForBean);

    // at this point valuesForBean has the values to be set into the
    // bean.

    if (getterIsArray) {
        // convert back to Array
        result = Array.newInstance(valueType, valuesForBean.size());
        for (int i = 0, len = valuesForBean.size(); i < len; i++) {
            if (valueType == Boolean.TYPE) {
                Array.setBoolean(result, i, ((Boolean) valuesForBean.get(i)).booleanValue());
            } else if (valueType == Byte.TYPE) {
                Array.setByte(result, i, ((Byte) valuesForBean.get(i)).byteValue());
            } else if (valueType == Double.TYPE) {
                Array.setDouble(result, i, ((Double) valuesForBean.get(i)).doubleValue());
            } else if (valueType == Float.TYPE) {
                Array.setFloat(result, i, ((Float) valuesForBean.get(i)).floatValue());
            } else if (valueType == Integer.TYPE) {
                Array.setInt(result, i, ((Integer) valuesForBean.get(i)).intValue());
            } else if (valueType == Character.TYPE) {
                Array.setChar(result, i, ((Character) valuesForBean.get(i)).charValue());
            } else if (valueType == Short.TYPE) {
                Array.setShort(result, i, ((Short) valuesForBean.get(i)).shortValue());
            } else if (valueType == Long.TYPE) {
                Array.setLong(result, i, ((Long) valuesForBean.get(i)).longValue());
            } else {
                Array.set(result, i, valuesForBean.get(i));
            }
        }
    } else {
        result = valuesForBean;
    }

    if (getterIsNull || getterIsArray) {
        PropertyUtils.setProperty(bean, propertyName, result);
    }

}

From source file:it.unibo.alchemist.language.EnvironmentBuilder.java

@SuppressWarnings("unchecked")
private static Object parseAndCreate(final Class<?> clazz, final String val, final Map<String, Object> env,
        final RandomGenerator random)
        throws InstantiationException, IllegalAccessException, InvocationTargetException {
    if (clazz.isAssignableFrom(RandomGenerator.class) && val.equalsIgnoreCase("random")) {
        L.debug("Random detected! Class " + clazz.getSimpleName() + ", param: " + val);
        if (random == null) {
            L.error("Random instatiation required, but RandomGenerator not yet defined.");
        }//from   w  w  w .  j av  a2 s.  c o m
        return random;
    }
    if (clazz.isPrimitive() || PrimitiveUtils.classIsWrapper(clazz)) {
        L.debug(val + " is a primitive or a wrapper: " + clazz);
        if ((clazz.isAssignableFrom(Boolean.TYPE) || clazz.isAssignableFrom(Boolean.class))
                && (val.equalsIgnoreCase("true") || val.equalsIgnoreCase("false"))) {
            return Boolean.parseBoolean(val);
        }
        /*
         * If Number is in clazz's hierarchy
         */
        if (PrimitiveUtils.classIsNumber(clazz)) {
            final Optional<Number> num = extractNumber(val);
            if (num.isPresent()) {
                final Optional<Number> castNum = PrimitiveUtils.castIfNeeded(clazz, num.get());
                /*
                 * If method requires Object or unsupported Number, return
                 * what was parsed.
                 */
                return castNum.orElse(num.get());
            }
        }
        if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) {
            return val.charAt(0);
        }
    }
    if (List.class.isAssignableFrom(clazz) && val.startsWith("[") && val.endsWith("]")) {
        final List<Constructor<List<?>>> l = unsafeExtractConstructors(clazz);
        @SuppressWarnings("rawtypes")
        final List list = tryToBuild(l, new ArrayList<String>(0), env, random);
        final StringTokenizer strt = new StringTokenizer(val.substring(1, val.length() - 1), ",; ");
        while (strt.hasMoreTokens()) {
            final String sub = strt.nextToken();
            final Object o = tryToParse(sub, env, random);
            if (o == null) {
                L.debug("WARNING: list elemnt skipped: " + sub);
            } else {
                list.add(o);
            }
        }
        return list;
    }
    L.debug(val + " is not a primitive: " + clazz + ". Searching it in the environment...");
    final Object o = env.get(val);
    if (o != null && clazz.isInstance(o)) {
        return o;
    }
    if (Time.class.isAssignableFrom(clazz)) {
        return new DoubleTime(Double.parseDouble(val));
    }
    if (clazz.isAssignableFrom(String.class)) {
        L.debug("String detected! Passing " + val + " back.");
        return val;
    }
    L.debug(val + " not found or class not compatible, unable to go further.");
    return null;
}

From source file:android.support.custom.view.VerticalViewPager.java

void setChildrenDrawingOrderEnabledCompat(boolean enable) {
    if (mSetChildrenDrawingOrderEnabled == null) {
        try {//from   w  w  w .j  a  v a2 s . co m
            mSetChildrenDrawingOrderEnabled = ViewGroup.class
                    .getDeclaredMethod("setChildrenDrawingOrderEnabled", new Class[] { Boolean.TYPE });
        } catch (NoSuchMethodException e) {
            Log.e(TAG, "Can't find setChildrenDrawingOrderEnabled", e);
        }
    }
    try {
        mSetChildrenDrawingOrderEnabled.invoke(this, enable);
    } catch (Exception e) {
        Log.e(TAG, "Error changing children drawing order", e);
    }
}

From source file:nl.strohalm.cyclos.controls.groups.EditGroupAction.java

private void initMember(final BeanBinder<? extends MemberGroup> memberGroupBinder,
        final BeanBinder<? extends MemberGroupSettings> memberSettingsBinder) {
    memberGroupBinder.registerBinder("memberSettings", memberSettingsBinder);
    memberGroupBinder.registerBinder("active", PropertyBinder.instance(Boolean.TYPE, "active"));
    memberGroupBinder.registerBinder("initialGroup", PropertyBinder.instance(Boolean.TYPE, "initialGroup"));
    memberGroupBinder.registerBinder("initialGroupShow",
            PropertyBinder.instance(String.class, "initialGroupShow"));
    memberGroupBinder.registerBinder("registrationAgreement",
            PropertyBinder.instance(RegistrationAgreement.class, "registrationAgreement"));
    memberGroupBinder.registerBinder("defaultMailMessages",
            SimpleCollectionBinder.instance(Message.Type.class, "defaultMailMessages"));
    memberGroupBinder.registerBinder("smsMessages",
            SimpleCollectionBinder.instance(Message.Type.class, "smsMessages"));
    memberGroupBinder.registerBinder("defaultSmsMessages",
            SimpleCollectionBinder.instance(Message.Type.class, "defaultSmsMessages"));
    memberGroupBinder.registerBinder("defaultAllowChargingSms",
            PropertyBinder.instance(Boolean.TYPE, "defaultAllowChargingSms"));
    memberGroupBinder.registerBinder("defaultAcceptFreeMailing",
            PropertyBinder.instance(Boolean.TYPE, "defaultAcceptFreeMailing"));
    memberGroupBinder.registerBinder("defaultAcceptPaidMailing",
            PropertyBinder.instance(Boolean.TYPE, "defaultAcceptPaidMailing"));
    memberGroupBinder.registerBinder("channels", SimpleCollectionBinder.instance(Channel.class, "channels"));
    memberGroupBinder.registerBinder("defaultChannels",
            SimpleCollectionBinder.instance(Channel.class, "defaultChannels"));
    memberGroupBinder.registerBinder("cardType", PropertyBinder.instance(CardType.class, "cardType"));

    final LocalSettings localSettings = settingsService.getLocalSettings();
    memberSettingsBinder.registerBinder("pinLength", DataBinderHelper.rangeConstraintBinder("pinLength"));
    memberSettingsBinder.registerBinder("maxPinWrongTries",
            PropertyBinder.instance(Integer.TYPE, "maxPinWrongTries"));
    memberSettingsBinder.registerBinder("pinBlockTimeAfterMaxTries",
            DataBinderHelper.timePeriodBinder("pinBlockTimeAfterMaxTries"));
    memberSettingsBinder.registerBinder("pinLength", DataBinderHelper.rangeConstraintBinder("pinLength"));
    memberSettingsBinder.registerBinder("smsChargeTransferType",
            PropertyBinder.instance(TransferType.class, "smsChargeTransferType"));
    memberSettingsBinder.registerBinder("smsChargeAmount",
            PropertyBinder.instance(BigDecimal.class, "smsChargeAmount", localSettings.getNumberConverter()));
    memberSettingsBinder.registerBinder("smsFree", PropertyBinder.instance(Integer.TYPE, "smsFree"));
    memberSettingsBinder.registerBinder("smsShowFreeThreshold",
            PropertyBinder.instance(Integer.TYPE, "smsShowFreeThreshold"));
    memberSettingsBinder.registerBinder("smsAdditionalCharged",
            PropertyBinder.instance(Integer.TYPE, "smsAdditionalCharged"));
    memberSettingsBinder.registerBinder("smsAdditionalChargedPeriod",
            DataBinderHelper.timePeriodBinder("smsAdditionalChargedPeriod"));
    memberSettingsBinder.registerBinder("smsContextClassName",
            PropertyBinder.instance(String.class, "smsContextClassName"));

    memberSettingsBinder.registerBinder("maxAdsPerMember",
            PropertyBinder.instance(Integer.TYPE, "maxAdsPerMember"));
    memberSettingsBinder.registerBinder("maxAdImagesPerMember",
            PropertyBinder.instance(Integer.TYPE, "maxAdImagesPerMember"));
    memberSettingsBinder.registerBinder("defaultAdPublicationTime",
            DataBinderHelper.timePeriodBinder("defaultAdPublicationTime"));
    memberSettingsBinder.registerBinder("maxAdPublicationTime",
            DataBinderHelper.timePeriodBinder("maxAdPublicationTime"));
    memberSettingsBinder.registerBinder("enablePermanentAds",
            PropertyBinder.instance(Boolean.TYPE, "enablePermanentAds"));
    memberSettingsBinder.registerBinder("externalAdPublication",
            PropertyBinder.instance(MemberGroupSettings.ExternalAdPublication.class, "externalAdPublication"));
    memberSettingsBinder.registerBinder("maxAdDescriptionSize",
            PropertyBinder.instance(Integer.TYPE, "maxAdDescriptionSize"));
    memberSettingsBinder.registerBinder("sendPasswordByEmail",
            PropertyBinder.instance(Boolean.TYPE, "sendPasswordByEmail"));
    memberSettingsBinder.registerBinder("emailValidation",
            SimpleCollectionBinder.instance(EmailValidation.class, HashSet.class, "emailValidation"));
    memberSettingsBinder.registerBinder("maxImagesPerMember",
            PropertyBinder.instance(Integer.TYPE, "maxImagesPerMember"));
    memberSettingsBinder.registerBinder("viewLoansByGroup",
            PropertyBinder.instance(Boolean.TYPE, "viewLoansByGroup"));
    memberSettingsBinder.registerBinder("repayLoanByGroup",
            PropertyBinder.instance(Boolean.TYPE, "repayLoanByGroup"));
    memberSettingsBinder.registerBinder("maxSchedulingPayments",
            PropertyBinder.instance(Integer.TYPE, "maxSchedulingPayments"));
    memberSettingsBinder.registerBinder("maxSchedulingPeriod",
            DataBinderHelper.timePeriodBinder("maxSchedulingPeriod"));
    memberSettingsBinder.registerBinder("showPosWebPaymentDescription",
            PropertyBinder.instance(Boolean.TYPE, "showPosWebPaymentDescription"));
    memberSettingsBinder.registerBinder("expireMembersAfter",
            DataBinderHelper.timePeriodBinder("expireMembersAfter"));
    memberSettingsBinder.registerBinder("groupAfterExpiration",
            PropertyBinder.instance(MemberGroup.class, "groupAfterExpiration"));
}

From source file:ResultSetIterator.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.// w w w .  j  a va  2 s  . c  om
 * 
 * @param value The value to be passed into the setter method.
 * @param type The setter's parameter type.
 * @return boolean True if the value is compatible.
 */
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;

    } else {
        return false;
    }

}

From source file:com.github.helenusdriver.driver.impl.FieldInfoImpl.java

/**
 * Finds the getter method from the declaring class suitable to get a
 * reference to the field./*from w w w.j  av a 2  s  . c o  m*/
 *
 * @author paouelle
 *
 * @param  declaringClass the non-<code>null</code> class declaring the field
 * @return the getter method for the field or <code>null</code> if none found
 * @throws IllegalArgumentException if unable to find a suitable getter
 */
private Method findGetterMethod(Class<?> declaringClass) {
    Method getter = findGetterMethod(declaringClass, "get");

    if ((getter == null) && (type == Boolean.class) || (type == Boolean.TYPE)) {
        // try for "is"
        getter = findGetterMethod(declaringClass, "is");
    }
    return getter;
}