Example usage for java.lang Class equals

List of usage examples for java.lang Class equals

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.PagingParametersFinder.java

/**
 * primitive?String//from w  ww .ja va2  s .  c o m
 * <p/>
 * fixed:paramter string type.
 *
 * @param clazz ?
 * @return <code>null</code>?primitive<code>false</code>?<code>true</code>
 */
@SuppressWarnings("rawtypes")
public static boolean isPrimitiveType(Class clazz) {
    return clazz != null && (clazz.isPrimitive() || clazz.equals(Long.class) || clazz.equals(Integer.class)
            || clazz.equals(Short.class) || clazz.equals(Byte.class) || clazz.equals(Double.class)
            || clazz.equals(Float.class) || clazz.equals(Boolean.class) || clazz.equals(Character.class)
            || clazz.equals(String.class));

}

From source file:nz.co.senanque.validationengine.ConvertUtils.java

public static Object getPrimitiveTypeForNull(Class<?> clazz) {
    if (clazz.equals(Long.TYPE)) {
        return 0L;
    } else if (clazz.equals(Integer.TYPE)) {
        return 0;
    } else if (clazz.equals(Float.TYPE)) {
        return 0.0F;
    } else if (clazz.equals(Double.TYPE)) {
        return 0.0D;
    } else if (clazz.equals(Boolean.TYPE)) {
        return false;
    }//from  w  ww  .j av  a  2 s  .  c om
    return null;
}

From source file:nz.co.senanque.validationengine.ConvertUtils.java

public static Object getObjectForNull(Class<?> clazz) {
    if (clazz.equals(Long.TYPE)) {
        return new Long(0);
    } else if (clazz.equals(Integer.TYPE)) {
        return new Integer(0);
    } else if (clazz.equals(Float.TYPE)) {
        return new Float(0.0F);
    } else if (clazz.equals(Double.TYPE)) {
        return new Double(0.0D);
    } else if (clazz.equals(Boolean.TYPE)) {
        return new Boolean(false);
    }/* w w  w .j ava 2s.c  om*/
    return null;
}

From source file:com.adobe.acs.commons.mcp.util.AnnotatedFieldDeserializer.java

@SuppressWarnings("squid:S3776")
private static Object convertPrimitiveValue(String value, Class<?> type) throws ParseException {
    if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
        return value.toLowerCase().trim().equals("true");
    } else {// ww w  . j a  v a 2 s  .c  om
        NumberFormat numberFormat = NumberFormat.getNumberInstance();
        Number num = numberFormat.parse(value);
        if (type.equals(Byte.class) || type.equals(Byte.TYPE)) {
            return num.byteValue();
        } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
            return num.doubleValue();
        } else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
            return num.floatValue();
        } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
            return num.intValue();
        } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
            return num.longValue();
        } else if (type.equals(Short.class) || type.equals(Short.TYPE)) {
            return num.shortValue();
        } else {
            return null;
        }
    }
}

From source file:com.twitter.elephantbird.pig.piggybank.Invoker.java

private static Class<?> unPrimitivize(Class<?> klass) {
    if (klass.equals(Integer.TYPE)) {
        return Integer.class;
    }//from   w  ww.  j  av  a  2  s  . co  m
    if (klass.equals(Long.TYPE)) {
        return Long.class;
    } else if (klass.equals(Float.TYPE)) {
        return Float.class;
    } else if (klass.equals(Double.TYPE)) {
        return Double.class;
    } else if (klass.equals(DOUBLE_ARRAY_CLASS)) {
        return DOUBLE_ARRAY_CLASS;
    } else {
        return klass;
    }
}

From source file:NumberUtils.java

/**
 * Parse the given text into a number instance of the given target class,
 * using the corresponding default <code>decode</code> methods. Trims the
 * input <code>String</code> before attempting to parse the number. Supports
 * numbers in hex format (with leading 0x) and in octal format (with leading 0).
 *
 * @param text        the text to convert
 * @param targetClass the target class to parse into
 * @return the parsed number/* w  ww  .  j a v a 2 s.c  om*/
 * @throws IllegalArgumentException if the target class is not supported
 *                                  (i.e. not a standard Number subclass as included in the JDK)
 * @see java.lang.Byte#decode
 * @see java.lang.Short#decode
 * @see java.lang.Integer#decode
 * @see java.lang.Long#decode
 * @see #decodeBigInteger(String)
 * @see java.lang.Float#valueOf
 * @see java.lang.Double#valueOf
 * @see java.math.BigDecimal#BigDecimal(String)
 */
public static Number parseNumber(String text, Class targetClass) {
    String trimmed = text.trim();

    if (targetClass.equals(Byte.class)) {
        return Byte.decode(trimmed);
    } else if (targetClass.equals(Short.class)) {
        return Short.decode(trimmed);
    } else if (targetClass.equals(Integer.class)) {
        return Integer.decode(trimmed);
    } else if (targetClass.equals(Long.class)) {
        return Long.decode(trimmed);
    } else if (targetClass.equals(BigInteger.class)) {
        return decodeBigInteger(trimmed);
    } else if (targetClass.equals(Float.class)) {
        return Float.valueOf(trimmed);
    } else if (targetClass.equals(Double.class)) {
        return Double.valueOf(trimmed);
    } else if (targetClass.equals(BigDecimal.class) || targetClass.equals(Number.class)) {
        return new BigDecimal(trimmed);
    } else {
        throw new IllegalArgumentException(
                "Cannot convert String [" + text + "] to target class [" + targetClass.getName() + "]");
    }
}

From source file:cz.incad.kramerius.rest.api.k5.client.utils.SOLRUtils.java

public static <T> T value(String val, Class<T> clz) {
    if (val == null)
        return null;
    val = val.trim();
    if (clz.equals(String.class))
        return (T) val;
    else if (clz.equals(Boolean.class))
        return (T) new Boolean(val);
    else if (clz.equals(Integer.class))
        return (T) Integer.valueOf(val);
    else//from   w w  w  .j  a v a2 s  .co  m
        throw new IllegalArgumentException("unsupported type " + clz + "");
}

From source file:com.google.code.siren4j.util.ComponentUtils.java

public static boolean isNumeric(Object obj) {
    Class<?> clazz = obj.getClass();
    boolean numeric = false;
    if (clazz.isPrimitive()) {
        numeric = clazz.equals(byte.class) || clazz.equals(short.class) || clazz.equals(int.class)
                || clazz.equals(long.class) || clazz.equals(float.class) || clazz.equals(double.class);

    } else {/*from  w w w .  j  a v  a 2  s  . c o m*/
        numeric = obj instanceof Number;
    }
    return numeric;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static int indexOfLike(Class[] a, Class key) {
    if (null == a || a.length == 0 || null == key) {
        return -1;
    }/*from   w  ww .j  a  v  a  2s. com*/
    for (int i = 0; i < a.length; i++) {
        final Class item = a[i];
        // is 'item' equal or super-class of 'key'?
        if (key.equals(item) || item.isAssignableFrom(key)) {
            return i;
        }
    }
    return -1;
}

From source file:fr.paris.lutece.util.method.MethodUtil.java

/**
 * Gets the primitive method.//from ww w  .  ja  v  a 2s  . c o m
 *
 * @param <A> the generic type of the instance
 * @param strMethodName the str method name
 * @param instance the instance
 * @param clazz the clazz
 * @return the primitive method
 * @throws SecurityException the security exception
 * @throws NoSuchMethodException the no such method exception
 */
public static <A> Method getPrimitiveMethod(String strMethodName, A instance, Class<?> clazz)
        throws SecurityException, NoSuchMethodException {
    if (clazz.equals(Integer.class)) {
        return instance.getClass().getMethod(strMethodName, new Class[] { int.class });
    } else if (clazz.equals(Long.class)) {
        return instance.getClass().getMethod(strMethodName, new Class[] { long.class });
    } else if (clazz.equals(Double.class)) {
        return instance.getClass().getMethod(strMethodName, new Class[] { double.class });
    } else if (clazz.equals(Short.class)) {
        return instance.getClass().getMethod(strMethodName, new Class[] { short.class });
    } else if (clazz.equals(Byte.class)) {
        return instance.getClass().getMethod(strMethodName, new Class[] { byte.class });
    } else if (clazz.equals(Float.class)) {
        return instance.getClass().getMethod(strMethodName, new Class[] { float.class });
    } else if (clazz.equals(Character.class)) {
        return instance.getClass().getMethod(strMethodName, new Class[] { char.class });
    } else if (clazz.equals(Boolean.class)) {
        return instance.getClass().getMethod(strMethodName, new Class[] { boolean.class });
    }

    throw new NoSuchMethodException();
}