private static void mergeWildcardTypes ( final List < Type > types , final Type ... addition ) { if ( types . isEmpty ( ) ) { Collections . addAll ( types , addition ) ; return ; } for ( Type add : addition ) { final Class < ? > addClass = GenericsUtils . resolveClass ( add ) ; final Iterator < Type > it = types . iterator ( ) ; boolean additionApproved = true ; while ( it . hasNext ( ) ) { final Type type = it . next ( ) ; // it can't contain incompatible generics just because of sane sense (type system will not allow) final Class < ? > typeClass = GenericsUtils . resolveClass ( type ) ; if ( addClass . isAssignableFrom ( typeClass ) ) { if ( TypeUtils . isMoreSpecific ( add , type ) ) { // replace it . remove ( ) ; } else { // more specific type already contained additionApproved = false ; } break ; } } if ( additionApproved ) { types . add ( add ) ; } } }
Adds new types to wildcard if types are not already contained . If added type is more specific then already contained type then it replace such type .