private static < T extends Callback > T getCallbackByType ( Iterable < Callback > callbacks , Class < T > callbackType ) { T foundCallback = null ; Iterator < Callback > callbackIterator = callbacks . iterator ( ) ; while ( foundCallback == null && callbackIterator . hasNext ( ) ) { Callback callback = callbackIterator . next ( ) ; // Remove callback wrappers while ( ( callback instanceof Delegating ) && ( ! callbackType . isInstance ( callback ) ) ) { callback = ( ( Delegating < Callback > ) callback ) . getDelegate ( ) ; } if ( callbackType . isInstance ( callback ) ) { // Callback found foundCallback = callbackType . cast ( callback ) ; } else if ( callback instanceof CompositeCallback ) { // Visit the composite callback foundCallback = getCallbackByType ( ( ( CompositeCallback ) callback ) . callbacks ( ) , callbackType ) ; } } return foundCallback ; }
Search callback by type in list of callbacks