* If this type is a {@link Collection} or array, returns the underlying element type.
* Returns Object.class if this type is a collection and the element type was not explicitly declared.
* @return the map element type, or <code>null</code> if not a collection or array.
* @throws IllegalStateException if this descriptor is not for a java.util.Collection or Array
*/
publicClass<?>getElementType(){
returngetElementTypeDescriptor().getType();
returngetType().isArray();
}
/**
* The collection or array element type as a type descriptor.
* Returns TypeDescriptor.valueOf(Object.class) if this type is a collection and the element type is not explicitly declared.
* @throws IllegalStateException if this descriptor is not for a java.util.Collection or Array
* If this type is an array, returns the array's component type.
* If this type is a {@link Collection} and it is parameterized, returns the Collection's element type.
* If the Collection is not parameterized, returns null indicating the element type is not declared.
* @return the array component type or Collection element type, or <code>null</code> if this type is a Collection but its element type is not parameterized.
* @throws IllegalStateException if this type is not a java.util.Collection or Array type
*/
publicTypeDescriptorgetElementTypeDescriptor(){
publicTypeDescriptorgetElementType(){
if(!isCollection()&&!isArray()){
thrownewIllegalStateException("Not a java.util.Collection or Array");
}
returnthis.elementType;
}
/**
* Returns a copy of this type descriptor that has its elementType populated from the specified Collection.
* This property will be set by calculating the "common element type" of the specified Collection.
* For example, if the collection contains String elements, the returned TypeDescriptor will have its elementType set to String.
* This method is designed to be used when converting values read from Collection fields or method return values that are not parameterized e.g. Collection vs. Collection<String>
* In this scenario the elementType will be Object.class before invoking this method.
* @param colection the collection to derive the elementType from
* @return a new TypeDescriptor with the resolved elementType property
* @throws IllegalArgumentException if this is not a type descriptor for a java.util.Collection.
* Returns TypeDescriptor.valueOf(Object.class) if this type is a map and the value type is not explicitly declared.
* @throws IllegalStateException if this descriptor is not for a java.util.Map
* If this type is a {@link Map} and its value type is parameterized, returns the map's value type.
* If the Map's value type is not parameterized, returns null indicating the value type is not declared.
* @return the Map value type, or <code>null</code> if this type is a Map but its value type is not parameterized.
* @throws IllegalStateException if this type is not a java.util.Map.
*/
publicTypeDescriptorgetMapValueTypeDescriptor(){
publicTypeDescriptorgetMapValueType(){
if(!isMap()){
thrownewIllegalStateException("Not a map");
}
returnthis.mapValueType;
}
/**
* Returns a copy of this type descriptor that has its mapKeyType and mapValueType properties populated from the specified Map.
* These properties will be set by calculating the "common element type" of the specified Map's keySet and values collection.
* For example, if the Map contains String keys and Integer values, the returned TypeDescriptor will have its mapKeyType set to String and its mapValueType to Integer.
* This method is designed to be used when converting values read from Map fields or method return values that are not parameterized e.g. Map vs. Map<String, Integer>.
* In this scenario the key and value types will be Object.class before invoking this method.
* @param map the map to derive key and value types from
* @return a new TypeDescriptor with the resolved mapKeyType and mapValueType properties
* @throws IllegalArgumentException if this is not a type descriptor for a java.util.Map.