public List < Metric > union ( List < Metric > metrics ) { SystemAssert . requireArgument ( metrics != null , "Cannot transform empty metric/metrics" ) ; if ( metrics . isEmpty ( ) ) { return metrics ; } Metric newMetric = reduce ( metrics ) ; Map < Long , Double > reducedDatapoints = newMetric . getDatapoints ( ) ; Set < Long > sharedTimestamps = reducedDatapoints . keySet ( ) ; Map < Long , Double > unionDatapoints = new TreeMap <> ( ) ; for ( Metric metric : metrics ) { for ( Map . Entry < Long , Double > entry : metric . getDatapoints ( ) . entrySet ( ) ) { if ( ! sharedTimestamps . contains ( entry . getKey ( ) ) ) { unionDatapoints . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } } } newMetric . addDatapoints ( unionDatapoints ) ; return Arrays . asList ( newMetric ) ; }
Performs a columnar union of metrics .