Example usage for java.lang Class getName

List of usage examples for java.lang Class getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String .

Usage

From source file:HasBatteries.java

static void printInfo(Class cc) {
    System.out.println("Class name: " + cc.getName() + " is interface? [" + cc.isInterface() + "]");
}

From source file:net.jodah.sarge.internal.util.Types.java

public static boolean isProxy(Class<?> type) {
    return type.getName().contains("$$EnhancerBy");
}

From source file:Main.java

private static ExecutorService getExecutorService(Class clazz) {
    String key = clazz.getName();
    if (!map.containsKey(key)) {
        synchronized (map) {
            if (!map.containsKey(key)) {
                map.put(key, Executors.newFixedThreadPool(TOTAL_SIZE));
            }//from ww w  . ja v  a 2s. com
        }
    }
    return map.get(key);
}

From source file:SampleField.java

static void printFieldNames(Object o) {
    Class c = o.getClass();//from  ww w. jav a  2  s . c  om
    Field[] publicFields = c.getFields();
    for (int i = 0; i < publicFields.length; i++) {
        String fieldName = publicFields[i].getName();
        Class typeClass = publicFields[i].getType();
        String fieldType = typeClass.getName();
        System.out.println("Name: " + fieldName + ", Type: " + fieldType);
    }
}

From source file:Main.java

public static <T> Set<Class<? extends T>> filter(Collection<Class<? extends T>> source, String packageFilter) {
    Set<Class<? extends T>> filtered = new HashSet<Class<? extends T>>();
    for (Class<? extends T> klazz : source) {
        if (klazz.getName().startsWith(packageFilter))
            filtered.add(klazz);/*from  w ww.j  av a 2s  .c o  m*/
    }
    return filtered;
}

From source file:MainClass.java

public static void premain(final Instrumentation inst) {
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            try {
                PrintWriter out = new PrintWriter(System.err);

                ThreadMXBean tb = ManagementFactory.getThreadMXBean();
                out.printf("Current thread count: %d%n", tb.getThreadCount());
                out.printf("Peak thread count: %d%n", tb.getPeakThreadCount());

                List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
                for (MemoryPoolMXBean pool : pools) {
                    MemoryUsage peak = pool.getPeakUsage();
                    out.printf("Peak %s memory used: %,d%n", pool.getName(), peak.getUsed());
                    out.printf("Peak %s memory reserved: %,d%n", pool.getName(), peak.getCommitted());
                }/*from w w  w .  jav a  2s.c  o m*/

                Class[] loaded = inst.getAllLoadedClasses();
                out.println("Loaded classes:");
                for (Class c : loaded)
                    out.println(c.getName());
                out.close();
            } catch (Throwable t) {
                System.err.println("Exception in agent: " + t);
            }
        }
    });
}

From source file:Main.java

public static String getClassFileName(Class clazz) {
    String className = clazz.getName();
    int lastDotIndex = className.lastIndexOf(PACKAGE_SEPARATOR);
    return className.substring(lastDotIndex + 1) + CLASS_FILE_SUFFIX;
}

From source file:Main.java

public static String getClassSimpleName(final Class<?> clz) {
    final String name = clz.getName();
    final int endCutOff = name.length();
    int beginCutOff = name.lastIndexOf(".") + 1;

    if (beginCutOff == -1)
        beginCutOff = 1;//from   www  .ja va 2 s.co m

    return name.substring(beginCutOff, endCutOff);
}

From source file:Main.java

public static void LOG_E(Class<?> paramClass, String paramString) {
    String str = paramClass.getName();
    Log.e(LOG_TAG, str + " -> " + paramString);
}

From source file:Main.java

private static boolean isCompatible(Class<?> type0, Class<?> type1) {
    if (type0.getName().equals(type1.getName())) {
        return true;
    }/*from   ww  w  .  j a  v a2 s  . com*/
    if (type0.isPrimitive()) {
        return isCompatible(PRIMITIVE_TO_WRAPPER.get(type0), type1);
    }
    if (type1.isPrimitive()) {
        return isCompatible(type0, PRIMITIVE_TO_WRAPPER.get(type1));
    }
    return type0.isAssignableFrom(type1);
}