private < T , U > void clearMap ( Map < T , Set < U > > map , BiConsumer < T , U > consumer ) { for ( T observable : map . keySet ( ) ) { for ( U listener : map . get ( observable ) ) { consumer . accept ( observable , listener ) ; } } map . clear ( ) ; }
This method is used to clear the given map . To do this you need to implement a BiConsumer that calls the specific method to remove a listener from an observable .