* If this type is a {@link Collection} or array, returns the underlying element type.
* Returns <code>null</code> if this type is neither an array or collection.
* 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();
...
...
@@ -326,27 +326,47 @@ public class TypeDescriptor {
/**
* The collection or array element type as a type descriptor.
* Returns {@link TypeDescriptor#NULL} if this type is not a collection or an array.
* 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
*/
publicTypeDescriptorgetElementTypeDescriptor(){
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.
* If this type is a {@link Map}, returns the underlying key type.
* Returns <code>null</code> if this type is not map.
* Returns Object.class if this type is a map and its key type was not explicitly declared.
* @return the map key type, or <code>null</code> if not a map.
* @throws IllegalStateException if this descriptor is not for a java.util.Map
*/
publicClass<?>getMapKeyType(){
returngetMapKeyTypeDescriptor().getType();
...
...
@@ -354,10 +374,13 @@ public class TypeDescriptor {
/**
* The map key type as a type descriptor.
* Returns {@link TypeDescriptor#NULL} if this type is not a map.
* Returns TypeDescriptor.valueOf(Object.class) if this type is a map and the key type is not explicitly declared.
* @throws IllegalStateException if this descriptor is not for a java.util.Map
*/
publicTypeDescriptorgetMapKeyTypeDescriptor(){
if(!isMap()){
thrownewIllegalStateException("Not a map");
}
returnthis.mapKeyType;
}
...
...
@@ -366,6 +389,7 @@ public class TypeDescriptor {
* Returns <code>null</code> if this type is not map.
* Returns Object.class if this type is a map and its value type was not explicitly declared.
* @return the map value type, or <code>null</code> if not a map.
* @throws IllegalStateException if this descriptor is not for a java.util.Map
*/
publicClass<?>getMapValueType(){
returngetMapValueTypeDescriptor().getType();
...
...
@@ -373,12 +397,32 @@ public class TypeDescriptor {
/**
* The map value type as a type descriptor.
* Returns {@link TypeDescriptor#NULL} if this type is not a map.
* 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
*/
publicTypeDescriptorgetMapValueTypeDescriptor(){
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.