-
Notifications
You must be signed in to change notification settings - Fork 53
io microsphere util TypeFinder
Type: Class | Module: microsphere-java-core | Package: io.microsphere.util | Since: 1.0.0
Source:
microsphere-java-core/src/main/java/io/microsphere/util/TypeFinder.java
A utility class for finding related types based on a given type.
This class allows searching for various related types such as:
- Self (the type itself)
- Direct superclass
- Interfaces directly implemented by the type
- Hierarchical types (recursive search through superclasses and interfaces)
`// Find all hierarchical types of String.class including itself
TypeFinder> finder = TypeFinder.classFinder(String.class, TypeFinder.Include.HIERARCHICAL);
List> types = finder.getTypes();
// Find only interfaces implemented by ArrayList.class
TypeFinder> finder = TypeFinder.classFinder(ArrayList.class, TypeFinder.Include.INTERFACES);
List> interfaceTypes = finder.getTypes();
// Custom combination: include self and interfaces but not superclass
TypeFinder> finder = new TypeFinder<>(MyClass.class,
TypeFinder.classGetSuperClassFunction,
TypeFinder.classGetInterfacesFunction,
true, // includeSelf
false, // includeHierarchicalTypes
false, // includeSuperclass
true); // includeInterfaces
`
public class TypeFinder<T>Author: Mercy
-
Introduced in:
1.0.0 -
Current Project Version:
0.2.2-SNAPSHOT
This component is tested and compatible with the following Java versions:
| Java Version | Status |
|---|---|
| Java 8 | ✅ Compatible |
| Java 11 | ✅ Compatible |
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |
// Find all hierarchical types of String.class including itself
TypeFinder<Class<?>> finder = TypeFinder.classFinder(String.class, TypeFinder.Include.HIERARCHICAL);
List<Class<?>> types = finder.getTypes();
// Find only interfaces implemented by ArrayList.class
TypeFinder<Class<?>> finder = TypeFinder.classFinder(ArrayList.class, TypeFinder.Include.INTERFACES);
List<Class<?>> interfaceTypes = finder.getTypes();
// Custom combination: include self and interfaces but not superclass
TypeFinder<Class<?>> finder = new TypeFinder<>(MyClass.class,
TypeFinder.classGetSuperClassFunction,
TypeFinder.classGetInterfacesFunction,
true, // includeSelf
false, // includeHierarchicalTypes
false, // includeSuperclass
true); // includeInterfacesTypeFinder<Class<?>> finder = new TypeFinder<>(
ArrayList.class,
(Function) Class::getSuperclass,
(Function) Class::getInterfaces,
true, // includeSelf
true, // includeHierarchicalTypes
true, // includeSuperclass
true // includeInterfaces
);TypeFinder<Class<?>> finder = TypeFinder.classFinder(ArrayList.class, TypeFinder.Include.HIERARCHICAL);
List<Class<?>> types = finder.getTypes();
// types contains AbstractList, AbstractCollection, Object, List, Collection, Iterable, ...TypeFinder<Class<?>> finder = TypeFinder.classFinder(HashMap.class, TypeFinder.Include.HIERARCHICAL);
List<Class<?>> interfaces = finder.findTypes(Class::isInterface);
// interfaces contains Map, Cloneable, Serializable, ...// Typically invoked internally by findTypes:
TypeFinder<Class<?>> finder = TypeFinder.classFinder(LinkedList.class, TypeFinder.Include.HIERARCHICAL);
List<Class<?>> types = finder.findTypes(t -> t != Object.class);TypeFinder<Class<?>> finder = TypeFinder.classFinder(ArrayList.class, TypeFinder.Include.HIERARCHICAL);
// Internally called as:
// getSuperTypes(ArrayList.class, true, true)
// returns [AbstractList, List, RandomAccess, Cloneable, Serializable]TypeFinder<Class<?>> finder = TypeFinder.classFinder(HashMap.class, TypeFinder.Include.SUPER_CLASS);
// Internally: getSuperClass(HashMap.class) returns AbstractMap.classTypeFinder<Class<?>> finder = TypeFinder.classFinder(ArrayList.class, TypeFinder.Include.INTERFACES);
// Internally: getInterfaces(ArrayList.class) returns [List, RandomAccess, Cloneable, Serializable]TypeFinder<Class<?>> finder = TypeFinder.classFinder(LinkedList.class, TypeFinder.Include.HIERARCHICAL);
// Internally, addSuperTypes is called recursively to collect:
// AbstractSequentialList, AbstractList, AbstractCollection, Object, List, Deque, Queue, ...TypeFinder<Class<?>> finder = TypeFinder.classFinder(ArrayList.class,
TypeFinder.Include.SELF, TypeFinder.Include.INTERFACES);
List<Class<?>> types = finder.getTypes();
// types contains ArrayList plus its directly implemented interfacesTypeFinder<Class<?>> finder = TypeFinder.classFinder(HashMap.class,
true, // includeSelf
true, // includeHierarchicalTypes
true, // includeSuperclass
false // includeInterfaces
);
List<Class<?>> types = finder.getTypes();
// types contains HashMap, AbstractMap, ObjectTypeFinder<Type> finder = TypeFinder.genericTypeFinder(ArrayList.class,
TypeFinder.Include.SELF, TypeFinder.Include.HIERARCHICAL);
List<Type> types = finder.getTypes();
// types contains generic types such as AbstractList<E>, List<E>, Collection<E>, Iterable<E>, ...TypeFinder<Type> finder = TypeFinder.genericTypeFinder(HashMap.class,
true, // includeSelf
false, // includeHierarchicalTypes
true, // includeSuperclass
true // includeInterfaces
);
List<Type> types = finder.getTypes();
// types contains HashMap, AbstractMap<K,V>, Map<K,V>, Cloneable, SerializableAdd the following dependency to your pom.xml:
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-java-core</artifactId>
<version>${microsphere-java.version}</version>
</dependency>Tip: Use the BOM (
microsphere-java-dependencies) for consistent version management. See the Getting Started guide.
import io.microsphere.util.TypeFinder;| Method | Description |
|---|---|
getTypes |
The enumeration for the type finder includes |
findTypes |
Finds related types that match all the specified filters. |
classFinder |
Performs the actual type finding logic by collecting related types and applying filters. |
classFinder |
Creates a TypeFinder for Class types with explicit boolean configuration. |
genericTypeFinder |
Creates a TypeFinder for generic Type instances using the specified include options. |
genericTypeFinder |
Creates a TypeFinder for generic Type instances with explicit boolean configuration. |
public List<T> getTypes()The enumeration for the type finder includes / public static enum Include {
SELF,
HIERARCHICAL,
SUPER_CLASS,
INTERFACES }
private final T type;
private final boolean includeSelf;
private final boolean includeHierarchicalTypes;
private final boolean includeSuperclass;
private final boolean includeInterfaces;
private final Function getSuperClassFunction;
private final Function getInterfacesFunction;
/**
Constructs a new TypeFinder with the specified type and configuration options.
`TypeFinder> finder = new TypeFinder<>(
ArrayList.class,
(Function) Class::getSuperclass,
(Function) Class::getInterfaces,
true, // includeSelf
true, // includeHierarchicalTypes
true, // includeSuperclass
true // includeInterfaces
);
`
Since: 1.0.0
public List<T> findTypes(Predicate<? super T>... typeFilters)Finds related types that match all the specified filters.
`TypeFinder> finder = TypeFinder.classFinder(HashMap.class, TypeFinder.Include.HIERARCHICAL); List> interfaces = finder.findTypes(Class::isInterface); // interfaces contains Map, Cloneable, Serializable, ... `
Since: 1.0.0
public static TypeFinder<Class<?>> classFinder(Class type, TypeFinder.Include... includes)Performs the actual type finding logic by collecting related types and applying filters.
`// Typically invoked internally by findTypes: TypeFinder> finder = TypeFinder.classFinder(LinkedList.class, TypeFinder.Include.HIERARCHICAL); List> types = finder.findTypes(t -> t != Object.class); `
Since: 1.0.0
public static TypeFinder<Class<?>> classFinder(Class type, boolean includeSelf, boolean includeHierarchicalTypes,
boolean includeSuperclass, boolean includeInterfaces)Creates a TypeFinder for Class types with explicit boolean configuration.
`TypeFinder> finder = TypeFinder.classFinder(HashMap.class,
true, // includeSelf
true, // includeHierarchicalTypes
true, // includeSuperclass
false // includeInterfaces
);
List> types = finder.getTypes();
// types contains HashMap, AbstractMap, Object
`
Since: 1.0.0
public static TypeFinder<Type> genericTypeFinder(Type type, TypeFinder.Include... includes)Creates a TypeFinder for generic Type instances using the specified include options.
Unlike #classFinder(Class, Include...), this method resolves generic superclass and
generic interface types.
`TypeFinder finder = TypeFinder.genericTypeFinder(ArrayList.class,
TypeFinder.Include.SELF, TypeFinder.Include.HIERARCHICAL);
List types = finder.getTypes();
// types contains generic types such as AbstractList, List, Collection, Iterable, ...
`
Since: 1.0.0
public static TypeFinder<Type> genericTypeFinder(Type type, boolean includeSelf, boolean includeHierarchicalTypes,
boolean includeSuperclass, boolean includeInterfaces)Creates a TypeFinder for generic Type instances with explicit boolean configuration.
Unlike #classFinder(Class, boolean, boolean, boolean, boolean), this method resolves
generic superclass and generic interface types.
`TypeFinder finder = TypeFinder.genericTypeFinder(HashMap.class,
true, // includeSelf
false, // includeHierarchicalTypes
true, // includeSuperclass
true // includeInterfaces
);
List types = finder.getTypes();
// types contains HashMap, AbstractMap, Map, Cloneable, Serializable
`
Since: 1.0.0
Type
This documentation was auto-generated from the source code of microsphere-java.
annotation-processor
- ConfigurationPropertyAnnotationProcessor
- ConfigurationPropertyJSONElementVisitor
- FilerProcessor
- ResourceProcessor
java-annotations
java-core
- ACLLoggerFactory
- AbstractArtifactResourceResolver
- AbstractConverter
- AbstractDeque
- AbstractEventDispatcher
- AbstractLogger
- AbstractURLClassPathHandle
- AccessibleObjectUtils
- AdditionalMetadataResourceConfigurationPropertyLoader
- AnnotationUtils
- ArchiveFileArtifactResourceResolver
- ArrayEnumeration
- ArrayStack
- ArrayUtils
- Artifact
- ArtifactDetector
- ArtifactResourceResolver
- Assert
- BannedArtifactClassLoadingExecutor
- BaseUtils
- BeanMetadata
- BeanProperty
- BeanUtils
- ByteArrayToObjectConverter
- CharSequenceComparator
- CharSequenceUtils
- CharsetUtils
- ClassDataRepository
- ClassDefinition
- ClassFileJarEntryFilter
- ClassFilter
- ClassLoaderUtils
- ClassPathResourceConfigurationPropertyLoader
- ClassPathUtils
- ClassUtils
- ClassicProcessIdResolver
- ClassicURLClassPathHandle
- CollectionUtils
- Compatible
- CompositeSubProtocolURLConnectionFactory
- CompositeURLStreamHandlerFactory
- ConditionalEventListener
- ConfigurationProperty
- ConfigurationPropertyGenerator
- ConfigurationPropertyLoader
- ConfigurationPropertyReader
- Configurer
- ConsoleURLConnection
- Constants
- ConstructorDefinition
- ConstructorUtils
- Converter
- Converters
- CustomizedThreadFactory
- DefaultConfigurationPropertyGenerator
- DefaultConfigurationPropertyReader
- DefaultDeserializer
- DefaultEntry
- DefaultSerializer
- DelegatingBlockingQueue
- DelegatingDeque
- DelegatingIterator
- DelegatingQueue
- DelegatingScheduledExecutorService
- DelegatingURLConnection
- DelegatingURLStreamHandlerFactory
- DelegatingWrapper
- Deprecation
- Deserializer
- Deserializers
- DirectEventDispatcher
- DirectoryFileFilter
- EmptyDeque
- EmptyIterable
- EmptyIterator
- EnumerationIteratorAdapter
- EnumerationUtils
- Event
- EventDispatcher
- EventListener
- ExceptionUtils
- ExecutableDefinition
- ExecutableUtils
- ExecutorUtils
- ExtendableProtocolURLStreamHandler
- FastByteArrayInputStream
- FastByteArrayOutputStream
- FieldDefinition
- FieldUtils
- FileChangedEvent
- FileChangedListener
- FileConstants
- FileExtensionFilter
- FileUtils
- FileWatchService
- Filter
- FilterOperator
- FilterUtils
- FormatUtils
- Functional
- GenericEvent
- GenericEventListener
- Handler
- Handler
- HierarchicalClassComparator
- IOFileFilter
- IOUtils
- ImmutableEntry
- IterableAdapter
- IterableUtils
- Iterators
- JDKLoggerFactory
- JSON
- JSONArray
- JSONException
- JSONObject
- JSONStringer
- JSONTokener
- JSONUtils
- JarEntryFilter
- JarUtils
- JavaType
- JmxUtils
- ListUtils
- Listenable
- Lists
- Logger
- LoggerFactory
- LoggingFileChangedListener
- MBeanAttribute
- MBeanAttributeInfoBuilder
- MBeanConstructorInfoBuilder
- MBeanDescribableBuilder
- MBeanExecutableInfoBuilder
- MBeanFeatureInfoBuilder
- MBeanInfoBuilder
- MBeanNotificationInfoBuilder
- MBeanOperationInfoBuilder
- MBeanParameterInfoBuilder
- ManagementUtils
- ManifestArtifactResourceResolver
- MapToPropertiesConverter
- MapUtils
- Maps
- MavenArtifact
- MavenArtifactResourceResolver
- MemberDefinition
- MemberUtils
- MetadataResourceConfigurationPropertyLoader
- MethodDefinition
- MethodHandleUtils
- MethodHandlesLookupUtils
- MethodUtils
- ModernProcessIdResolver
- ModernURLClassPathHandle
- Modifier
- MultiValueConverter
- MultipleType
- MutableInteger
- MutableURLStreamHandlerFactory
- NameFileFilter
- NoOpLogger
- NoOpLoggerFactory
- NoOpURLClassPathHandle
- NumberToByteConverter
- NumberToCharacterConverter
- NumberToDoubleConverter
- NumberToFloatConverter
- NumberToIntegerConverter
- NumberToLongConverter
- NumberToShortConverter
- NumberUtils
- ObjectToBooleanConverter
- ObjectToByteArrayConverter
- ObjectToByteConverter
- ObjectToCharacterConverter
- ObjectToDoubleConverter
- ObjectToFloatConverter
- ObjectToIntegerConverter
- ObjectToLongConverter
- ObjectToOptionalConverter
- ObjectToShortConverter
- ObjectToStringConverter
- PackageNameClassFilter
- PackageNameClassNameFilter
- ParallelEventDispatcher
- ParameterizedTypeImpl
- PathConstants
- Predicates
- Prioritized
- PriorityComparator
- ProcessExecutor
- ProcessIdResolver
- ProcessManager
- PropertiesToStringConverter
- PropertiesUtils
- PropertyConstants
- PropertyResourceBundleControl
- PropertyResourceBundleUtils
- ProtocolConstants
- ProxyUtils
- QueueUtils
- ReadOnlyIterator
- ReflectionUtils
- ReflectiveConfigurationPropertyGenerator
- ReflectiveDefinition
- ResourceConstants
- ReversedDeque
- Scanner
- SecurityUtils
- SeparatorConstants
- Serializer
- Serializers
- ServiceLoaderURLStreamHandlerFactory
- ServiceLoaderUtils
- ServiceLoadingURLClassPathHandle
- SetUtils
- Sets
- Sfl4jLoggerFactory
- ShutdownHookCallbacksThread
- ShutdownHookUtils
- SimpleClassScanner
- SimpleFileScanner
- SimpleJarEntryScanner
- SingletonDeque
- SingletonEnumeration
- SingletonIterator
- StackTraceUtils
- StandardFileWatchService
- StandardURLStreamHandlerFactory
- StopWatch
- StreamArtifactResourceResolver
- Streams
- StringBuilderWriter
- StringConverter
- StringDeserializer
- StringSerializer
- StringToArrayConverter
- StringToBlockingDequeConverter
- StringToBlockingQueueConverter
- StringToBooleanConverter
- StringToByteConverter
- StringToCharArrayConverter
- StringToCharacterConverter
- StringToClassConverter
- StringToCollectionConverter
- StringToDequeConverter
- StringToDoubleConverter
- StringToDurationConverter
- StringToFloatConverter
- StringToInputStreamConverter
- StringToIntegerConverter
- StringToIterableConverter
- StringToListConverter
- StringToLongConverter
- StringToMultiValueConverter
- StringToNavigableSetConverter
- StringToQueueConverter
- StringToSetConverter
- StringToShortConverter
- StringToSortedSetConverter
- StringToStringConverter
- StringToTransferQueueConverter
- StringUtils
- SubProtocolURLConnectionFactory
- SymbolConstants
- SystemUtils
- ThrowableAction
- ThrowableBiConsumer
- ThrowableBiFunction
- ThrowableConsumer
- ThrowableFunction
- ThrowableSupplier
- ThrowableUtils
- TrueClassFilter
- TrueFileFilter
- TypeArgument
- TypeFinder
- TypeUtils
- URLClassPathHandle
- URLUtils
- UnmodifiableDeque
- UnmodifiableIterator
- UnmodifiableQueue
- Utils
- ValueHolder
- Version
- VersionUtils
- VirtualMachineProcessIdResolver
- Wrapper
- WrapperProcessor
java-test
- AbstractAnnotationProcessingTest
- Ancestor
- AnnotationProcessingTestProcessor
- ArrayTypeModel
- CollectionTypeModel
- Color
- CompilerInvocationInterceptor
- ConfigurationPropertyModel
- DefaultTestService
- GenericTestService
- MapTypeModel
- Model
- Parent
- PrimitiveTypeModel
- SimpleTypeModel
- StringArrayList
- TestAnnotation
- TestService
- TestServiceImpl
jdk-tools
lang-model