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:ch.systemsx.cisd.openbis.generic.client.web.server.translator.UserFailureExceptionTranslator.java

private static String getPackageName(Class<?> clazz) {
    String fullName = clazz.getName();
    return fullName.substring(0, fullName.length() - clazz.getSimpleName().length() - 1);
}

From source file:com.redhat.rhtracking.persistance.services.Queries.java

public static <T extends Catalog, K extends Serializable> void initCatalog(List<String> catalogue,
        CrudRepository<T, K> repository, Class<T> type) {
    logger.info("Starting " + type.getSimpleName() + " catalog");
    Iterable<T> typeItr = repository.findAll();
    for (T t : typeItr) {
        if (catalogue.contains(t.toString())) {
            catalogue.remove(t.toString());
        }/*w ww .  j  a  v  a2 s.  c o m*/
    }
    if (!catalogue.isEmpty()) {
        try {
            for (String s : catalogue) {
                T missing = type.newInstance();
                missing.setType(s);
                repository.save(missing);
            }
        } catch (IllegalAccessException | InstantiationException ex) {
            logger.error(ex);
        }
    }
}

From source file:com.carmatech.maven.model.MergerTestUtils.java

public static <T> String readExpectedProperties(final String name, final Class<T> clazz) throws IOException {
    return Files.toString(new File(name), UTF_8).replace("${merger}", clazz.getSimpleName());
}

From source file:de.vandermeer.asciitable.commons.Table_ToStringStyle.java

/**
 * Returns a builder using the class and the value
 * @param clazz current class for the string
 * @param values values for the string, printed comma separated
 * @return a StrBuilder combining the inputs
 *///  www .  j a  v  a2  s .c  o  m
public static StrBuilder kv(Class<?> clazz, Object... values) {
    StrBuilder ret = new StrBuilder(50).append(clazz.getSimpleName()).append('[')
            .appendWithSeparators(values, ", ").append(']');
    return ret;
}

From source file:Main.java

static String getRootElementName(Class<?> clazz) {
    XmlRootElement element = (XmlRootElement) clazz.getAnnotation(XmlRootElement.class);
    return !DEFAULT_NAME.equals(element.name()) ? element.name() : clazz.getSimpleName();
}

From source file:kr.co.bitnine.octopus.util.StringUtils.java

/**
 * Print a log message for starting up and shutting down
 *
 * @param clazz the class of the server//from ww w .j av  a  2  s.  c  o m
 * @param args  arguments
 * @param log   the target log object
 */
public static void startupShutdownMessage(Class<?> clazz, String[] args, final Log log) {
    final String classname = clazz.getSimpleName();
    final String hostname = NetUtils.getHostname();

    final String build = VersionInfo.getUrl() + ", rev. " + VersionInfo.getRevision() + "; compiled by '"
            + VersionInfo.getUser() + "' on " + VersionInfo.getDate();
    String[] msg = new String[] { "Starting " + classname, "  host = " + hostname,
            "  args = " + Arrays.asList(args), "  version = " + VersionInfo.getVersion(),
            "  classpath = " + System.getProperty("java.class.path"), "  build = " + build,
            "  java = " + System.getProperty("java.version") };
    log.info(toStartupShutdownString("STARTUP_MSG: ", msg));

    if (SystemUtils.IS_OS_UNIX) {
        try {
            SignalLogger.INSTANCE.register(log);
        } catch (Throwable t) {
            log.warn("failed to register any UNIX signal loggers: ", t);
        }
    }
    ShutdownHookManager.get().addShutdownHook(new Runnable() {
        @Override
        public void run() {
            log.info(toStartupShutdownString("SHUTDOWN_MSG: ",
                    new String[] { "Shutting down " + classname + " at " + hostname }));
        }
    }, SHUTDOWN_HOOK_PRIORITY);
}

From source file:Main.java

public static <T> T castObjectOrThrow(Object o, Class<T> clazz) {
    try {//  w ww.ja  va 2 s.  c o m
        return clazz.cast(o);
    } catch (ClassCastException e) {
        throw new ClassCastException(o.toString() + " must implement " + clazz.getSimpleName());
    }
}

From source file:Main.java

public static void replaceFragment(FragmentManager manager, Class<? extends Fragment> fragmentClass,
        boolean isAddToBackStack) {

    Fragment fragment = manager.findFragmentByTag(fragmentClass.getSimpleName());

    if (null == fragment) {
        try {/*from  w  w  w  .j a va  2s.c o  m*/

            fragment = fragmentClass.newInstance();

        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }

    FragmentTransaction ft = manager.beginTransaction();
    ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out, android.R.anim.fade_in,
            android.R.anim.fade_out);
    if (!fragment.isAdded()) {
        ft.replace(android.R.id.content, fragment, fragment.getClass().getSimpleName());
        if (isAddToBackStack) {
            ft.addToBackStack(null);
        }
    }
    ft.commit();

}

From source file:Main.java

public static <T> T getView(Object object, Class<T> t) {

    try {/*ww w  .  j  av  a 2  s  . c  o m*/
        return (T) object;
    } catch (ClassCastException e) {

        throw new IllegalStateException(object.getClass().getSimpleName() + t.getSimpleName()
                + " does not implement contract interface", e);
    }
}

From source file:com.gargoylesoftware.htmlunit.TestCaseTest.java

/**
 * Returns list of all host classes defined.
 * @return the list/*w  w  w .ja  v a  2  s .c  om*/
 * @throws Exception if an error occurs.
 */
public static List<String> getAllClassNames() throws Exception {
    final Field field = JavaScriptConfiguration.class.getDeclaredField("CLASSES_");
    field.setAccessible(true);

    final List<String> list = new ArrayList<>();
    for (final Class<?> c : (Class<?>[]) field.get(null)) {
        final String name = c.getSimpleName();
        list.add(name);
    }
    list.add(Intl.class.getSimpleName());
    list.add("Error");
    return list;
}