List of usage examples for java.lang Class getSimpleName
public String getSimpleName()
From source file:Main.java
public static String createTableSql(Class<?> classs, String tableName, String... extraColumns) { mBuffer.setLength(0);//from w w w.j a v a 2 s.co m mBuffer.append("CREATE TABLE IF NOT EXISTS "); if (!TextUtils.isEmpty(tableName)) { mBuffer.append(tableName); } else { String className = classs.getSimpleName(); if (className.contains("[]")) { throw new IllegalArgumentException("Can not create array class table"); } mBuffer.append(classs.getSimpleName()); } mBuffer.append("(" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "); Field[] fields = classs.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; if (field.getType() == Integer.class) { mBuffer.append(field.getName() + " INTEGER,"); } else if (field.getType() == Double.class || field.getType() == Float.class) { mBuffer.append(field.getName() + " REAL,"); } else if (field.getType() == String.class) { mBuffer.append(field.getName() + " TEXT,"); } else if (field.getType() == Boolean.class) { mBuffer.append(field.getName() + " INTEGER,"); } else if (field.getType() == List.class || field.getType() == ArrayList.class) { mBuffer.append(field.getName() + " TEXT,"); } } if (extraColumns != null && extraColumns.length != 0) { for (int i = 0; i < extraColumns.length; i++) { mBuffer.append(extraColumns[i]); if (i != extraColumns.length - 1) { mBuffer.append(","); } else { mBuffer.append(")"); } } } return mBuffer.toString(); }
From source file:org.focusns.common.validation.ValidationHelper.java
/** * ? bean class ? ?? ?/*from w ww . j a v a 2 s.c o m*/ * * @param validatorFactory * @param clazz * @param groups * @return */ public static ValidatedBean createForClass(ValidatorFactory validatorFactory, Class<?> clazz, Class<?>... groups) { Class<?> beanType = clazz; String beanName = StringUtils.uncapitalize(clazz.getSimpleName()); // ValidatedBean validatedBean = new ValidatedBean(beanName, beanType); // Validator validator = validatorFactory.getValidator(); MessageInterpolator messageInterpolator = validatorFactory.getMessageInterpolator(); // BeanDescriptor beanDescriptor = validator.getConstraintsForClass(beanType); Set<PropertyDescriptor> propertyDescriptors = beanDescriptor.getConstrainedProperties(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String propertyName = propertyDescriptor.getPropertyName(); ValidatedProperty validatedProperty = new ValidatedProperty(propertyName); // Set<ConstraintDescriptor<?>> constraintDesctipors = propertyDescriptor.getConstraintDescriptors(); for (final ConstraintDescriptor<?> constraintDescriptor : constraintDesctipors) { // groups checks if (isOutOfGroup(constraintDescriptor, groups)) { continue; } // String constraintName = getConstraintName(constraintDescriptor); List<String> constraintParams = getConstraintParams(constraintDescriptor); ValidatedConstraint validatedConstraint = new ValidatedConstraint(constraintName, constraintParams); // String messageTemplate = (String) constraintDescriptor.getAttributes().get("message"); MessageInterpolator.Context context = new MessageInterpolatorContext(constraintDescriptor); String message = messageInterpolator.interpolate(messageTemplate, context); // validatedConstraint.setMessage(message); // validatedProperty.addValidatedConstraint(validatedConstraint); } // if (!validatedProperty.getValidatedConstraints().isEmpty()) { // validatedBean.addValidatedProperty(validatedProperty); } } // return validatedBean; }
From source file:com.pingcap.tikv.catalog.CatalogTransaction.java
public static <T> T parseFromJson(ByteString json, Class<T> cls) { Objects.requireNonNull(json, "json is null"); Objects.requireNonNull(cls, "cls is null"); logger.debug(String.format("Parse Json %s : %s", cls.getSimpleName(), json.toStringUtf8())); ObjectMapper mapper = new ObjectMapper(); try {//from w w w. jav a 2 s. c o m return mapper.readValue(json.toStringUtf8(), cls); } catch (JsonParseException | JsonMappingException e) { String errMsg = String.format("Invalid JSON value for Type %s: %s\n", cls.getSimpleName(), json.toStringUtf8()); throw new TiClientInternalException(errMsg, e); } catch (Exception e1) { throw new TiClientInternalException("Error parsing Json", e1); } }
From source file:org.opensprout.osaf.util.ApplicationContextUtils.java
public static <T> T getBeanByType(ApplicationContext applicationContext, Class<T> clazz) { Map beanMap = applicationContext.getBeansOfType(clazz); int size = beanMap.size(); if (size == 0) { if (applicationContext.getParent() != null) return getBeanByType(applicationContext.getParent(), clazz); throw new NoSuchBeanDefinitionException(clazz.getSimpleName()); }/*from ww w . j a v a2 s . c om*/ if (size > 1) throw new NoSuchBeanDefinitionException( "No unique bean definition type [" + clazz.getSimpleName() + "]"); return (T) beanMap.values().iterator().next(); }
From source file:com.haulmont.cuba.core.sys.persistence.DbmsSpecificFactory.java
public static <T> T create(Class<T> intf, String dbmsType, String dbmsVersion) { String intfName = intf.getName(); String packageName = intfName.substring(0, intfName.lastIndexOf('.') + 1); String name = packageName + StringUtils.capitalize(dbmsType) + dbmsVersion + intf.getSimpleName(); Class<?> aClass;/*from www .ja va 2s . co m*/ try { aClass = ReflectionHelper.loadClass(name); } catch (ClassNotFoundException e) { name = packageName + StringUtils.capitalize(dbmsType) + intf.getSimpleName(); try { aClass = ReflectionHelper.loadClass(name); } catch (ClassNotFoundException e1) { throw new RuntimeException("Error creating " + intfName + " implementation", e1); } } try { //noinspection unchecked return (T) aClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException("Error creating " + intfName + " implementation", e); } }
From source file:com.github.mybatis.spring.MapperFactoryBean.java
private static boolean isPrimitive(Class clz) { return clz.isPrimitive() || NAMES.contains(clz.getSimpleName()); }
From source file:fr.duminy.components.swing.form.JFormPane.java
public static <B> String getDefaultPanelName(Class<B> beanClass) { return beanClass.getSimpleName(); }
From source file:at.tuwien.ifs.somtoolbox.apps.SOMToolboxMain.java
/** * @param runnables ArrayList of available main-classes * @param runable The main class specified on command line * @param cleanArgs the arguments for the main class. * @param useGUI <code>true</code> if the {@link GenericGUI} should be used. * @return <code>true</code> if invocation was successful, <code>false</code> otherwise. *///from ww w. ja v a 2 s .co m private static boolean invokeMainClass(ArrayList<Class<? extends SOMToolboxApp>> runnables, String runable, String[] cleanArgs, boolean useGUI) { boolean exe = false; for (Class<? extends SOMToolboxApp> r : runnables) { if (r.getSimpleName().equalsIgnoreCase(runable)) { exe = tryInvokeMain(r, cleanArgs, useGUI); if (exe) { break; } } else { } } if (!exe) { try { exe = tryInvokeMain(Class.forName(runable), cleanArgs, useGUI); } catch (ClassNotFoundException e) { exe = false; } } if (!exe) { try { exe = tryInvokeMain(Class.forName("at.tuwien.ifs.somtoolbox." + runable), cleanArgs, useGUI); } catch (ClassNotFoundException e) { exe = false; } } return exe; }
From source file:com.splunk.shuttl.testutil.TUtilsFile.java
private static File getUniquelyNamedFileWithPrefix(String prefix) { Class<?> callerToThisMethod = MethodCallerHelper.getCallerToMyMethod(); String tempDirName = prefix + "-" + callerToThisMethod.getSimpleName(); File file = getFileInShuttlTestDirectory(tempDirName); while (file.exists()) { tempDirName += "-" + RandomStringUtils.randomAlphanumeric(2); file = getFileInShuttlTestDirectory(tempDirName); }/*from www.j a va 2 s. co m*/ return file; }
From source file:com.tesora.dve.common.PEStringUtils.java
public static <T> String toString(Class<T> theClass, Collection<? extends Object> values) { return toString(new StringBuffer(), theClass.getSimpleName(), values).toString(); }