public H getHandler ( Object o ) { if ( o == null ) { return null ; } // note that we start at the end of the list. ListIterator < Pair < Class < ? > , H > > iter = handlers . listIterator ( handlers . size ( ) ) ; while ( iter . hasPrevious ( ) ) { Pair < Class < ? > , H > pair = iter . previous ( ) ; try { // if we can cast to the restriction class, use the given handler. pair . getFirst ( ) . cast ( o ) ; return pair . getSecond ( ) ; } catch ( ClassCastException e ) { // do nothing, but try previous in list } } return null ; }
Find a matching handler for the given object