@ GwtIncompatible ( "incompatible method" ) @ SuppressWarnings ( "unchecked" ) @ Nullable public static < T > T findValueOfType ( final Collection < ? > collection , @ Nullable final Class < T > type ) { if ( CollectionUtils . isEmpty ( collection ) ) { return null ; } T value = null ; for ( final Object element : collection ) { if ( type == null || type . isInstance ( element ) ) { if ( value != null ) { // More than one value found... no clear single value. return null ; } value = ( T ) element ; } } return value ; }
Find a single value of the given type in the given Collection .