balu: (Memed2)
[personal profile] balu
ИМХО, такое сильно хуже пихания в Object:

  1. import java.util.HashMap;  
  2. import java.util.List;  
  3. import java.util.Map;  
  4.   
  5. import static com.google.common.collect.Maps.filterValues;  
  6. import static com.google.common.collect.Maps.transformValues;  
  7. import static java.util.Map.Entry;  
  8.   
  9. public class Test {  
  10.     private Map<Class<?>, Map<String, List<String>>> compressDependencies(  
  11.             Map<Class<?>, Map<String, List<String>>> dependencies ) {  
  12.   
  13.         final Map<Class<?>, Map<String, List<String>>> result = new HashMap<>();  
  14.         for( Entry<Class<?>, Map<String, List<String>>> clazz : dependencies.entrySet() ) {  
  15.   
  16.             final Map<String, List<String>> desc = new HashMap<>();  
  17.             for( Entry<String, List<String>> d : clazz.getValue().entrySet() ) {  
  18.                 List<String> value = d.getValue();  
  19.                 if( !value.isEmpty() ) desc.put( d.getKey(), value );  
  20.             }  
  21.             result.put( clazz.getKey(), desc );  
  22.         }  
  23.         return result;  
  24.     }  
  25.   
  26.     private Map<Class<?>, Map<String, List<String>>> compressDependencies2(  
  27.             Map<Class<?>, Map<String, List<String>>> dependencies ) {  
  28.         return transformValues( dependencies, map -> filterValues( map, v -> !v.isEmpty() ) );  
  29.     }  
  30. }  


Правда, на модном ныне хаскеле можно изобразить похожее:

Profile

balu: (Default)
от. Михайло

December 2025

S M T W T F S
 123 456
7 8910111213
14151617181920
21222324252627
28293031   

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 2nd, 2026 05:12 am
Powered by Dreamwidth Studios