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:edu.umn.msi.tropix.common.reflect.ReflectionHelperImpl.java

public static Class<?> box(final Class<?> arg) {
    return arg.isPrimitive() ? PRIMITIVE_TYPES.get(arg) : arg;
}

From source file:Main.java

public static <T> boolean contains(T[] array, T value) {
    final Class<?> componetType = array.getClass().getComponentType();
    boolean isPrimitive = false;
    if (null != componetType) {
        isPrimitive = componetType.isPrimitive();
    }/*from   w  ww.ja  va2  s  .c om*/
    for (T t : array) {
        if (t == value) {
            return true;
        } else if (false == isPrimitive && null != value && value.equals(t)) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static <T> boolean contains(T[] array, T value) {
    final Class<?> componetType = array.getClass().getComponentType();
    boolean isPrimitive = false;
    if (null != componetType) {
        isPrimitive = componetType.isPrimitive();
    }/*from w  ww .j  av a  2s.  c  o  m*/
    for (T t : array) {
        if (t == value) {
            return true;
        } else if (!isPrimitive && null != value && value.equals(t)) {
            return true;
        }
    }
    return false;
}

From source file:com.github.jknack.handlebars.helper.MethodHelper.java

/**
 * Wrap (if possible) a primitive type to their wrapper.
 *
 * @param type The candidate type./*from   w  w w  .j av  a2  s . c o  m*/
 * @return A wrapper for the primitive type or the original type.
 */
private static Class<?> wrap(final Class<?> type) {
    if (type.isPrimitive()) {
        if (type == Integer.TYPE) {
            return Integer.class;
        } else if (type == Boolean.TYPE) {
            return Boolean.class;
        } else if (type == Character.TYPE) {
            return Character.class;
        } else if (type == Double.TYPE) {
            return Double.class;
        } else if (type == Long.TYPE) {
            return Long.class;
        } else if (type == Float.TYPE) {
            return Float.class;
        } else if (type == Short.TYPE) {
            return Short.class;
        } else if (type == Byte.TYPE) {
            return Byte.class;
        }
    }
    return type;
}

From source file:game.utils.Utils.java

public static boolean isConcrete(Class type) {
    return type.isPrimitive()
            || (!Modifier.isAbstract(type.getModifiers()) && !Modifier.isInterface(type.getModifiers()));
}

From source file:Main.java

static boolean canAssign(Class<?> baseClass, Class<?> classToCheck) {
    if (baseClass.isAssignableFrom(classToCheck)) {
        return true;
    } else {/*from  ww  w . j a  va  2s.  c o m*/
        if (baseClass.isPrimitive()) {
            Class primitiveClass = PRIMITIVE_WRAPPERS.get(classToCheck);
            if (primitiveClass != null) {
                return baseClass.isAssignableFrom(primitiveClass);
            }
        } else if (classToCheck.isPrimitive()) {
            Class primitiveClass = PRIMITIVE_WRAPPERS.get(baseClass);
            if (primitiveClass != null) {
                return primitiveClass.isAssignableFrom(classToCheck);
            }
        }
    }

    return false;
}

From source file:com.github.erchu.beancp.MapperExecutorSelector.java

private static boolean classEqualsOrWrapper(final Class objectClass, final Class supportedClass) {
    if (objectClass.isPrimitive()) {
        Class<?> primitiveTypeWrapper = ClassUtils.primitiveToWrapper(objectClass);

        return objectClass.equals(supportedClass) || primitiveTypeWrapper.equals(supportedClass);
    } else if (supportedClass.isPrimitive()) {
        Class<?> primitiveTypeWrapper = ClassUtils.primitiveToWrapper(supportedClass);

        return objectClass.equals(supportedClass) || objectClass.equals(primitiveTypeWrapper);
    } else {/*from   w  w w .  j av a 2  s . c om*/
        return supportedClass.equals(objectClass);
    }
}

From source file:hu.bme.mit.sette.tools.spf.SpfGenerator.java

static String getParameterLiteral(Class<?> javaClass) {
    if (javaClass.isPrimitive()) {
        javaClass = ClassUtils.primitiveToWrapper(javaClass);
    }/*w  w w . ja v a  2  s  .c  o m*/

    if (javaClass.equals(Byte.class)) {
        return "(byte) 1";
    } else if (javaClass.equals(Short.class)) {
        return "(short) 1";
    } else if (javaClass.equals(Integer.class)) {
        return "1";
    } else if (javaClass.equals(Long.class)) {
        return "1L";
    } else if (javaClass.equals(Float.class)) {
        return "1.0f";
    } else if (javaClass.equals(Double.class)) {
        return "1.0";
    } else if (javaClass.equals(Boolean.class)) {
        return "false";
    } else if (javaClass.equals(Character.class)) {
        return "' '";
    } else {
        return "null";
    }
}

From source file:Main.java

/**
 * @param type the type can be converted to simple String
 * @return true of the type is simple/*ww w .  jav  a 2 s.c  o  m*/
 */
public static boolean isSimpleType(Type type) {
    boolean simpleType = false;

    if (type instanceof Class) {
        Class<?> typeClass = (Class<?>) type;

        simpleType = SIMPLECLASSES.contains(typeClass) || Number.class.isAssignableFrom(typeClass)
                || typeClass.isPrimitive() || typeClass.isEnum();
    }

    return simpleType;
}

From source file:Main.java

public static String getType(Class<?> paramClass) {
    if (paramClass.isArray()) {
        return "[" + getDesc(paramClass.getComponentType());
    }/*from w  ww.  j a v a 2s . co m*/
    if (!paramClass.isPrimitive()) {
        return paramClass.getName().replaceAll("\\.", "/");
    }
    return getPrimitiveLetter(paramClass);
}