List of usage examples for java.lang Class getName
public String getName()
From source file:Main.java
/** * Given an input class object, return a string which consists of the class's package name as a pathname, i.e., all dots ('.') are replaced by slashes ('/'). Neither a leading nor trailing slash is added. The result could be concatenated with a slash and the name of a resource, and fed directly to <code>ClassLoader.getResource()</code>. For it to be fed to <code>Class.getResource</code> instead, a leading slash would also have to be prepended to the returned value. * /*from w w w. jav a 2s. c om*/ * @param clazz * the input class. A <code>null</code> value or the default (empty) package will result in an empty string ("") being returned. * @return a path which represents the package name * @see ClassLoader#getResource * @see Class#getResource */ public static String classPackageAsResourcePath(Class<?> clazz) { if (clazz == null) { return ""; } String className = clazz.getName(); int packageEndIndex = className.lastIndexOf('.'); if (packageEndIndex == -1) { return ""; } String packageName = className.substring(0, packageEndIndex); return packageName.replace('.', '/'); }
From source file:com.shelfmap.stepsfinder.CandidateStepsFactory.java
public static String packagePath(Class<?> codeLocationClass) { String classPath = codeLocationClass.getName().replace(".", "/"); return removeEnd(classPath, codeLocationClass.getSimpleName()); }
From source file:Main.java
private static void setterValue(PropertyDescriptor property, Object mapValue, Object object) throws InvocationTargetException, IllegalAccessException, ParseException { Method setter = property.getWriteMethod(); if (mapValue == null) { setter.invoke(object, mapValue); return;// www . j a v a 2 s . c om } Class propertyType = property.getPropertyType(); String type = propertyType.getName(); String value = mapValue.toString(); if (type.equals("java.lang.String")) { setter.invoke(object, value); } else if (type.equals("java.lang.Integer")) { setter.invoke(object, Integer.parseInt(value)); } else if (type.equals("java.lang.Long")) { setter.invoke(object, Long.parseLong(value)); } else if (type.equals("java.math.BigDecimal")) { setter.invoke(object, BigDecimal.valueOf(Double.parseDouble(value))); } else if (type.equals("java.math.BigInteger")) { setter.invoke(object, BigInteger.valueOf(Long.parseLong(value))); } else if (type.equals("java.util.Date")) { setter.invoke(object, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value)); } else if (type.equals("java.lang.Boolean")) { setter.invoke(object, Boolean.valueOf(value)); } else if (type.equals("java.lang.Float")) { setter.invoke(object, Float.parseFloat(value)); } else if (type.equals("java.lang.Double")) { setter.invoke(object, Double.parseDouble(value)); } else if (type.equals("java.lang.byte[]")) { setter.invoke(object, value.getBytes()); } else { setter.invoke(object, value); } }
From source file:Main.java
/** * Checks if a class is a subclass of a class with the specified name. Used * as an instanceOf without having to load the class, useful when trying to * check for classes that might not be available in the runtime JRE. * /*w ww. j a v a2 s.c o m*/ * @param clazz * The class to check * @param className * The class name to look for in the super classes * @return true if the class extends a class by the specified name. */ public static boolean extendsClass(final Class<?> clazz, String className) { Class<?> superClass = clazz.getSuperclass(); while (superClass != null) { if (superClass.getName().equals(className)) { return true; } superClass = superClass.getSuperclass(); } return false; }
From source file:Main.java
public static long generateCodeOfMethod(Class<?> providerClass, Method method) { StringBuilder buider = new StringBuilder(method.getName()); long classCode = providerClass.getName().hashCode(); Class<?>[] paramTypes = method.getParameterTypes(); for (Class<?> c : paramTypes) { buider.append(c.getName());/*www . j ava2s . c o m*/ } return classCode << 32 + buider.toString().hashCode(); }
From source file:Main.java
public static void printFields(Class cl) { Field[] fields = cl.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field f = fields[i];// ww w . ja v a 2 s. c om Class type = f.getType(); String name = f.getName(); System.out.print(Modifier.toString(f.getModifiers())); System.out.println(" " + type.getName() + " " + name + ";"); } }
From source file:com.googlecode.flyway.core.util.ClassUtils.java
/** * Computes the short name (name without package) of this class. * * @param aClass The class to analyse.//w ww .j a v a2s. co m * @return The short name. */ public static String getShortName(Class<?> aClass) { String name = aClass.getName(); return name.substring(name.lastIndexOf(".") + 1); }
From source file:com.glaf.activiti.tasklistener.factory.TaskListenerTypes.java
public static void addTaskListener(Class<?> clazz) { String name = clazz.getName(); taskListeners.put(name, clazz); }
From source file:Main.java
private static TypeKind getKindOfType(Class<?> type) { if (!type.isPrimitive()) { return TypeKind.DECLARED; }/*ww w . j a v a 2 s . c o m*/ return TypeKind.valueOf(type.getName().toUpperCase()); }
From source file:Main.java
public static String getPlainName(Class<?> type) { String typeName = type.getCanonicalName(); if (typeName == null) { typeName = type.getName().replace('$', '.'); }// w ww.ja va 2s . c o m return getPlainName(typeName); }