/*
 * The MIT License
 *
 * Copyright (c) 2014, CloudBees, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.codahale.metrics.jenkins;

import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricSet;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.ExtensionPoint;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Provides metrics to register.
 */
public abstract class MetricProvider implements ExtensionPoint {
    /**
     * Returns the set of metrics to register.
     *
     * @return the set of metrics to register.
     */
    @NonNull
    public abstract MetricSet getMetricSet();

    protected static Map.Entry<String, Metric> metric(String name, Metric metric) {
        return new StringImmutableEntry<Metric>(name, metric);
    }

    protected static MetricSet metrics(Map.Entry<String, Metric>... metrics) {
        final Map<String, Metric> result = new LinkedHashMap<String, Metric>(metrics.length);
        for (Map.Entry<String, Metric> metric : metrics) {
            result.put(metric.getKey(), metric.getValue());
        }
        return new FixedMetricSet(result);
    }

    private static class FixedMetricSet implements MetricSet {
        private final Map<String, Metric> result;

        public FixedMetricSet(Map<String, Metric> result) {
            this.result = Collections.unmodifiableMap(result);
        }

        public Map<String, Metric> getMetrics() {
            return result;
        }
    }
}

@@ -1525,185 +1525,8 @@
 t %7B%0A
-    /**%0A     * Returns the set of metrics to register.%0A     *%0A     * @return the set of metrics to register.%0A     */%0A    @NonNull%0A    public abstract MetricSet getMetricSet();%0A%0A
     
@@ -1899,32 +1899,99 @@
 ic : metrics) %7B%0A
+            if (metric != null && metric.getValue() != null) %7B%0A    
             resu
@@ -2034,16 +2034,30 @@
 lue());%0A
+            %7D%0A
         
@@ -2104,24 +2104,201 @@
 lt);%0A    %7D%0A%0A
+    /**%0A     * Returns the set of metrics to register.%0A     *%0A     * @return the set of metrics to register.%0A     */%0A    @NonNull%0A    public abstract MetricSet getMetricSet();%0A%0A
     private 

Allow metrics that are not supported to be safely handled in the utility methods