Example usage for java.lang Class getSimpleName

List of usage examples for java.lang Class getSimpleName

Introduction

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

Prototype

public String getSimpleName() 

Source Link

Document

Returns the simple name of the underlying class as given in the source code.

Usage

From source file:com.github.cherimojava.data.mongo.entity.EntityUtils.java

/**
 * retrieves the name for the Entity, which might be different from the clazz name if the @Named annotation is
 * present/*www.  j  a v  a2  s . c  om*/
 *
 * @param clazz Entity from which to retrieve the collection name
 * @return the name of the Entity as declared with the Named annotation or the clazz name if annotation isn't
 *         present as plural
 */
public static String getCollectionName(Class<? extends Entity> clazz) {
    Named name = clazz.getAnnotation(Named.class);
    if (name != null && isNotEmpty(name.value())) {
        return name.value();
    }
    return uncapitalize(clazz.getSimpleName() + "s");
}

From source file:com.lakeside.core.utils.ReflectionUtils.java

/**
 * ??, Class?./* ww w  .  j av  a 2  s.  co  m*/
 * , Object.class.
 * 
 * public UserDao extends HibernateDao<User,Long>
 *
 * @param clazz clazz The class to introspect
 * @param index the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or Object.class if cannot be determined
 */
@SuppressWarnings("unchecked")
public static Class getSuperClassGenricType(final Class clazz, final int index) {

    Type genType = clazz.getGenericSuperclass();

    if (!(genType instanceof ParameterizedType)) {
        logger.debug(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }

    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if (index >= params.length || index < 0) {
        logger.debug("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index] instanceof Class)) {
        logger.debug(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}

From source file:io.github.sparta.helpers.reflex.Reflections.java

/**
 * ??, Class?./*w  w  w . j  a va  2  s  . c o  m*/
 * , Object.class.
 * <p/>
 * public UserDao extends HibernateDao<User,Long>
 *
 * @param clazz clazz The class to introspect
 * @param index the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or Object.class if cannot be determined
 */
@SuppressWarnings("rawtypes")
public static Class getSuperClassGenricType(final Class clazz, final int index) {

    Type genType = clazz.getGenericSuperclass();

    if (!(genType.getClass().isAssignableFrom(ParameterizedType.class))) {
        log.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }

    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if (index >= params.length || index < 0) {
        log.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index].getClass().isAssignableFrom(Class.class))) {
        log.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}

From source file:ReflectionUtils.java

/**
 * ,Class./*  w w w .ja  v  a 2  s .c om*/
 * 
 * public UserDao extends HibernateDao<User,Long>
 * 
 * @param clazz
 *            clazz The class to introspect
 * @param index
 *            the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or Object.class if cannot be
 *         determined
 */

@SuppressWarnings("unchecked")
public static Class getSuperClassGenricType(final Class clazz, final int index) {

    Type genType = clazz.getGenericSuperclass();

    if (!(genType instanceof ParameterizedType)) {
        logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }

    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if (index >= params.length || index < 0) {
        logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index] instanceof Class)) {
        logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}

From source file:com.turbospaces.core.SpaceUtility.java

/**
 * raise new {@link DuplicateKeyException} exception for given uniqueIdentifier and persistent class.
 * //from   ww w .ja v a  2 s  .  co m
 * @param uniqueIdentifier
 *            primary key
 * @param persistentClass
 *            space class
 * @see SpaceErrors#DUPLICATE_KEY_VIOLATION
 */
public static void raiseDuplicateException(final Object uniqueIdentifier, final Class<?> persistentClass) {
    throw new DuplicateKeyException(String.format(SpaceErrors.DUPLICATE_KEY_VIOLATION,
            persistentClass.getSimpleName(), uniqueIdentifier.toString()));
}

From source file:com.izforge.izpack.panels.licence.LicenceLoader.java

/**
 * Finds the IzPanel target class for the given {@code panelClass}.
 *
 * @param panelClass The panel class./*from w w w . j  a  v a 2  s .  co  m*/
 * @return The related IzPanel class.
 * @throws ResourceException If a related IzPanel class could not be found.
 *
 * @see PanelHelper#getIzPanel(String)
 */
static Class<?> findTargetClass(Class<?> panelClass) throws ResourceException {
    Class<?> targetClass = PanelHelper.getIzPanel(panelClass.getName());

    if (null == targetClass) {
        throw new ResourceNotFoundException(
                "No IzPanel implementation found for " + panelClass.getSimpleName());
    }

    return targetClass;
}

From source file:net.librec.util.DriverClassUtil.java

/**
 * get Driver Name by clazz/*  w  w  w  . j ava2 s.co m*/
 *
 * @param clazz clazz name
 * @return driver name
 * @throws ClassNotFoundException if can't find the Class
 */
public static String getDriverName(Class<? extends Recommender> clazz) throws ClassNotFoundException {
    if (clazz == null) {
        return null;
    } else {
        String driverName = driverClassInverseBiMap.get(clazz.getName());
        if (StringUtils.isNotBlank(driverName)) {
            return driverName;
        } else {
            return clazz.getSimpleName().toLowerCase().replace("recommender", "");
        }
    }
}

From source file:com.hemou.android.util.StrUtils.java

public static <K> K str2Obj(String str, Class<K> cls) {
    try {/*w  w w  .  j a va  2  s  . c o m*/
        return new ObjectMapper().readValue(str, cls);
    } catch (Exception e) {
        Log.w("Str2Obj", "Can not convert " + str + " to class ?" + cls.getSimpleName() + "");
        e.printStackTrace();
    }
    return null;
}

From source file:com.agileEAP.ireport.utils.Reflections.java

/**
 * ??, Class?./*  w ww  .  j av  a 2  s .c o  m*/
 * , Object.class.
 * 
 * public UserDao extends HibernateDao<User,Long>
 *
 * @param clazz clazz The class to introspect
 * @param index the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or Object.class if cannot be determined
 */
public static Class getClassGenricType(final Class clazz, final int index) {

    Type genType = clazz.getGenericSuperclass();

    if (!(genType instanceof ParameterizedType)) {
        logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }

    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if (index >= params.length || index < 0) {
        logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index] instanceof Class)) {
        logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}

From source file:com.yc.modules.utils.Reflections.java

/**
 * ??, Class?.//from w w w  .  jav a 2s. c o m
 * , Object.class.
 * 
 * public UserDao extends HibernateDao<User,Long>
 * 
 * @param clazz clazz The class to introspect
 * @param index the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or Object.class if cannot be determined
 */
public static Class getClassGenricType(final Class clazz, final int index) {

    Type genType = clazz.getGenericSuperclass();

    if (!(genType instanceof ParameterizedType)) {
        logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }

    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if ((index >= params.length) || (index < 0)) {
        logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index] instanceof Class)) {
        logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}