Class CollectionTypeUtils
java.lang.Object
tech.guilhermekaua.spigotboot.core.utils.CollectionTypeUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable CollectionTypeUtils.CollectionTypeInfoextractCollectionTypeInfo(@NotNull Type type) Extracts collection type information from aType, identifying both the collection class and its element type.static @Nullable CollectionTypeUtils.MapTypeInfoextractMapTypeInfo(@NotNull Type type) Extracts map type information from aType, identifying both the key and value types.static <T> @Nullable Class<T>getRawClass(@NotNull Type type) Extracts the raw class from aType, handling both simple classes and parameterized types.
-
Constructor Details
-
CollectionTypeUtils
public CollectionTypeUtils()
-
-
Method Details
-
extractCollectionTypeInfo
@Nullable public static @Nullable CollectionTypeUtils.CollectionTypeInfo extractCollectionTypeInfo(@NotNull @NotNull Type type) Extracts collection type information from aType, identifying both the collection class and its element type. This method analyzes parameterized types to determine if they represent a collection (e.g.,List,Set,Collection) and extracts the generic element type. The method handles:- Parameterized collection types (e.g.,
List<String>,Set<Service>) - Wildcard types with upper bounds (e.g.,
List<? extends Service>) - Raw types and non-collection types return
null
extractCollectionTypeInfo(new TypeToken<List<String>>(){}.getType())returnsCollectionTypeInfowith collection classList.classand element typeString.classextractCollectionTypeInfo(new TypeToken<Set<Service>>(){}.getType())returnsCollectionTypeInfowith collection classSet.classand element typeService.classextractCollectionTypeInfo(String.class)returnsnull(not a collection)extractCollectionTypeInfo(List.class)returnsnull(raw type, no generics)
- Parameters:
type- the type to analyze, not null- Returns:
- a
CollectionTypeUtils.CollectionTypeInfocontaining the collection class and element type, ornullif the type is not a parameterized collection type - Throws:
NullPointerException- iftypeis null
- Parameterized collection types (e.g.,
-
getRawClass
Extracts the raw class from aType, handling both simple classes and parameterized types. This method is useful when you need to work with the actual class type, ignoring generic type parameters. For parameterized types (e.g.,List<String>), it returns the raw type (e.g.,List.class). For simple class types, it returns the class itself. Examples:getRawClass(String.class)returnsString.classgetRawClass(new TypeToken<List<String>>(){}.getType())returnsList.classgetRawClass(new TypeToken<Map<String, Integer>>(){}.getType())returnsMap.class
- Type Parameters:
T- the type parameter for the returned class- Parameters:
type- the type to extract the raw class from, not null- Returns:
- the raw class, or
nullif the type cannot be converted to a class - Throws:
NullPointerException- iftypeis null
-
extractMapTypeInfo
@Nullable public static @Nullable CollectionTypeUtils.MapTypeInfo extractMapTypeInfo(@NotNull @NotNull Type type) Extracts map type information from aType, identifying both the key and value types.This method analyzes parameterized types to determine if they represent a
Mapand extracts the generic key and value types.The method handles:
- Parameterized map types (e.g.,
Map<String, Location>) - Wildcard types with upper bounds (e.g.,
Map<String, ? extends Location>) - Raw types and non-map types return
null
- Parameters:
type- the type to analyze, not null- Returns:
- a
CollectionTypeUtils.MapTypeInfocontaining the key and value types, ornullif the type is not a parameterized map type - Throws:
NullPointerException- iftypeis null
- Parameterized map types (e.g.,
-