Here you can find the source of getClasses(Class infoClass)
Parameter | Description |
---|---|
infoClass | Class for which classes are wanted. |
public static String[] getClasses(Class infoClass)
//package com.java2s; /* Please see the license information at the end of this file. */ import java.util.*; public class Main { /** Get classes for a class. *//from w w w . ja v a 2 s . co m * @param infoClass Class for which classes are wanted. * * @return String array of classes. * */ public static String[] getClasses(Class infoClass) { String result[] = null; Object[] classes = null; // Get list of internal classes, both // public and private. classes = infoClass.getDeclaredClasses(); // Return null result if no classes. if ((classes == null) || (classes.length == 0)) return result; // Sort classes in ascending order by class name. Comparator comparator = new Comparator() { public int compare(Object o1, Object o2) { return o1.toString().compareTo(o2.toString()); } }; Arrays.sort(classes, comparator); result = new String[classes.length]; // Create "result" array containing list // of class names. for (int i = 0; i < classes.length; i++) { Object aClass = classes[i]; // Throw away the leading "class" etc. // modifier. result[i] = trimClassName(aClass.toString()); int firstBlank = result[i].indexOf(' '); if (firstBlank != -1) { result[i] = result[i].substring(firstBlank + 1); } } // Return string array of class names. return result; } /** * Removes class modifiers, leaving only the class name. * * @param name The class name plus modifiers, if any. * * @return The class name stripped of modifiers. * */ public static String trimClassName(String name) { String result; // Find last period in class name. int lastPeriod = name.lastIndexOf('.'); // If found, strip everything // before it. The result is the // unmodified class name. // e.g., // a.b.c.simple -> simple . if (lastPeriod != -1) { result = name.substring(lastPeriod + 1); } else { result = name; } // Return trimmed class name. return result; } }