java.lang.Object
imagingbook.common.util.ClassUtils
Static utility methods related to classes.
- Version:
- 2022/11/20
-
Method Summary
Modifier and TypeMethodDescriptionCollects and returns the list of classes defined in the specified package.getClassesInPackage(String pkgName) Collects and returns the list of classes defined in the specified package.static <T extends Comparable>
Comparator<T> getComparator(Class<T> clazz) Returns the "natural order"Comparatorinstance for the specifiedComparableclass.static <E extends Enum<E>>
E[]getEnumConstantsSorted(Class<E> enumClass) Returns an array of all constants defined by the specified enum class, sorted by their names.static StringlistFields(Object obj) Lists all accessible public fields of the given object and returns the result as a string.
-
Method Details
-
listFields
Lists all accessible public fields of the given object and returns the result as a string.- Parameters:
obj- a (non-null) object- Returns:
- a string listing the names and values of the object's fields
-
getClassesInPackage
Collects and returns the list of classes defined in the specified package. ThePackagemay be obtained from an existingClassobject (clazz) byclazz.getPackage().- Parameters:
pkg- aPackageinstance, e.g.,Package.getPackage("imagingbook.lib.ij.overlay")- Returns:
- a list of classes contained in the package
-
getClassesInPackage
Collects and returns the list of classes defined in the specified package. Adapted from https://stackoverflow.com/a/58773271- Parameters:
pkgName- the full package name, e.g., "imagingbook.lib.ij.overlay"- Returns:
- a list of classes contained in the package
-
getEnumConstantsSorted
Returns an array of all constants defined by the specified enum class, sorted by their names.- Type Parameters:
E- generic type- Parameters:
enumClass- the enum class- Returns:
- an array of enum items sorted by names
-
getComparator
Returns the "natural order"Comparatorinstance for the specifiedComparableclass. UseComparator.reversed()to obtain the comparator for sorting in reverse order.- Type Parameters:
T- the generic type- Parameters:
clazz- a class implementingComparable- Returns:
- the associated
Comparatorinstance
-