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:jef.tools.ArrayUtils.java

/**
 * ?/* w  ww . ja  v  a2 s .co  m*/
 * 
 * @param obj
 * @return
 */
public static Object[] toObject(Object obj) {
    Class<?> c = obj.getClass();
    Assert.isTrue(c.isArray());
    Class<?> priType = c.getComponentType();
    if (!priType.isPrimitive())
        return (Object[]) obj;
    if (priType == Boolean.TYPE) {
        return toObject((boolean[]) obj);
    } else if (priType == Byte.TYPE) {
        return toObject((byte[]) obj);
    } else if (priType == Character.TYPE) {
        return toObject((char[]) obj);
    } else if (priType == Integer.TYPE) {
        return toObject((int[]) obj);
    } else if (priType == Long.TYPE) {
        return toObject((long[]) obj);
    } else if (priType == Float.TYPE) {
        return toObject((float[]) obj);
    } else if (priType == Double.TYPE) {
        return toObject((double[]) obj);
    } else if (priType == Short.TYPE) {
        return toObject((short[]) obj);
    }
    throw new IllegalArgumentException();
}

From source file:org.evosuite.regression.ObjectFields.java

private static Object getFieldValue(Field field, Object p) {
    try {//from w ww .  j a va 2 s. com
        /*Class objClass = p.getClass();
        if(p instanceof java.lang.String){
           ((String) p).hashCode();
        }*/
        Class<?> fieldType = field.getType();
        field.setAccessible(true);
        if (fieldType.isPrimitive()) {
            if (fieldType.equals(Boolean.TYPE)) {
                return field.getBoolean(p);
            }
            if (fieldType.equals(Integer.TYPE)) {
                return field.getInt(p);
            }
            if (fieldType.equals(Byte.TYPE)) {
                return field.getByte(p);
            }
            if (fieldType.equals(Short.TYPE)) {
                return field.getShort(p);
            }
            if (fieldType.equals(Long.TYPE)) {
                return field.getLong(p);
            }
            if (fieldType.equals(Double.TYPE)) {
                return field.getDouble(p);
            }
            if (fieldType.equals(Float.TYPE)) {
                return field.getFloat(p);
            }
            if (fieldType.equals(Character.TYPE)) {
                return field.getChar(p);
            }
            throw new UnsupportedOperationException("Primitive type " + fieldType + " not implemented!");
        }
        return field.get(p);
    } catch (IllegalAccessException exc) {
        throw new RuntimeException(exc);
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        if (MAX_RECURSION != 0)
            MAX_RECURSION = 0;
        else
            throw new RuntimeErrorException(e);
        return getFieldValue(field, p);
    }
}

From source file:org.atemsource.atem.impl.common.attribute.primitive.PrimitiveTypeFactory.java

@PostConstruct
public void initialize() {
    classes = new ArrayList<Class>();
    classes.add(String.class);
    classes.add(Boolean.class);
    classes.add(Boolean.TYPE);
    classes.add(Long.class);
    classes.add(Long.TYPE);/*from   w w  w  . j av a 2  s. co m*/
    classes.add(Integer.class);
    classes.add(Integer.TYPE);
    classes.add(Float.class);
    classes.add(Float.TYPE);
    classes.add(Double.TYPE);
    classes.add(Double.class);
    classes.add(Character.TYPE);
    classes.add(Character.TYPE);
    classes.add(Character.class);
    classes.add(Byte.TYPE);
    classes.add(Byte.class);
    classes.add(Enum.class);
    classes.add(BigInteger.class);
    classes.add(BigDecimal.class);
    Collection<PrimitiveTypeRegistrar> registrars = beanLocator.getInstances(PrimitiveTypeRegistrar.class);
    for (PrimitiveTypeRegistrar registrar : registrars) {
        PrimitiveType<?>[] types = registrar.getTypes();
        for (PrimitiveType<?> primitiveType : types) {
            classToType.put(primitiveType.getJavaType(), primitiveType);
            classes.add(primitiveType.getJavaType());
        }
    }
}

From source file:nl.strohalm.cyclos.controls.ads.SearchAdsAction.java

public static DataBinder<FullTextAdQuery> adFullTextQueryDataBinder(final LocalSettings settings) {

    final BeanBinder<AdCustomFieldValue> adCustomValueBinder = BeanBinder.instance(AdCustomFieldValue.class);
    adCustomValueBinder.registerBinder("field", PropertyBinder.instance(AdCustomField.class, "field",
            ReferenceConverter.instance(AdCustomField.class)));
    adCustomValueBinder.registerBinder("value", PropertyBinder.instance(String.class, "value"));

    final BeanBinder<MemberCustomFieldValue> memberCustomValueBinder = BeanBinder
            .instance(MemberCustomFieldValue.class);
    memberCustomValueBinder.registerBinder("field", PropertyBinder.instance(MemberCustomField.class, "field",
            ReferenceConverter.instance(MemberCustomField.class)));
    memberCustomValueBinder.registerBinder("value", PropertyBinder.instance(String.class, "value"));

    final BeanBinder<FullTextAdQuery> binder = BeanBinder.instance(FullTextAdQuery.class);
    binder.registerBinder("groupFilters", SimpleCollectionBinder.instance(GroupFilter.class, "groupFilters"));
    binder.registerBinder("groups", SimpleCollectionBinder.instance(MemberGroup.class, "groups"));
    binder.registerBinder("tradeType", PropertyBinder.instance(Ad.TradeType.class, "tradeType"));
    binder.registerBinder("status", PropertyBinder.instance(Ad.Status.class, "status"));
    binder.registerBinder("keywords", PropertyBinder.instance(String.class, "keywords"));
    binder.registerBinder("category", PropertyBinder.instance(AdCategory.class, "category",
            ReferenceConverter.instance(AdCategory.class)));
    binder.registerBinder("since", DataBinderHelper.timePeriodBinder("since"));
    binder.registerBinder("initialPrice",
            PropertyBinder.instance(BigDecimal.class, "initialPrice", settings.getNumberConverter()));
    binder.registerBinder("finalPrice",
            PropertyBinder.instance(BigDecimal.class, "finalPrice", settings.getNumberConverter()));
    binder.registerBinder("currency", PropertyBinder.instance(Currency.class, "currency"));
    binder.registerBinder("withImagesOnly", PropertyBinder.instance(Boolean.TYPE, "withImagesOnly"));
    binder.registerBinder("adValues", BeanCollectionBinder.instance(adCustomValueBinder, "adValues"));
    binder.registerBinder("memberValues",
            BeanCollectionBinder.instance(memberCustomValueBinder, "memberValues"));
    binder.registerBinder("pageParameters", DataBinderHelper.pageBinder());

    return binder;
}

From source file:com.epam.catgenome.manager.externaldb.bindings.ExternalDBBindingTest.java

private Object createParam(Class type)
        throws IllegalAccessException, InvocationTargetException, InstantiationException {
    Object param;/*from  w  ww .  j a va2 s. co  m*/
    if (type == String.class) {
        param = "test";
    } else if (type == Integer.class || type == Integer.TYPE) {
        param = RandomUtils.nextInt();
    } else if (type == Long.class || type == Long.TYPE) {
        param = RandomUtils.nextLong();
    } else if (type == Float.class || type == Float.TYPE) {
        param = RandomUtils.nextFloat();
    } else if (type == Double.class || type == Double.TYPE) {
        param = RandomUtils.nextDouble();
    } else if (type == Boolean.class || type == Boolean.TYPE) {
        param = RandomUtils.nextBoolean();
    } else if (type == BigInteger.class) {
        param = new BigInteger(TEST_BIGINTEGER);
    } else if (type == List.class) {
        param = new ArrayList<>();
    } else if (type == XMLGregorianCalendar.class) {
        try {
            param = DatatypeFactory.newInstance().newXMLGregorianCalendar();
        } catch (DatatypeConfigurationException e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    } else {
        Constructor[] constructors = type.getConstructors();
        param = constructors[0].newInstance();
    }

    return param;
}

From source file:candr.yoclip.option.OptionField.java

@Override
public void setOption(final T bean, final String value) {

    final Class<?> fieldType = getField().getType();
    try {/*w w w  .j  a  v a 2s. co m*/

        if (Boolean.TYPE.equals(fieldType) || Boolean.class.isAssignableFrom(fieldType)) {
            setBooleanOption(bean, value);

        } else if (Byte.TYPE.equals(fieldType) || Byte.class.isAssignableFrom(fieldType)) {
            setByteOption(bean, value);

        } else if (Short.TYPE.equals(fieldType) || Short.class.isAssignableFrom(fieldType)) {
            setShortOption(bean, value);

        } else if (Integer.TYPE.equals(fieldType) || Integer.class.isAssignableFrom(fieldType)) {
            setIntegerOption(bean, value);

        } else if (Long.TYPE.equals(fieldType) || Long.class.isAssignableFrom(fieldType)) {
            setLongOption(bean, value);

        } else if (Character.TYPE.equals(fieldType) || Character.class.isAssignableFrom(fieldType)) {
            setCharacterOption(bean, value);

        } else if (Float.TYPE.equals(fieldType) || Float.class.isAssignableFrom(fieldType)) {
            setFloatOption(bean, value);

        } else if (Double.TYPE.equals(fieldType) || Double.class.isAssignableFrom(fieldType)) {
            setDoubleOption(bean, value);

        } else if (String.class.isAssignableFrom(fieldType)) {
            setStringOption(bean, value);

        } else {
            final String supportedTypes = "boolean, byte, short, int, long, char, float, double, and String";
            throw new OptionsParseException(
                    String.format("OldOptionsParser only support %s types", supportedTypes));
        }

    } catch (NumberFormatException e) {
        final String error = String.format("Error converting '%s' to %s", value, fieldType);
        throw new OptionsParseException(error, e);
    }
}

From source file:nl.strohalm.cyclos.controls.members.preferences.NotificationPreferenceAction.java

@Override
protected ActionForward handleSubmit(final ActionContext context) throws Exception {
    final NotificationPreferenceForm form = context.getForm();
    long memberId = form.getMemberId();

    if (memberId < 1) {
        memberId = context.getElement().getId();
    }//from ww  w  .j  a  va  2  s  . c  o  m

    // Load member and member group
    final Member member = elementService.load(memberId,
            RelationshipHelper.nested(Element.Relationships.GROUP, MemberGroup.Relationships.SMS_MESSAGES),
            Member.Relationships.CHANNELS);

    // Load member notification preferences
    Collection<NotificationPreference> list = preferenceService.load(member);
    if (list == null) {
        list = new ArrayList<NotificationPreference>();
    }

    // Store notification preferences by type
    final Map<Message.Type, NotificationPreference> map = new HashMap<Message.Type, NotificationPreference>();
    for (final NotificationPreference preference : list) {
        map.put(preference.getType(), preference);
    }

    // Check if the member have e-mail
    final boolean hasEmail = StringUtils.isNotEmpty(member.getEmail());

    final LocalSettings localSettings = settingsService.getLocalSettings();
    final boolean smsEnabled = localSettings.isSmsEnabled();
    boolean hasNotificationsBySms = false;
    // Save the notification preferences
    final List<Message.Type> usedTypes = preferenceService.listNotificationTypes(member);
    for (final Message.Type type : Message.Type.values()) {
        final String isEmailStr = (String) form.getNotificationPreference(type.name() + "_email");
        final String isMessageStr = (String) form.getNotificationPreference(type.name() + "_message");
        final String isSmsStr = (String) form.getNotificationPreference(type.name() + "_sms");

        boolean isEmail = false;
        boolean isMessage = false;
        boolean isSms = false;

        // If not use type, use both as false
        if (usedTypes.contains(type)) {
            isEmail = hasEmail ? CoercionHelper.coerce(Boolean.TYPE, isEmailStr) : false;
            isMessage = CoercionHelper.coerce(Boolean.TYPE, isMessageStr);
            if (type == Message.Type.FROM_ADMIN_TO_MEMBER || type == Message.Type.FROM_ADMIN_TO_GROUP) {
                isMessage = true;
            }
            if (smsEnabled) {
                isSms = CoercionHelper.coerce(Boolean.TYPE, isSmsStr);
            }
        }
        hasNotificationsBySms |= isSms;
        NotificationPreference preference = map.get(type);
        if (preference == null && (isEmail || isMessage || isSms)) {
            // Insert new notification preference
            preference = new NotificationPreference();
            preference.setType(type);
            preference.setEmail(isEmail);
            preference.setMessage(isMessage);
            preference.setSms(isSms);
            map.put(type, preference);
        } else if (preference != null) {
            // Update an existing notification preference
            preference.setEmail(isEmail);
            preference.setMessage(isMessage);
            preference.setSms(isSms);
        }
    }
    preferenceService.save(member, map.values());

    if (smsEnabled) {
        // Store the sms operations channel
        final Channel smsChannel = channelService.getSmsChannel();

        if (accessService.canChangeChannelsAccess(member) && smsChannel != null) {
            final Set<Channel> channels = new HashSet<Channel>(
                    accessService.getChannelsEnabledForMember(member));
            if (form.isEnableSmsOperations()) {
                channels.add(smsChannel);
            } else {
                channels.remove(smsChannel);
            }
            accessService.changeChannelsAccess(member, channels, false);
        }
        // The other flags come from the member sms status
        preferenceService.saveSmsStatusPreferences(member, form.isAcceptFreeMailing(),
                form.isAcceptPaidMailing(), form.isAllowChargingSms(), hasNotificationsBySms);
    }

    context.sendMessage("notificationPreferences.modified");
    if (context.getElement().getId() == memberId) { // my preferences
        return context.getSuccessForward();
    } else {
        return ActionHelper.redirectWithParam(context.getRequest(), context.getSuccessForward(), "memberId",
                memberId);
    }
}

From source file:org.projectforge.continuousdb.TableAttribute.java

/**
 * Creates a property and gets the information from the entity class. The JPA annotations Column, JoinColumn, Entity,
 * Table and ID are supported./*  w  w  w  .j av  a 2  s. c o m*/
 *
 * @param clazz
 * @param property
 */
public TableAttribute(final Class<?> clazz, final String property) {
    final Method getterMethod = BeanHelper.determineGetter(clazz, property, false);
    if (getterMethod == null) {
        throw new IllegalStateException("Can't determine getter: " + clazz + "." + property);
    }
    this.entityClass = clazz;
    this.property = property;
    this.name = property;
    this.propertyType = BeanHelper.determinePropertyType(getterMethod);
    // final boolean typePropertyPresent = false;
    // final String typePropertyValue = null;
    for (final TableAttributeHook hook : hooks) {
        this.type = hook.determineType(getterMethod);
        if (this.type != null) {
            break;
        }
    }
    final boolean primitive = this.propertyType.isPrimitive();
    if (JPAHelper.isPersistenceAnnotationPresent(getterMethod) == false) {
        log.warn(
                "************** ProjectForge schema updater expect JPA annotations at getter method such as @Column for proper functioning!");
    }
    if (this.type != null) {
        // Type is already determined.
    } else if (Boolean.class.isAssignableFrom(this.propertyType) == true
            || Boolean.TYPE.isAssignableFrom(this.propertyType) == true) {
        this.type = TableAttributeType.BOOLEAN;
    } else if (Integer.class.isAssignableFrom(this.propertyType) == true
            || Integer.TYPE.isAssignableFrom(this.propertyType) == true) {
        this.type = TableAttributeType.INT;
    } else if (Long.class.isAssignableFrom(this.propertyType) == true
            || Long.TYPE.isAssignableFrom(this.propertyType) == true) {
        this.type = TableAttributeType.LONG;
    } else if (Short.class.isAssignableFrom(this.propertyType) == true
            || Short.TYPE.isAssignableFrom(this.propertyType) == true) {
        this.type = TableAttributeType.SHORT;
    } else if (String.class.isAssignableFrom(this.propertyType) == true || this.propertyType.isEnum() == true) {
        this.type = TableAttributeType.VARCHAR;
    } else if (BigDecimal.class.isAssignableFrom(this.propertyType) == true) {
        this.type = TableAttributeType.DECIMAL;
    } else if (java.sql.Date.class.isAssignableFrom(this.propertyType) == true) {
        this.type = TableAttributeType.DATE;
    } else if (java.util.Date.class.isAssignableFrom(this.propertyType) == true) {
        this.type = TableAttributeType.TIMESTAMP;
    } else if (java.util.Locale.class.isAssignableFrom(this.propertyType) == true) {
        this.type = TableAttributeType.LOCALE;
    } else if (java.util.List.class.isAssignableFrom(this.propertyType) == true) {
        this.type = TableAttributeType.LIST;
        this.setGenericReturnType(getterMethod);
    } else if (java.util.Set.class.isAssignableFrom(this.propertyType) == true) {
        this.type = TableAttributeType.SET;
        this.setGenericReturnType(getterMethod);
        // } else if (typePropertyPresent == true && "binary".equals(typePropertyValue) == true) {
        // type = TableAttributeType.BINARY;
    } else {
        final Entity entity = this.propertyType.getAnnotation(Entity.class);
        if (entity != null) {
            final javax.persistence.Table table = this.propertyType
                    .getAnnotation(javax.persistence.Table.class);
            if (table != null) {
                this.foreignTable = table.name();
            } else {
                this.foreignTable = new Table(this.propertyType).getName();
            }
            // if (entity != null && table != null && StringUtils.isNotEmpty(table.name()) == true) {
            final String idProperty = JPAHelper.getIdProperty(this.propertyType);
            if (idProperty == null) {
                log.info("Id property not found for class '" + this.propertyType + "'): " + clazz + "."
                        + property);
            }
            this.foreignAttribute = idProperty;
            final Column column = JPAHelper.getColumnAnnotation(this.propertyType, idProperty);
            if (column != null && StringUtils.isNotEmpty(column.name()) == true) {
                this.foreignAttribute = column.name();
            }
        } else {
            log.info("Unsupported property (@Entity expected for the destination class '" + this.propertyType
                    + "'): " + clazz + "." + property);
        }
        this.type = TableAttributeType.INT;
    }
    this.annotations = JPAHelper.getPersistenceAnnotations(getterMethod);
    final Id id = JPAHelper.getIdAnnotation(clazz, property);
    if (id != null) {
        this.primaryKey = true;
        this.nullable = false;
    }
    if (primitive == true) {
        this.nullable = false;
    }
    final Column column = JPAHelper.getColumnAnnotation(clazz, property);
    if (column != null) {
        if (this.isPrimaryKey() == false && primitive == false) {
            this.nullable = column.nullable();
        }
        if (StringUtils.isNotEmpty(column.name()) == true) {
            this.name = column.name();
        }
        if (this.type.isIn(TableAttributeType.VARCHAR, TableAttributeType.CHAR) == true) {
            this.length = column.length();
        }
        if (this.type == TableAttributeType.DECIMAL) {
            this.precision = column.precision();
            this.scale = column.scale();
        }
        this.unique = column.unique();
    }
    if (this.type == TableAttributeType.DECIMAL && this.scale == 0 && this.precision == 0) {
        throw new UnsupportedOperationException(
                "Decimal values should have a precision and scale definition: " + clazz + "." + property);
    }
    final JoinColumn joinColumn = JPAHelper.getJoinColumnAnnotation(clazz, property);
    if (joinColumn != null) {
        if (StringUtils.isNotEmpty(joinColumn.name()) == true) {
            this.name = joinColumn.name();
        }
        if (joinColumn.nullable() == false) {
            this.nullable = false;
        }
    }
}

From source file:com.nonninz.robomodel.RoboModel.java

private void loadField(Field field, Cursor query) throws DatabaseNotUpToDateException {
    final Class<?> type = field.getType();
    final boolean wasAccessible = field.isAccessible();
    final int columnIndex = query.getColumnIndex(field.getName());
    field.setAccessible(true);//w  w w  .j a v  a  2 s  . c  o m

    /*
     * TODO: There is the potential of a problem here:
     * What happens if the developer changes the type of a field between releases?
     *
     * If he saves first, then the column type will be changed (In the future).
     * If he loads first, we don't know if an Exception will be thrown if the
     * types are incompatible, because it's undocumented in the Cursor documentation.
     */

    try {
        if (type == String.class) {
            field.set(this, query.getString(columnIndex));
        } else if (type == Boolean.TYPE) {
            final boolean value = query.getInt(columnIndex) == 1 ? true : false;
            field.setBoolean(this, value);
        } else if (type == Byte.TYPE) {
            field.setByte(this, (byte) query.getShort(columnIndex));
        } else if (type == Double.TYPE) {
            field.setDouble(this, query.getDouble(columnIndex));
        } else if (type == Float.TYPE) {
            field.setFloat(this, query.getFloat(columnIndex));
        } else if (type == Integer.TYPE) {
            field.setInt(this, query.getInt(columnIndex));
        } else if (type == Long.TYPE) {
            field.setLong(this, query.getLong(columnIndex));
        } else if (type == Short.TYPE) {
            field.setShort(this, query.getShort(columnIndex));
        } else if (type.isEnum()) {
            final String string = query.getString(columnIndex);
            if (string != null && string.length() > 0) {
                final Object[] constants = type.getEnumConstants();
                final Method method = type.getMethod("valueOf", Class.class, String.class);
                final Object value = method.invoke(constants[0], type, string);
                field.set(this, value);
            }
        } else {
            // Try to de-json it (db column must be of type text)
            try {
                final Object value = mMapper.readValue(query.getString(columnIndex), field.getType());
                field.set(this, value);
            } catch (final Exception e) {
                final String msg = String.format("Type %s is not supported for field %s", type,
                        field.getName());
                Ln.w(e, msg);
                throw new IllegalArgumentException(msg);
            }
        }
    } catch (final IllegalAccessException e) {
        final String msg = String.format("Field %s is not accessible", type, field.getName());
        throw new IllegalArgumentException(msg);
    } catch (final NoSuchMethodException e) {
        // Should not happen
        throw new RuntimeException(e);
    } catch (final InvocationTargetException e) {
        // Should not happen
        throw new RuntimeException(e);
    } catch (IllegalStateException e) {
        // This is when there is no column in db, but there is in the model
        throw new DatabaseNotUpToDateException(e);
    } finally {
        field.setAccessible(wasAccessible);
    }
}

From source file:in.hatimi.nosh.support.CmdLineManager.java

private boolean injectString(Object target, Field field, String value) {
    if (field.getType().equals(Boolean.class) || field.getType().equals(Boolean.TYPE)) {
        Boolean vobj = new Boolean(value);
        return injectImpl(target, field, vobj);
    }//from  w ww  . j a  v a 2  s . com
    if (field.getType().equals(Double.class) || field.getType().equals(Double.TYPE)) {
        Double vobj = Double.valueOf(value);
        return injectImpl(target, field, vobj);
    }
    if (field.getType().equals(Float.class) || field.getType().equals(Float.TYPE)) {
        Float vobj = Float.valueOf(value);
        return injectImpl(target, field, vobj);
    }
    if (field.getType().equals(Long.class) || field.getType().equals(Long.TYPE)) {
        Long vobj = Long.valueOf(value);
        return injectImpl(target, field, vobj);
    }
    if (field.getType().equals(Integer.class) || field.getType().equals(Integer.TYPE)) {
        Integer vobj = Integer.valueOf(value);
        return injectImpl(target, field, vobj);
    }
    if (field.getType().equals(String.class)) {
        return injectImpl(target, field, value);
    }
    if (field.getType().equals(byte[].class)) {
        return injectImpl(target, field, value.getBytes());
    }
    if (field.getType().equals(char[].class)) {
        return injectImpl(target, field, value.toCharArray());
    }
    return false;
}