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:com.granule.logging.LoggerFactory.java

public static Logger getLogger(final Class<?> loggedClass) {
    return getLogger(loggedClass.getName());
}

From source file:com.igitras.codegen.common.utils.Utils.java

public static String getPathString(Class<?> clazz) {
    return clazz.getName().replaceAll("\\.", "/") + ".tm";
}

From source file:Main.java

/**
 * <p>Is the specified class an inner class or static nested class.</p>
 *
 * @param cls  the class to check, may be null
 * @return <code>true</code> if the class is an inner or static nested class,
 *  false if not or <code>null</code>
 *///from   w w w. j  ava2 s  .  com
public static boolean isInnerClass(Class cls) {
    if (cls == null) {
        return false;
    }
    return cls.getName().indexOf(INNER_CLASS_SEPARATOR_CHAR) >= 0;
}

From source file:org.flywaydb.test.ExecutionListenerHelper.java

/**
 * Helper method to build test execution information with test class and
 * method/*  www .j  ava  2  s  .c om*/
 * 
 * @param testContext of spring test environment
 * 
 * @return String like &lt;Class Name&gt;[.&lt;Method Name&gt;]
 */
public static String getExecutionInformation(TestContext testContext) {
    String result = "";
    Class<?> testClass = testContext.getTestClass();

    result = testClass.getName();

    // now check for method
    Method m = testContext.getTestMethod();
    if (m != null) {
        result = result + "." + m.getName();
    }

    return result;
}

From source file:Main.java

private static Object convertValType(Object value, Class fieldTypeClass) {
    Object retVal = null;/*from w  w  w .ja v a 2s  .  com*/
    if (Long.class.getName().equals(fieldTypeClass.getName())
            || long.class.getName().equals(fieldTypeClass.getName())) {
        retVal = Long.parseLong(value.toString());
    } else if (Integer.class.getName().equals(fieldTypeClass.getName())
            || int.class.getName().equals(fieldTypeClass.getName())) {
        retVal = Integer.parseInt(value.toString());
    } else if (Float.class.getName().equals(fieldTypeClass.getName())
            || float.class.getName().equals(fieldTypeClass.getName())) {
        retVal = Float.parseFloat(value.toString());
    } else if (Double.class.getName().equals(fieldTypeClass.getName())
            || double.class.getName().equals(fieldTypeClass.getName())) {
        retVal = Double.parseDouble(value.toString());
    } else {
        retVal = value;
    }
    return retVal;
}

From source file:Main.java

/**
 * Decodes a String into an object of the specified type. If the object
 * type is not supported, null will be returned.
 *
 * @param type the type of the property.
 * @param value the encode String value to decode.
 * @return the String value decoded into the specified type.
 * @throws Exception If decoding failed due to an error.
 *///from  www . j av a2  s .co m
private static Object decode(Class type, String value) throws Exception {
    if (type.getName().equals("java.lang.String")) {
        return value;
    }
    if (type.getName().equals("boolean")) {
        return Boolean.valueOf(value);
    }
    if (type.getName().equals("int")) {
        return Integer.valueOf(value);
    }
    if (type.getName().equals("long")) {
        return Long.valueOf(value);
    }
    if (type.getName().equals("float")) {
        return Float.valueOf(value);
    }
    if (type.getName().equals("double")) {
        return Double.valueOf(value);
    }
    if (type.getName().equals("java.lang.Class")) {
        return Class.forName(value);
    }
    return null;
}

From source file:Main.java

public static void checkRecyclerView(ViewGroup recyclerView) {
    checkRecyclerViewOnClassPath();/*from   w w  w .  j  av  a  2s .com*/

    Class clazz = recyclerView.getClass();
    while (clazz != null) {
        if (clazz.getName().equals(RECYCLERVIEW_CLASS_NAME)) {
            return;
        }
        clazz = clazz.getSuperclass();
    }

    throw new IllegalArgumentException("ViewGroup " + recyclerView.getClass().getName() + " not supported");

}

From source file:Main.java

private static Class<?>[] convertToPrimitiveClasses(Class<?>... classes) {

    Collection<Class<?>> convertedClasses = new HashSet<Class<?>>();
    for (Class<?> classObject : classes) {

        if (classObject.getName().equalsIgnoreCase(Integer.class.getName())) {
            convertedClasses.add(int.class);
        } else if (classObject.getName().equalsIgnoreCase(Long.class.getName())) {
            convertedClasses.add(long.class);
        } else if (classObject.getName().equalsIgnoreCase(Float.class.getName())) {
            convertedClasses.add(float.class);
        } else if (classObject.getName().equalsIgnoreCase(Double.class.getName())) {
            convertedClasses.add(double.class);
        } else if (classObject.getName().equalsIgnoreCase(Boolean.class.getName())) {
            convertedClasses.add(boolean.class);
        } else if (classObject.getName().equalsIgnoreCase(Blob.class.getName())) {
            convertedClasses.add(byte.class);
        } else {/*from   w w w  .  jav a 2s.  c  om*/
            convertedClasses.add(classObject);
        }
    }

    Class<?>[] convertedArrayClasses = new Class<?>[convertedClasses.size()];
    Iterator<Class<?>> convertedClassesItr = convertedClasses.iterator();

    int count = 0;
    while (convertedClassesItr.hasNext()) {
        convertedArrayClasses[count++] = convertedClassesItr.next();
    }

    return convertedArrayClasses;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean setProxyLollipop(final Context context, String host, int port) {
    System.setProperty("http.proxyHost", host);
    System.setProperty("http.proxyPort", port + "");
    System.setProperty("https.proxyHost", host);
    System.setProperty("https.proxyPort", port + "");
    try {/*from  w ww  .j a va 2s . com*/
        Context appContext = context.getApplicationContext();
        Class applictionClass = Class.forName("android.app.Application");
        Field mLoadedApkField = applictionClass.getDeclaredField("mLoadedApk");
        mLoadedApkField.setAccessible(true);
        Object mloadedApk = mLoadedApkField.get(appContext);
        Class loadedApkClass = Class.forName("android.app.LoadedApk");
        Field mReceiversField = loadedApkClass.getDeclaredField("mReceivers");
        mReceiversField.setAccessible(true);
        ArrayMap receivers = (ArrayMap) mReceiversField.get(mloadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object receiver : ((ArrayMap) receiverMap).keySet()) {
                Class clazz = receiver.getClass();
                if (clazz.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
                    onReceiveMethod.invoke(receiver, appContext, intent);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:Main.java

public static void LOG_D(Class<?> paramClass, String paramString) {
    if (DEBUG) {//from  www  .  j  a v  a 2 s .  co  m
        String str = paramClass.getName();
        if (str != null) {
            str = str.substring(1 + str.lastIndexOf("."));
        }
        int i = paramString.length();
        if (i > LOG_SIZE_LIMIT) {
            int j = 0;
            int k = 1 + i / LOG_SIZE_LIMIT;
            while (j < k + -1) {
                Log.d(LOG_TAG, paramString.substring(j * LOG_SIZE_LIMIT, LOG_SIZE_LIMIT * (j + 1)));
                j++;
            }
            Log.d(LOG_TAG, paramString.substring(j * LOG_SIZE_LIMIT, i));
        } else {
            Log.d(LOG_TAG, str + " -> " + paramString);
        }
    }

}