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:$.Reflections.java

/**
     * ??, Class?.//  w ww  . j a  v  a2s . c  om
     * , 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:gr.abiss.calipso.jpasearch.specifications.GenericSpecifications.java

/**
 * Dynamically create a specification for the given class and search
 * parameters.//from  w  ww .  j ava  2  s.c  o m
 * 
 * @param searchTerm
 * @return
 */
public static Specification matchAll(final Class clazz, final Map<String, String[]> searchTerms) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("matchAll, entity: " + clazz.getSimpleName() + ", searchTerms: " + searchTerms);
    }
    return new Specification<Persistable>() {
        @Override
        public Predicate toPredicate(Root<Persistable> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            return GenericSpecifications.getRootPredicate(clazz, searchTerms, root, cb, false);
        }

    };
}

From source file:com.brienwheeler.svc.monitor.telemetry.impl.TelemetryServiceBaseTestUtils.java

@SuppressWarnings("unchecked")
public static <T> T findProcessor(TelemetryServiceBase telemetryServiceBase, Class<T> clazz) {
    List<ITelemetryInfoProcessor> processors = (List<ITelemetryInfoProcessor>) ReflectionTestUtils
            .getField(telemetryServiceBase, "processors");
    if (processors != null) {
        for (ITelemetryInfoProcessor proc : processors)
            if (clazz.isAssignableFrom(proc.getClass()))
                return clazz.cast(proc);
    }//from   ww  w .  ja  v a 2  s  .  c  om

    throw new IllegalStateException("no " + clazz.getSimpleName() + " found in test context!");
}

From source file:net.kaczmarzyk.spring.data.jpa.web.EnhancerUtil.java

@SuppressWarnings("unchecked")
static <T> T wrapWithIfaceImplementation(final Class<T> iface, final Specification<Object> targetSpec) {
    Enhancer enhancer = new Enhancer();
    enhancer.setInterfaces(new Class[] { iface });
    enhancer.setCallback(new MethodInterceptor() {
        @Override//from w  w  w .jav  a2  s. c o  m
        public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
            if ("toString".equals(method.getName())) {
                return iface.getSimpleName() + "[" + proxy.invoke(targetSpec, args) + "]";
            }
            return proxy.invoke(targetSpec, args);
        }
    });

    return (T) enhancer.create();
}

From source file:com.github.sevntu.checkstyle.internal.ChecksTest.java

private static void validateEclipseCsMetaPropFile(File file, String pkg, Set<Class<?>> pkgModules)
        throws Exception {
    Assert.assertTrue("'checkstyle-metadata.properties' must exist in eclipsecs in inside " + pkg,
            file.exists());// w w  w .  ja v  a  2s  . c  om

    final Properties prop = new Properties();
    prop.load(new FileInputStream(file));

    final Set<Object> properties = new HashSet<>(Collections.list(prop.keys()));

    for (Class<?> module : pkgModules) {
        final String moduleName = module.getSimpleName();

        Assert.assertTrue(moduleName + " requires a name in eclipsecs properties " + pkg,
                properties.remove(moduleName + ".name"));
        Assert.assertTrue(moduleName + " requires a desc in eclipsecs properties " + pkg,
                properties.remove(moduleName + ".desc"));

        final Set<String> moduleProperties = getFinalProperties(module);

        for (String moduleProperty : moduleProperties) {
            Assert.assertTrue(
                    moduleName + " requires the property " + moduleProperty + " in eclipsecs properties " + pkg,
                    properties.remove(moduleName + "." + moduleProperty));
        }
    }

    for (Object property : properties) {
        Assert.fail("Unknown property found in eclipsecs properties " + pkg + ": " + property);
    }
}

From source file:Main.java

/**
 * Format a collection, array, or map (internal method).
 *
 * @param theLabel//from   w ww .j a v a  2  s . co  m
 * @param coll
 * @param maxNumberReported
 * @param theClassName
 * @return The formatted collection, spans multiple lines.
 */
private static String format(String theLabel, Collection<?> coll, int maxNumberReported, String theClassName) {
    final boolean showCollectionIndexes = false;
    final int half = (maxNumberReported == 0) ? 10000 : ((maxNumberReported - 1) / 2) + 1;

    String label = theLabel;
    if (label == null) {
        label = "";
    }

    final Map<Class<?>, Integer> instancesByClass = new HashMap<Class<?>, Integer>();
    final StringBuilder sb = new StringBuilder(label);

    if (label.length() > 0) {
        sb.append(' ');
    }

    final int size = (coll != null) ? coll.size() : 0;

    if (size > 0) {
        sb.append('\n');
    }

    int counter = 0;
    boolean shownEllipsis = false;

    if (coll == null) {
        sb.append("null Collection or Map");
        return sb.toString();
    }

    for (final Object element : coll) {
        // Statistics
        final Class<?> theElementClass = (element != null) ? element.getClass() : null;
        Integer nbrOfThisClass = instancesByClass.get(theElementClass);

        if (nbrOfThisClass == null) {
            nbrOfThisClass = 0;
        }
        nbrOfThisClass = nbrOfThisClass.intValue() + 1;
        instancesByClass.put(theElementClass, nbrOfThisClass);

        // Report
        if (counter < half || counter >= size - half) {
            if (element instanceof Entry<?, ?>) {
                final Entry<?, ?> entry = (Entry<?, ?>) element;
                if (entry.getValue() instanceof Collection<?>) {
                    final int colLSize = ((Collection<?>) entry.getValue()).size();
                    sb.append(" ").append(entry.getKey()).append('[').append(colLSize).append("]=")
                            .append(entry.getValue()).append('\n');
                } else {
                    sb.append(" ").append(entry.getKey()).append('=').append(entry.getValue()).append('\n');
                }
            } else {
                sb.append(' ');
                if (showCollectionIndexes) {
                    sb.append('[');
                    sb.append(counter);
                    sb.append("]=");
                }
                sb.append(String.valueOf(element));
                sb.append('\n');
            }
        } else {
            if (!shownEllipsis) {
                sb.append(" [").append(half).append('-').append(size - half - 1).append("]=(")
                        .append(size - half - half).append(" skipped)\n");
            }
            shownEllipsis = true;
        }
        counter++;
    }

    // Special case for Arrays$ArrayList
    String className = theClassName;
    if ("Arrays$ArrayList".equals(className)) {
        className = "Object[]";
    }
    sb.append(className);
    sb.append(" size=");
    sb.append(size);

    if (!className.endsWith("Map")) {
        // Report number of classes
        for (final Entry<Class<?>, Integer> entry : instancesByClass.entrySet()) {
            final Class<?> key = entry.getKey();
            final Integer value = entry.getValue();
            sb.append(", ");
            sb.append(value);
            sb.append(' ');
            sb.append(key.getSimpleName());
        }
    }
    sb.append('.');
    return sb.toString();
}

From source file:com.impetus.core.DefaultKunderaEntity.java

/**
 * Sets the schema and pu./*w  ww. ja  va  2 s. com*/
 *
 * @param clazz
 *            the clazz
 * @param metadata
 *            the metadata
 */
private static void setSchemaAndPU(Class<?> clazz, EntityMetadata metadata) {
    Table table = clazz.getAnnotation(Table.class);
    if (table != null) {
        metadata.setTableName(!StringUtils.isBlank(table.name()) ? table.name() : clazz.getSimpleName());
        String schemaStr = table.schema();

        MetadataUtils.setSchemaAndPersistenceUnit(metadata, schemaStr,
                em.getEntityManagerFactory().getProperties());
    } else {
        metadata.setTableName(clazz.getSimpleName());
        metadata.setSchema((String) em.getEntityManagerFactory().getProperties().get("kundera.keyspace"));
    }

    if (metadata.getPersistenceUnit() == null) {
        metadata.setPersistenceUnit(getPersistenceUnit());
    }
}

From source file:net.cloudkit.enterprises.infrastructure.utilities.ReflectionHelper.java

/**
 * ??, Class?./*from   w w  w  . j  ava2 s.c  om*/
 * , 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:org.grails.datastore.gorm.finders.DynamicFinder.java

/**
 * Registers a new method expression. The Class must extends from the class {@link MethodExpression} and provide
 * a constructor that accepts a Class parameter and a String parameter.
 *
 * @param methodExpression A class that extends from {@link MethodExpression}
 *///w w  w  .j a  va 2  s .c  o  m
public static void registerNewMethodExpression(Class methodExpression) {
    try {
        methodExpressions.put(methodExpression.getSimpleName(),
                methodExpression.getConstructor(Class.class, String.class));
        resetMethodExpressionPattern();
    } catch (SecurityException e) {
        throw new IllegalArgumentException("Class [" + methodExpression
                + "] does not provide a constructor that takes parameters of type Class and String: "
                + e.getMessage(), e);
    } catch (NoSuchMethodException e) {
        throw new IllegalArgumentException("Class [" + methodExpression
                + "] does not provide a constructor that takes parameters of type Class and String: "
                + e.getMessage(), e);
    }
}

From source file:com.kangyonggan.api.common.util.Reflections.java

/**
 * ??, Class?./*from w  w w  .ja  va2  s  .c  o m*/
 * , Object.class.
 * <p>
 * public UserDao extend 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)) {
        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] instanceof Class)) {
        log.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}