}
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
GetMetricStatistics getRequest = GetMetricStatistics.class.cast(checkNotNull(payload,
"GetMetricStatistics must be set!"));
int dimensionIndex = 1;
int statisticIndex = 1;
ImmutableMultimap.Builder<String, String> formParameters = ImmutableMultimap.builder();
for (Dimension dimension : getRequest.getDimensions()) {
formParameters.put("Dimensions.member." + dimensionIndex + ".Name", dimension.getName());
formParameters.put("Dimensions.member." + dimensionIndex + ".Value", dimension.getValue());
dimensionIndex++;
}
if (getRequest.getEndTime().isPresent()) {
formParameters.put("EndTime", dateService.iso8601SecondsDateFormat(getRequest.getEndTime().get()));
}
formParameters.put("MetricName", getRequest.getMetricName());
formParameters.put("Namespace", getRequest.getNamespace());
formParameters.put("Period", Integer.toString(getRequest.getPeriod()));
if (getRequest.getStartTime().isPresent()) {
formParameters.put("StartTime", dateService.iso8601SecondsDateFormat(getRequest
.getStartTime().get()));
}
for (Statistics statistic : getRequest.getStatistics()) {
formParameters.put("Statistics.member." + statisticIndex, statistic.toString());
statisticIndex++;
}
if (getRequest.getUnit().isPresent()) {
formParameters.put("Unit", getRequest.getUnit().get().toString());
}
return (R) request.toBuilder().replaceFormParams(formParameters.build()).build();
}