Example usage for java.lang Class toString

List of usage examples for java.lang Class toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Converts the object to a string.

Usage

From source file:com.sf.ddao.chain.CtxHelper.java

public static <T> T remove(Context ctx, Class<T> clazz) {
    //noinspection unchecked
    return (T) ctx.remove(clazz.toString());
}

From source file:com.sf.ddao.chain.CtxHelper.java

public static <T> T put(Context ctx, Class<T> clazz, T value) {
    //noinspection unchecked
    return (T) ctx.put(clazz.toString(), value);
}

From source file:com.sf.ddao.chain.CtxHelper.java

public static <T> T get(Context ctx, Class<T> clazz, Callable<T> callback) throws Exception {
    //noinspection unchecked
    T res = (T) ctx.get(clazz.toString());
    if (res == null) {
        res = callback.call();/*from   w  ww.j a  va  2 s. co m*/
        put(ctx, clazz, res);
    }
    return res;
}

From source file:Main.java

private static String getUnmappedElementName(Class<?> c, boolean brief) {
    if (brief) {// w  w w  .j a va 2 s. co m
        String name = c.getName();
        return name.substring(name.lastIndexOf('.') + 1);
    }
    return c.toString();
}

From source file:nl.knaw.dans.common.lang.search.bean.SearchBeanUtil.java

private static void checkSearchBean(Class<?> sbClass) throws ObjectIsNotASearchBeanException {
    if (!sbClass.isAnnotationPresent(SearchBean.class))
        throw new ObjectIsNotASearchBeanException(sbClass.toString());
}

From source file:org.jdto.impl.BeanClassUtils.java

/**
 * Create a new instance of a class or log the exception if the class is not
 * instanceable. This method will rethrow any exception as an unchecked
 * {@link RuntimeException}.//from w w  w.j  a  v  a 2  s  .com
 *
 * @param <T>
 * @param cls
 * @return a new instance of the type given in the argument.
 */
public static <T> T createInstance(Class<T> cls) {
    try {
        return cls.newInstance();
    } catch (Throwable t) {
        logger.error("Could not create bean instance of class " + cls.toString(), t);
        throw new RuntimeException(t);
    }
}

From source file:org.dd4t.databind.builder.BaseDataBinder.java

private static void storeModelClassForModelNames(final List<String> viewModelNames, final Class model) {
    for (String viewModelName : viewModelNames) {
        LOG.info("Storing viewModelName: {}, for class: {}", viewModelName, model.toString());
        if (VIEW_MODELS.containsKey(viewModelName)) {
            LOG.warn("Key: {} already exists! Model for key is: {}", viewModelName, model.toString());
        } else {//from   ww  w  .j  av  a2  s . c o  m
            VIEW_MODELS.put(viewModelName, model);
        }
    }
}

From source file:com.google.cloud.genomics.dockerflow.util.StringUtils.java

/** Deserialize from json. */
public static <T> T fromJson(String s, Class<T> c) throws IOException {
    FileUtils.LOG.debug("Deserializing from json to " + c);
    T retval;/* w  w  w.ja  v a2  s .c o  m*/

    // For some reason, this only works for auto-generated Google API
    // classes
    if (c.toString().startsWith("com.google.api.services.")) {
        FileUtils.LOG.debug("Using Google APIs JsonParser");
        retval = Utils.getDefaultJsonFactory().createJsonParser(s).parse(c);
    } else {
        FileUtils.LOG.debug("Using Gson");
        retval = new GsonBuilder().setLenient().create().fromJson(s, c);
    }
    return retval;
}

From source file:gr.ntua.ece.cslab.panic.core.client.Benchmark.java

/**
 * Method used to configure the benchmarking tool in order to set the
 * benchmark parameters./* w w  w.j  a  v a 2s  . co m*/
 *
 * @param args
 * @throws Exception
 */
public static void configure(String args[]) throws Exception {
    // cli arguments parsing
    cliOptionsSetup(args);
    CommandLineParser parser = new GnuParser();
    cmd = parser.parse(options, args);

    if (cmd.hasOption("h")) {
        HelpFormatter format = new HelpFormatter();
        format.printHelp(Main.class.toString(), options);
        System.exit(0);
    }

    if (cmd.hasOption("list-models")) {
        for (Class<? extends Model> c : discoverModels()) {
            System.out.println(c.toString());
        }
        System.exit(1);
    }

    if (cmd.hasOption("list-samplers")) {
        for (Class<? extends Sampler> c : discoverSamplers()) {
            System.out.println(c.toString());
        }
        System.exit(1);
    }

    if (cmd.hasOption("i")) {
        inputFile = cmd.getOptionValue("i");
    } else {
        System.err.println("Input file is necessary");
        HelpFormatter format = new HelpFormatter();
        format.printHelp(Main.class.toString(), options);
        System.exit(0);
    }

    if (cmd.hasOption("o")) {
        outputPrintStream = new PrintStream(cmd.getOptionValue("o"));
    } else {
        outputPrintStream = System.out;
    }

    if (cmd.hasOption("sr")) {
        samplingRate = new Double(cmd.getOptionValue("sr"));
    } else {
        samplingRate = 0.2;
    }

    if (cmd.hasOption("mo")) {
        metricsOut = new PrintStream(cmd.getOptionValue("mo"));
    } else {
        metricsOut = System.out;
    }

    instantiateModels();
    instantiateSamplers();

}

From source file:org.jdto.impl.BeanClassUtils.java

/**
 * Create a new instance of a class using a specific constructor or log the
 * exception if the class is not instanceable. This method will rethrow any
 * exception as an unchecked {@link RuntimeException}.
 *
 * @param <T> the type of the instance to create
 * @param cls the class which represents the type of the instance to create.
 * @param constructor the constructor to use.
 * @param args an array of the constructor arguments.
 * @return a new instance of the type given on the argument by using the
 * specified constructor.//w ww. java 2s  . co m
 */
public static <T> T createInstance(Class<T> cls, Constructor constructor, Object... args) {
    try {
        return (T) constructor.newInstance(args);
    } catch (Throwable t) {
        logger.error("Could not create bean instance of class" + cls.toString(), t);
        throw new RuntimeException(t);
    }
}