Merges a list of metrics.

@param   metrics     The metrics to merge.
@param   baseMetric  The base metric.

@return  The merged metrics.
194370
public List<Metric> zip(List<Metric> metrics, Metric baseMetric) {
        SystemAssert.requireArgument(baseMetric != null, "Zipper transform requires base metric as second param!");

        List<Metric> zippedMetrics = new ArrayList<Metric>();
        Map<Long, Double> baseDatapoints = baseMetric.getDatapoints();

        for (Metric metric : metrics) {
            Map<Long, Double> originalDatapoints = metric.getDatapoints();
            Map<Long, Double> zippedDatadpoints = this.zip(originalDatapoints, baseDatapoints);

            metric.setDatapoints(zippedDatadpoints);
            zippedMetrics.add(metric);
        }
        return zippedMetrics;
    }
202352
public List<InMemoryHistoryNode> getMetrics(final String metricName, final Date from,
      final Date to,
      final Boolean useStats) throws ClassCastException {
    final LinkedList<InMemoryHistoryNode> selectedLists = new LinkedList<>();
    if (this.historyListMapping.containsKey(metricName)) {

      logger.debug("selecting snapshots within time frame");
      synchronized (this.historyListMapping.get(metricName)) {
        for (final InMemoryHistoryNode node : this.historyListMapping.get(metricName)) {
          if (node.getTimestamp().after(from) && node.getTimestamp().before(to)) {
            selectedLists.add(node);
          }
          if (node.getTimestamp().after(to)) {
            break;
          }
        }
      }

      // selecting nodes if num of nodes > numInstances
      if (useStats) {
        statBasedSelectMetricHistory(selectedLists);
      } else {
        generalSelectMetricHistory(selectedLists);
      }
    }
    cleanUsingTime(metricName, new Date());
    return selectedLists;
  }
739704
public static List<MetricDto> transformToDto(List<Metric> metrics) {
        if (metrics == null) {
            throw new WebApplicationException("Null entity object cannot be converted to Dto object.", Status.INTERNAL_SERVER_ERROR);
        }

        List<MetricDto> result = new ArrayList<>();

        for (Metric metric : metrics) {
            result.add(transformToDto(metric));
        }
        return result;
    }
1287743
public void setMetricData(java.util.Collection<MetricDatum> metricData) {
        if (metricData == null) {
            this.metricData = null;
            return;
        }

        this.metricData = new com.amazonaws.internal.SdkInternalList<MetricDatum>(metricData);
    }
497540
public static void setCommonAttributes(List<Metric> metrics, Metric result) {
        MetricDistiller distiller = new MetricDistiller();

        distiller.distill(metrics);
        result.setDisplayName(distiller.getDisplayName());
        result.setUnits(distiller.getUnits());
        result.setTags(distiller.getTags());
    }
547572
public void registerNewMetrics(MetricName name, Metric metric) {
		final Set<MetricName> registeredNames = getNames();
		if (!registeredNames.contains(name)) {
			try {
				register(name, metric);
			} catch (IllegalArgumentException e){/* exception due to race condition*/}
		}
	}
1126586
public void mergeHistograms(MetricInfo metricInfo, String meta, Map<Integer, MetricSnapshot> data,
                                Map<String, Integer> metaCounters, Map<String, Map<Integer, Histogram>> histograms) {
        Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
        if (existing == null) {
            metricInfo.put_to_metrics(meta, data);
            Map<Integer, Histogram> histogramMap = new HashMap<>();
            for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
                Histogram histogram = MetricUtils.metricSnapshot2Histogram(dataEntry.getValue());
                histogramMap.put(dataEntry.getKey(), histogram);
            }
            histograms.put(meta, histogramMap);
        } else {
            for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
                Integer win = dataEntry.getKey();
                MetricSnapshot snapshot = dataEntry.getValue();
                MetricSnapshot old = existing.get(win);
                if (old == null) {
                    existing.put(win, snapshot);
                    histograms.get(meta).put(win, MetricUtils.metricSnapshot2Histogram(snapshot));
                } else {
                    if (snapshot.get_ts() >= old.get_ts()) {
                        old.set_ts(snapshot.get_ts());
                        Histogram histogram = histograms.get(meta).get(win);
                        Snapshot updateSnapshot = histogram.getSnapshot();
                        if (updateSnapshot instanceof JAverageSnapshot) {
                            sumMetricSnapshot(((JAverageSnapshot) updateSnapshot).getMetricSnapshot(), snapshot);
                        } else {
                            // update points
                            MetricUtils.updateHistogramPoints(histogram, snapshot.get_points(), snapshot.get_pointSize());
                        }
                    }
                }
            }
        }
        updateMetricCounters(meta, metaCounters);
    }
1306710
public void mergeMeters(MetricInfo metricInfo, String meta, Map<Integer, MetricSnapshot> data) {
        Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
        if (existing == null) {
            metricInfo.put_to_metrics(meta, data);
        } else {
            for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
                Integer win = dataEntry.getKey();
                MetricSnapshot snapshot = dataEntry.getValue();
                MetricSnapshot old = existing.get(win);
                if (old == null) {
                    existing.put(win, snapshot);
                } else {
                    if (snapshot.get_ts() >= old.get_ts()) {
                        old.set_ts(snapshot.get_ts());
                        old.set_mean(old.get_mean() + snapshot.get_mean());
                        old.set_m1(old.get_m1() + snapshot.get_m1());
                        old.set_m5(old.get_m5() + snapshot.get_m5());
                        old.set_m15(old.get_m15() + snapshot.get_m15());
                    }
                }
            }
        }
    }
1099556
@Override
  public void getMetrics(MetricsCollector collector, boolean all) {
    MetricsRecordBuilder metricsRecordBuilder = collector.addRecord("sparkShuffleService");

    for (Map.Entry<String, Metric> entry : metricSet.getMetrics().entrySet()) {
      collectMetric(metricsRecordBuilder, entry.getKey(), entry.getValue());
    }
  }
610060
public boolean merge(ResourceMetadata other) {
        boolean modified = m_metrics.addAll(other.m_metrics);
        if (!modified) {
            modified = !m_attributes.equals(other.m_attributes);
        }
        m_attributes.putAll(other.m_attributes);
        return modified;
    }
1077343
protected List<Metric> mapping(List<Metric> metrics, List<String> constants) {
		SystemAssert.requireArgument(metrics != null, "Cannot transform null metrics");

		if (metrics.isEmpty()) {
			return metrics;
		}

		List<Metric> newMetricsList = new ArrayList<Metric>();

		for (Metric metric : metrics) {
			metric.setDatapoints(this.valueReducerOrMapping.mapping(metric.getDatapoints(), constants));
			newMetricsList.add(metric);
		}
		return newMetricsList;
	}
1092951
public void setMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory)
   {
      if (metricsTrackerFactory != null) {
         this.metricsTracker = new MetricsTrackerDelegate(metricsTrackerFactory.create(config.getPoolName(), getPoolStats()));
      }
      else {
         this.metricsTracker = new NopMetricsTrackerDelegate();
      }
   }
31116
protected void updateMetricCounters(String metricName, Map<String, Integer> metricNameCounters) {
        if (metricNameCounters.containsKey(metricName)) {
            metricNameCounters.put(metricName, metricNameCounters.get(metricName) + 1);
        } else {
            metricNameCounters.put(metricName, 1);
        }
    }
1239774
@Override
    public List<Metric> transform(QueryContext context, List<Metric> metrics) {
        List<String> l = new ArrayList<String>();
        int size = metrics.get(0).getDatapoints().size();
        if (size >= 52 * 2) {
            l.add(0, "52");
        } else {
            l.add(0, Integer.toString(size/2));
        }
        return transform(null, metrics, l);
    }
190827
public List<Series> retrieveMetricSeries(String metricName, String entityName) {
        return retrieveMetricSeries(metricName, Collections.singletonMap("entity", entityName));
    }
477831
@Override
	public List<Metric> transform(QueryContext queryContext, List<Metric> metrics, List<String> constants) {
		if (constants == null || constants.isEmpty()) {
			return transform(queryContext, metrics);
		}

		if (constants.size() == 1) {
			if (constants.get(0).toUpperCase().equals(FULLJOIN)){
				fulljoinIndicator=true;
				return transform(queryContext, metrics);
			}else if(constants.get(0).toUpperCase().equals(INTERSECT)) {
				fulljoinIndicator=false;
				return transform(queryContext, metrics);
			}
		}
		return mapping(metrics, constants);
	}
161969
public Iterable<MetricsInfo> filter(Iterable<MetricsInfo> metricsInfos) {
    List<MetricsInfo> metricsFiltered = new ArrayList<MetricsInfo>();
    for (MetricsInfo metricsInfo : metricsInfos) {
      if (contains(metricsInfo.getName())) {
        metricsFiltered.add(metricsInfo);
      }
    }

    return metricsFiltered;
  }