Example usage for java.lang Class isPrimitive

List of usage examples for java.lang Class isPrimitive

Introduction

In this page you can find the example usage for java.lang Class isPrimitive.

Prototype

@HotSpotIntrinsicCandidate
public native boolean isPrimitive();

Source Link

Document

Determines if the specified Class object represents a primitive type.

Usage

From source file:net.paoding.rose.jade.statement.UpdateQuerier.java

public UpdateQuerier(DataAccessFactory dataAccessProvider, StatementMetaData metaData) {
    this.dataAccessProvider = dataAccessProvider;
    Method method = metaData.getMethod();
    // ?// www  .jav a  2  s .c om
    Class<?> returnType = method.getReturnType();
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }
    this.returnType = returnType;
    if (returnType != void.class && (method.isAnnotationPresent(ReturnGeneratedKeys.class))) {
        returnGeneratedKeys = true;
    } else {
        returnGeneratedKeys = false;
    }
}

From source file:com.codenvy.cli.preferences.file.JsonPreferences.java

private boolean shouldMapUnmap(Class<?> clazz) {
    return !(simpleTypes.contains(clazz) || clazz.isPrimitive() || clazz.isArray()
            || Enum.class.isAssignableFrom(clazz) || Collection.class.isAssignableFrom(clazz));
}

From source file:eu.squadd.reflections.mapper.ServiceModelTranslator.java

private static boolean assignPropertyValue(PropertyDescriptor sourceProp, Object sourceValue,
        PropertyDescriptor destProp, Object destInstance) {
    if (sourceValue == null) {
        System.out.println("Null value found, assignment skipped");
        return true;
    }//w w  w .  j av a 2 s . co  m
    boolean result = false;
    Class<?> sourceType = sourceProp.getPropertyType();
    Method getter = sourceProp.getReadMethod();
    Class<?> destType = destProp.getPropertyType();
    Method setter = destProp.getWriteMethod();
    try {
        if (destType.isInterface() || destType.isArray() || destType.isEnum()) {
            if (Collection.class.isAssignableFrom(sourceType) && Collection.class.isAssignableFrom(destType))
                assignCollectionValue(getter, sourceValue, destType, setter, destInstance);
            else if (Map.class.isAssignableFrom(sourceType) && Map.class.isAssignableFrom(destType))
                assignMapValue(getter, sourceValue, setter, destInstance);
            else
                assignMixedTypesValue(sourceType, getter, sourceValue, destType, setter, destInstance);
        } else if (destType.isInstance(sourceValue) || destType.isPrimitive())
            setter.invoke(destInstance, sourceValue);

        else if (destType.isMemberClass())
            setter.invoke(destInstance, sourceValue);

        else if (destType.isAssignableFrom(sourceType))
            setter.invoke(destInstance, destType.cast(sourceValue));

        else { //if (ClassUtils.isInnerClass(destType)) {
            Object member = transposeModel(sourceType, destType, sourceValue);
            member = destType.cast(member);
            setter.invoke(destInstance, member);
        }
        result = true;
    } catch (IllegalArgumentException ex) {
        System.out.println("Looks like type mismatch, source type: " + sourceType + ", dest type: " + destType);
        Logger.getLogger(ServiceModelTranslator.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvocationTargetException | IllegalAccessException ex) {
        Logger.getLogger(ServiceModelTranslator.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result;
}

From source file:com.wavemaker.tools.apidocs.tools.parser.impl.PropertyParserImpl.java

private Property feedPrimitiveProperty(Class<?> type) {
    Class<?> wrapperType = (type.isPrimitive()) ? ClassUtils.primitiveToWrapper(type) : type;
    Property property;//w w w  .j  av  a  2 s.  com
    if (Boolean.class.equals(wrapperType)) {
        property = new BooleanProperty();
    } else if (Character.class.equals(wrapperType)) {
        property = new StringProperty();
        ((StringProperty) property).setMaxLength(1);
    } else if (Byte.class.equals(wrapperType)) {
        property = new StringProperty(StringProperty.Format.BYTE);
    } else if (Number.class.isAssignableFrom(wrapperType)) {
        if (Long.class.equals(wrapperType) || BigInteger.class.equals(wrapperType)) {
            property = new LongProperty();
        } else if (Double.class.equals(wrapperType) || BigDecimal.class.equals(wrapperType)) {
            property = new DoubleProperty();
        } else if (Float.class.equals(wrapperType)) {
            property = new FloatProperty();
        } else {
            property = new IntegerProperty(); // cases like Integer, Short and any remaining
        }

    } else {
        property = new ObjectProperty(); // cases like Void.class
    }
    return property;
}

From source file:de.micromata.genome.util.bean.SoftCastPropertyUtilsBean.java

public Class<?> getWrappedClass(Class<?> target) {
    if (target.isPrimitive() == false) {
        return target;
    }//from   w w  w .ja va2  s.com
    if (target == Integer.TYPE) {
        return Integer.class;
    }
    if (target == Long.TYPE) {
        return Long.class;
    }
    if (target == Byte.TYPE) {
        return Byte.class;
    }
    if (target == Short.TYPE) {
        return Short.class;
    }
    if (target == Float.TYPE) {
        return Short.class;
    }
    if (target == Double.TYPE) {
        return Double.class;
    }
    if (target == Character.TYPE) {
        return Character.class;
    }
    if (target == Boolean.TYPE) {
        return Boolean.class;
    }
    throw new RuntimeException("Unmapped basic type: " + target);
}

From source file:com.manydesigns.elements.fields.BooleanField.java

public BooleanField(PropertyAccessor accessor, Mode mode, String prefix) {
    super(accessor, mode, prefix);
    Class type = accessor.getType();
    if (type.isPrimitive()) {
        setRequired(true);//from  ww w.  ja va 2 s .co m
    }
    checkInputName = CHECK_PREFIX + inputName;
}

From source file:com.sinosoft.one.data.jade.statement.UpdateQuerier.java

public UpdateQuerier(EntityManager em, StatementMetaData metaData) {
    this.em = em;
    Method method = metaData.getMethod();
    // ?/*from   w  ww .  j  ava  2  s  .com*/
    Class<?> returnType = method.getReturnType();
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }
    this.returnType = returnType;
    if (returnType == Identity.class
            || (returnType != void.class && (method.isAnnotationPresent(ReturnGeneratedKeys.class)))) {
        returnGeneratedKeys = true;
    } else {
        returnGeneratedKeys = false;
    }
}

From source file:com.github.gekoh.yagen.util.FieldInfo.java

private static List<FieldInfo> convertFields(List<FieldInfo> fields, Class baseEntity) {

    for (Field field : baseEntity.getDeclaredFields()) {
        FieldInfo fi;// w ww . j a  v  a  2 s . co  m
        Class type = field.getType();
        String name = field.getName();
        Column column = field.getAnnotation(Column.class);
        if (field.isAnnotationPresent(Embedded.class)) {
            if (field.isAnnotationPresent(AttributeOverride.class)) {
                fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverride.class));
            } else {
                fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverrides.class));
            }
        } else if (field.isAnnotationPresent(Enumerated.class)) {
            fi = new FieldInfo(type, name, true, column);
        } else if (column != null && !field.isAnnotationPresent(CollectionTable.class)) {
            if (type.isPrimitive()) {
                if (type.equals(Boolean.TYPE)) {
                    type = Boolean.class;
                } else if (type.equals(Long.TYPE)) {
                    type = Long.class;
                } else if (type.equals(Integer.TYPE)) {
                    type = Integer.class;
                } else if (type.equals(Short.TYPE)) {
                    type = Short.class;
                } else if (type.equals(Byte.TYPE)) {
                    type = Byte.class;
                } else if (type.equals(Double.TYPE)) {
                    type = Double.class;
                } else if (type.equals(Float.TYPE)) {
                    type = Float.class;
                } else if (type.equals(Character.TYPE)) {
                    type = Character.class;
                }
            }
            fi = new FieldInfo(type, name, false, column);
        } else if ((field.isAnnotationPresent(ManyToOne.class) && !field.isAnnotationPresent(JoinTable.class))
                || (field.isAnnotationPresent(OneToOne.class)
                        && StringUtils.isEmpty(field.getAnnotation(OneToOne.class).mappedBy()))) {
            String columnName = field.isAnnotationPresent(JoinColumn.class)
                    ? field.getAnnotation(JoinColumn.class).name()
                    : field.getName();
            fi = getIdFieldInfo(type, name, columnName);
        } else if (!field.isAnnotationPresent(Transient.class)
                && (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type))
                && (field.isAnnotationPresent(JoinColumn.class) || field.isAnnotationPresent(JoinTable.class)
                        || field.isAnnotationPresent(CollectionTable.class))) {
            fi = new FieldInfo(type, name);
        } else {
            continue;
        }
        if (field.isAnnotationPresent(Type.class)) {
            fi.addAnnotation(field.getAnnotation(Type.class));
        }
        fi.setField(field);
        fields.add(fi);
    }

    return fields;
}

From source file:javadz.beanutils.MethodUtils.java

/**
 * Find a non primitive representation for given primitive class.
 *
 * @param clazz the class to find a representation for, not null
 * @return the original class if it not a primitive. Otherwise the wrapper class. Not null
 *///  ww w . ja v  a2 s.  com
public static Class toNonPrimitiveClass(Class clazz) {
    if (clazz.isPrimitive()) {
        Class primitiveClazz = MethodUtils.getPrimitiveWrapper(clazz);
        // the above method returns 
        if (primitiveClazz != null) {
            return primitiveClazz;
        } else {
            return clazz;
        }
    } else {
        return clazz;
    }
}

From source file:com.quatico.base.aem.test.api.builders.AbstractBuilder.java

private Class<?> wrapPrimitive(Class<?> type) {
    return type.isPrimitive() ? PRIMITIVE_TYPE_WRAPPERS.get(type) : type;
}