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.plusub.lib.annotate.JsonParserUtils.java

/**
 * ?//  w  w  w  .j  a v a2s.  co  m
 * <p>Title: isWrapClass
 * <p>Description: 
 * @param clazz
 * @return
 */
private static boolean isBaseDataType(Class clazz) {
    return (clazz.isPrimitive() || clazz.equals(String.class) || clazz.equals(Integer.class)
            || clazz.equals(Boolean.class) || clazz.equals(Long.class) || clazz.equals(Double.class)
            || clazz.equals(Float.class) || clazz.equals(Short.class) || clazz.equals(Character.class)
            || clazz.equals(Date.class)) || clazz.equals(Byte.class) || clazz.equals(Void.class)
            || clazz.equals(BigDecimal.class) || clazz.equals(BigInteger.class);
}

From source file:com.bah.culvert.accumulo.database.AccumuloDatabaseAdapter.java

private static Instance getInstance(Configuration conf) throws ClassNotFoundException {
    String instClass = conf.get(AccumuloConstants.INSTANCE_CLASS_KEY);
    Class<? extends Instance> clazz;

    // make sure that we have a valid instance
    if (instClass == null) {
        LOG.debug("No instance type specified for connecting to Accumulo, using default");
        clazz = AccumuloConstants.DEFAULT_INSTANCE_CLASS;
    } else//from  w w w . j av  a  2 s. c  o m
        clazz = Class.forName(instClass).asSubclass(Instance.class);

    // create the valid instance
    if (clazz.equals(ZooKeeperInstance.class))
        return new ZooKeeperInstance(conf.get(AccumuloConstants.INSTANCE_NAME_KEY),
                conf.get(AccumuloConstants.ZOOKEEPER_SERVERS_KEY));
    else if (clazz.equals(MockInstance.class))
        return new MockInstance(
                conf.get(AccumuloConstants.INSTANCE_NAME_KEY, AccumuloConstants.DEFAULT_INSTANCE_NAME));
    else
        throw new IllegalArgumentException(instClass + "is not a valid instance class");
}

From source file:antre.TypeResolver.java

/**
 * Resolves the generic Type for the {@code targetType} by walking the type hierarchy upwards from
 * the {@code initialType}.//from  ww  w .j  av a  2 s.  c  o  m
 */
public static Type resolveGenericType(Type initialType, Class<?> targetType) {
    Class<?> rawType;
    if (initialType instanceof ParameterizedType)
        rawType = (Class<?>) ((ParameterizedType) initialType).getRawType();
    else
        rawType = (Class<?>) initialType;

    if (targetType.equals(rawType))
        return initialType;

    Type result;
    if (targetType.isInterface()) {
        for (Type superInterface : rawType.getGenericInterfaces())
            if (superInterface != null && !superInterface.equals(Object.class))
                if ((result = resolveGenericType(superInterface, targetType)) != null)
                    return result;
    }

    Type superType = rawType.getGenericSuperclass();
    if (superType != null && !superType.equals(Object.class))
        if ((result = resolveGenericType(superType, targetType)) != null)
            return result;

    return null;
}

From source file:com.github.valdr.thirdparty.spring.AnnotationUtils.java

/**
 * Find a single {@link java.lang.annotation.Annotation} of {@code annotationType} from the supplied {@link Class},
 * traversing its interfaces and superclasses if no annotation can be found on the given class itself.
 * <p>This method explicitly handles class-level annotations which are not declared as
 * {@link java.lang.annotation.Inherited inherited} <i>as well as annotations on interfaces</i>.
 * <p>The algorithm operates as follows: Searches for an annotation on the given class and returns
 * it if found. Else searches all interfaces that the given class declares, returning the annotation
 * from the first matching candidate, if any. Else proceeds with introspection of the superclass
 * of the given class, checking the superclass itself; if no annotation found there, proceeds
 * with the interfaces that the superclass declares. Recursing up through the entire superclass
 * hierarchy if no match is found.//w  ww.  j av  a  2  s  .co m
 * @param clazz the class to look for annotations on
 * @param annotationType the annotation class to look for
 * @return the annotation found, or {@code null} if none found
 */
public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType) {
    A annotation = clazz.getAnnotation(annotationType);
    if (annotation != null) {
        return annotation;
    }
    for (Class<?> ifc : clazz.getInterfaces()) {
        annotation = findAnnotation(ifc, annotationType);
        if (annotation != null) {
            return annotation;
        }
    }
    if (!Annotation.class.isAssignableFrom(clazz)) {
        for (Annotation ann : clazz.getAnnotations()) {
            annotation = findAnnotation(ann.annotationType(), annotationType);
            if (annotation != null) {
                return annotation;
            }
        }
    }
    Class<?> superClass = clazz.getSuperclass();
    if (superClass == null || superClass.equals(Object.class)) {
        return null;
    }
    return findAnnotation(superClass, annotationType);
}

From source file:cn.afterturn.easypoi.util.PoiPublicUtil.java

/**
 * /*from w ww .  j a  v a 2 s .  c o m*/
 *
 * @param clazz
 * @return
 */
public static Object createObject(Class<?> clazz, String targetId) {
    Object obj = null;
    try {
        if (clazz.equals(Map.class)) {
            return new LinkedHashMap<String, Object>();
        }
        obj = clazz.newInstance();
        Field[] fields = getClassFields(clazz);
        for (Field field : fields) {
            if (isNotUserExcelUserThis(null, field, targetId)) {
                continue;
            }
            if (isCollection(field.getType())) {
                ExcelCollection collection = field.getAnnotation(ExcelCollection.class);
                PoiReflectorUtil.fromCache(clazz).setValue(obj, field.getName(),
                        collection.type().newInstance());
            } else if (!isJavaClass(field) && !field.getType().isEnum()) {
                PoiReflectorUtil.fromCache(clazz).setValue(obj, field.getName(),
                        createObject(field.getType(), targetId));
            }
        }

    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException("");
    }
    return obj;

}

From source file:org.synyx.hades.util.ClassUtils.java

/**
 * Checks whether the given parameter type matches the generic type of the
 * given parameter. Thus when {@literal PK} is declared, the method ensures
 * that given method parameter is the primary key type declared in the given
 * DAO interface e.g./*from   www  .j a v  a 2s .com*/
 * 
 * @param name
 * @param parameterType
 * @param daoInterface
 * @return
 */
private static boolean matchesGenericType(String name, Class<?> parameterType, Class<?> daoInterface) {

    Class<?> entityType = getDomainClass(daoInterface);
    Class<?> idClass = getIdClass(daoInterface);

    if (ID_TYPE_NAME.equals(name) && parameterType.equals(idClass)) {
        return true;
    }

    if (DOMAIN_TYPE_NAME.equals(name) && parameterType.equals(entityType)) {
        return true;
    }

    return false;
}

From source file:org.jdal.dao.jpa.JpaUtils.java

/**
 * Find the Root with type class on CriteriaQuery Root Set
 * @param <T> root type/*from  w  w w.  j  a  va2  s  .  c  om*/
 * @param query criteria query
 * @param clazz root type
 * @return Root<T> of null if none
 */
@SuppressWarnings("unchecked")
public static <T> Root<T> findRoot(CriteriaQuery<?> query, Class<T> clazz) {

    for (Root<?> r : query.getRoots()) {
        if (clazz.equals(r.getJavaType())) {
            return (Root<T>) r.as(clazz);
        }
    }
    return (Root<T>) query.getRoots().iterator().next();
}

From source file:com.phoenixnap.oss.ramlapisync.naming.SchemaHelper.java

/**
 * Maps primitives and other simple Java types into simple types supported by RAML
 * // w  w w  .jav a  2 s.  c om
 * @param clazz The Class to map
 * @return The Simple RAML ParamType which maps to this class or null if one is not found
 */
public static ParamType mapSimpleType(Class<?> clazz) {
    Class<?> targetClazz = clazz;
    if (targetClazz.isArray() && clazz.getComponentType() != null) {
        targetClazz = clazz.getComponentType();
    }
    if (targetClazz.equals(Long.TYPE) || targetClazz.equals(Long.class) || targetClazz.equals(Integer.TYPE)
            || targetClazz.equals(Integer.class) || targetClazz.equals(Short.TYPE)
            || targetClazz.equals(Short.class) || targetClazz.equals(Byte.TYPE)
            || targetClazz.equals(Byte.class)) {
        return ParamType.INTEGER;
    } else if (targetClazz.equals(Float.TYPE) || targetClazz.equals(Float.class)
            || targetClazz.equals(Double.TYPE) || targetClazz.equals(Double.class)
            || targetClazz.equals(BigDecimal.class)) {
        return ParamType.NUMBER;
    } else if (targetClazz.equals(Boolean.class) || targetClazz.equals(Boolean.TYPE)) {
        return ParamType.BOOLEAN;
    } else if (targetClazz.equals(String.class)) {
        return ParamType.STRING;
    }
    return null; // default to string
}

From source file:com.alibaba.otter.node.etl.common.db.utils.SqlUtils.java

/**
 * sqlValueToString?//from  ww w  . ja va  2 s .  co  m
 * 
 * @param value
 * @param sqlType
 * @param isTextRequired
 * @param isEmptyStringNulled
 * @return
 */
public static Object stringToSqlValue(String value, int sqlType, boolean isRequired,
        boolean isEmptyStringNulled) {
    // ??
    String sourceValue = value;
    if (SqlUtils.isTextType(sqlType)) {
        if ((sourceValue == null) || (true == StringUtils.isEmpty(sourceValue) && isEmptyStringNulled)) {
            return isRequired ? REQUIRED_FIELD_NULL_SUBSTITUTE : null;
        } else {
            return sourceValue;
        }
    } else {
        if (StringUtils.isEmpty(sourceValue)) {
            return isEmptyStringNulled ? null : sourceValue;// oraclenull??
        } else {
            Class<?> requiredType = sqlTypeToJavaTypeMap.get(sqlType);
            if (requiredType == null) {
                throw new IllegalArgumentException("unknow java.sql.Types - " + sqlType);
            } else if (requiredType.equals(String.class)) {
                return sourceValue;
            } else if (true == isNumeric(sqlType)) {
                return convertUtilsBean.convert(sourceValue.trim(), requiredType);
            } else {
                return convertUtilsBean.convert(sourceValue, requiredType);
            }
        }
    }
}

From source file:de.cebitec.readXplorer.util.GeneralUtils.java

/**
 * Converts a given number into a number of the given classType. If this is
 * not possible, it throws a ClassCastException
 * @param <T> one of the classes derived from Number
 * @param classType the type to convert the number into
 * @param number the number to convert//from w  ww  .  j a v  a 2  s.co m
 * @return The converted number
 */
public static <T extends Number> T convertNumber(Class<T> classType, Number number) throws ClassCastException {
    T convertedValue = null;
    if (classType.equals(Integer.class)) {
        convertedValue = classType.cast(number.intValue());
    } else if (classType.equals(Double.class)) {
        convertedValue = classType.cast(number.doubleValue());
    } else if (classType.equals(Long.class)) {
        convertedValue = classType.cast(number.longValue());
    } else if (classType.equals(Float.class)) {
        convertedValue = classType.cast(number.floatValue());
    } else if (classType.equals(Short.class)) {
        convertedValue = classType.cast(number.shortValue());
    } else if (classType.equals(Byte.class)) {
        convertedValue = classType.cast(number.byteValue());
    }

    if (convertedValue == null) {
        throw new ClassCastException("Cannot cast the given number into the given format.");
    }

    return convertedValue;
}