@ SuppressWarnings ( "unchecked" ) public < T > T features ( Class < T > interfaceClass ) { try { List < Class < ? > > todo = new ArrayList < Class < ? > > ( ) ; Set < Class < ? > > done = new HashSet < Class < ? > > ( ) ; todo . add ( interfaceClass ) ; while ( ! todo . isEmpty ( ) ) { Class < ? > currentClass = todo . remove ( 0 ) ; done . add ( currentClass ) ; for ( Method method : currentClass . getDeclaredMethods ( ) ) { if ( ! methods . containsKey ( method ) ) { methods . put ( method , findInvocationHandler ( method ) ) ; } for ( Class < ? > superInterfaceClazz : currentClass . getInterfaces ( ) ) { if ( ! done . contains ( superInterfaceClazz ) ) { todo . add ( superInterfaceClazz ) ; } } } } return ( T ) Proxy . newProxyInstance ( interfaceClass . getClassLoader ( ) , new Class [ ] { interfaceClass } , this ) ; } catch ( NoSuchMethodException e ) { throw new PicklockException ( "cannot resolve method/property " + e . getMessage ( ) + " on " + object . getClass ( ) ) ; } }
maps the given interface to the wrapped object