static ArrayList<Datapoint> convertMetricStatisticsToDatapoints(
     Statistics statistics, Collection<MetricStatistics> metrics) {
   ArrayList<Datapoint> datapoints = Lists.newArrayList();
   boolean wantsAverage = statistics.getMember().contains("Average");
   boolean wantsSum = statistics.getMember().contains("Sum");
   boolean wantsSampleCount = statistics.getMember().contains("SampleCount");
   boolean wantsMaximum = statistics.getMember().contains("Maximum");
   boolean wantsMinimum = statistics.getMember().contains("Minimum");
   for (MetricStatistics metricStatistics : metrics) {
     Datapoint datapoint = new Datapoint();
     datapoint.setTimestamp(metricStatistics.getTimestamp());
     datapoint.setUnit(metricStatistics.getUnits().toString());
     if (wantsSum) {
       datapoint.setSum(metricStatistics.getSampleSum());
     }
     if (wantsSampleCount) {
       datapoint.setSampleCount(metricStatistics.getSampleSize());
     }
     if (wantsMaximum) {
       datapoint.setMaximum(metricStatistics.getSampleMax());
     }
     if (wantsMinimum) {
       datapoint.setMinimum(metricStatistics.getSampleMin());
     }
     if (wantsAverage) {
       datapoint.setAverage(
           MetricUtils.average(metricStatistics.getSampleSum(), metricStatistics.getSampleSize()));
     }
     datapoints.add(datapoint);
   }
   return datapoints;
 }
  static Statistics validateStatistics(Statistics statistics) throws CloudWatchException {
    Collection<String> statisticCollection = null;
    if (statistics != null) {
      statisticCollection = statistics.getMember();
    }
    if (statisticCollection == null) {
      throw new MissingParameterException("The parameter Statistics is required.");
    }
    if (statisticCollection.size() < 1) {
      throw new MissingParameterException("The parameter Statistics is required.");
    }

    if (statisticCollection.size() > 5) {
      throw new InvalidParameterValueException(
          "The collection MetricData must not have a size greater than 5.");
    }
    int ctr = 1;
    String[] statisticValues = new String[] {"Average", "Sum", "SampleCount", "Maximum", "Minimum"};
    for (String statistic : statisticCollection) {
      if (statistic == null) {
        throw new InvalidParameterValueException(
            "The parameter Statistics.member." + ctr + " is required.");
      }
      if (!Arrays.asList(statisticValues).contains(statistic)) {
        throw new InvalidParameterValueException(
            "The parameter Statistics.member."
                + ctr
                + " must be a value in the set "
                + Arrays.asList(statisticValues)
                + ".");
      }
      ctr++;
    }
    return statistics;
  }