public static List < Class < ? > > filterSameParameterizedTypes ( final List < Class < ? > > types , final Type type ) { if ( type instanceof ParameterizedType ) { Type [ ] fieldArugmentTypes = ( ( ParameterizedType ) type ) . getActualTypeArguments ( ) ; List < Class < ? > > typesWithSameParameterizedTypes = new ArrayList <> ( ) ; for ( Class < ? > currentConcreteType : types ) { List < Type [ ] > actualTypeArguments = getActualTypeArgumentsOfGenericInterfaces ( currentConcreteType ) ; typesWithSameParameterizedTypes . addAll ( actualTypeArguments . stream ( ) . filter ( currentTypeArguments -> Arrays . equals ( fieldArugmentTypes , currentTypeArguments ) ) . map ( currentTypeArguments -> currentConcreteType ) . collect ( toList ( ) ) ) ; } return typesWithSameParameterizedTypes ; } return types ; }
Filters a list of types to keep only elements having the same parameterized types as the given type .