public Double getPowerSourceMetric ( String powerSourceName , ID metricToCollect ) { Map < String , PowerSource > cache = getPowerSources ( ) ; PowerSource powerSource = cache . get ( powerSourceName ) ; if ( powerSource == null ) { return null ; } if ( PlatformMetricType . POWER_SOURCE_REMAINING_CAPACITY . getMetricTypeId ( ) . equals ( metricToCollect ) ) { return powerSource . getRemainingCapacity ( ) ; } else if ( PlatformMetricType . POWER_SOURCE_TIME_REMAINING . getMetricTypeId ( ) . equals ( metricToCollect ) ) { return powerSource . getTimeRemaining ( ) ; } else { throw new UnsupportedOperationException ( "Invalid power source metric to collect: " + metricToCollect ) ; } }
Returns the given metric s value or null if there is no power source with the given name .