private static DecoratorMap metric_map_ ( Map < IdentifierPair , MetricMatcher > matchers ) { if ( matchers . isEmpty ( ) ) return concat ( ) ; return new DecoratorMap ( ) { @ Override public Stream < Consumer < MutableContext > > map ( Stream < Consumer < MutableContext > > in , Context ctx ) { final Map < IdentifierPair , List < Map . Entry < MetricMatcher . MatchedName , MetricValue > > > metricMapping = matchers . entrySet ( ) . stream ( ) . collect ( Collectors . toMap ( Map . Entry :: getKey , mmEntry -> mmEntry . getValue ( ) . filter ( ctx ) . collect ( Collectors . toList ( ) ) ) ) ; for ( final Map . Entry < IdentifierPair , List < Map . Entry < MetricMatcher . MatchedName , MetricValue > > > mm : metricMapping . entrySet ( ) ) { final String groupIdentifier = mm . getKey ( ) . getGroup ( ) ; final String metricIdentifier = mm . getKey ( ) . getMetric ( ) ; final List < Consumer < MutableContext > > applications = mm . getValue ( ) . stream ( ) . map ( matchedMetric -> { Consumer < MutableContext > application = ( nestedCtx ) - > { nestedCtx . putGroupAliasByName ( groupIdentifier , matchedMetric . getKey ( ) . getMatchedGroup ( ) :: getGroup ) ; nestedCtx . putMetricAliasByName ( metricIdentifier , matchedMetric . getKey ( ) . getMatchedGroup ( ) :: getGroup , matchedMetric . getKey ( ) :: getMetric ) ; } ; return application ; } ) . collect ( Collectors . toList ( ) ) ; in = in . flatMap ( inApplication -> applications . stream ( ) . map ( inApplication :: andThen ) ) ; } return in ; } } ; }
Create a decorator map from a mapping of metric matchers .