diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java
index 997f437b2f..38524189f2 100644
--- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/binders/MetricDataBinder.java
@@ -93,8 +93,10 @@ public class MetricDataBinder implements org.jclouds.rest.Binder {
formParameters.put("MetricData.member." + metricDatumIndex + ".Unit",
String.valueOf(metricDatum.getUnit()));
- formParameters.put("MetricData.member." + metricDatumIndex + ".Value",
- String.valueOf(metricDatum.getValue()));
+ if (metricDatum.getValue().isPresent()) {
+ formParameters.put("MetricData.member." + metricDatumIndex + ".Value",
+ String.valueOf(metricDatum.getValue().get()));
+ }
metricDatumIndex++;
}
diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java
index 2bd2d1385e..23745a9eb4 100644
--- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java
+++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/domain/MetricDatum.java
@@ -25,14 +25,16 @@ import java.util.Date;
import java.util.Set;
import com.google.common.base.Objects;
-import com.google.common.base.Optional;
import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
/**
- * @see
- *
+ * @see
+ *
* @author Jeremy Whitlock
*/
public class MetricDatum {
@@ -42,17 +44,17 @@ public class MetricDatum {
private final Optional statisticValues;
private final Optional timestamp;
private final Unit unit;
- private final double value;
+ private final Optional value;
/**
* Private constructor to enforce using {@link Builder}.
*/
- protected MetricDatum(Set dimensions, String metricName, StatisticValues statisticValues, Date timestamp,
- Unit unit, double value) {
- this.dimensions = ImmutableSet.copyOf(checkNotNull(dimensions, "dimensions"));
+ protected MetricDatum(Iterable dimensions, String metricName, Optional statisticValues,
+ Optional timestamp, Unit unit, Optional value) {
+ this.dimensions = ImmutableSet. copyOf(checkNotNull(dimensions, "dimensions"));
this.metricName = checkNotNull(metricName, "metricName");
- this.statisticValues = Optional.fromNullable(statisticValues);
- this.timestamp = Optional.fromNullable(timestamp);
+ this.statisticValues = checkNotNull(statisticValues, "statisticValues");
+ this.timestamp = checkNotNull(timestamp, "timestamp");
this.unit = checkNotNull(unit, "unit");
this.value = checkNotNull(value, "value");
}
@@ -95,13 +97,13 @@ public class MetricDatum {
/**
* return the actual value of the metric
*/
- public double getValue() {
+ public Optional getValue() {
return value;
}
/**
- * Returns a new builder. The generated builder is equivalent to the builder
- * created by the {@link Builder} constructor.
+ * Returns a new builder. The generated builder is equivalent to the builder created by the
+ * {@link Builder} constructor.
*/
public static Builder builder() {
return new Builder();
@@ -110,36 +112,39 @@ public class MetricDatum {
public static class Builder {
// this builder is set to be additive on dimension calls, so make this mutable
- private Set dimensions = Sets.newLinkedHashSet();
+ private ImmutableList.Builder dimensions = ImmutableList. builder();
private String metricName;
- private StatisticValues statisticValues;
- private Date timestamp;
+ private Optional statisticValues = Optional.absent();
+ private Optional timestamp = Optional.absent();
private Unit unit = Unit.NONE;
- private double value;
+ private Optional value = Optional.absent();
/**
- * Creates a new builder. The returned builder is equivalent to the builder
- * generated by {@link org.jclouds.cloudwatch.domain.MetricDatum#builder}.
+ * Creates a new builder. The returned builder is equivalent to the builder generated by
+ * {@link org.jclouds.cloudwatch.domain.MetricDatum#builder}.
*/
- public Builder() {}
+ public Builder() {
+ }
/**
* A list of dimensions describing qualities of the metric.
- *
- * @param dimensions the dimensions describing the qualities of the metric
- *
+ *
+ * @param dimensions
+ * the dimensions describing the qualities of the metric
+ *
* @return this {@code Builder} object
*/
- public Builder dimensions(Set dimensions) {
+ public Builder dimensions(Iterable dimensions) {
this.dimensions.addAll(checkNotNull(dimensions, "dimensions"));
return this;
}
/**
* A dimension describing qualities of the metric.
- *
- * @param dimension the dimension describing the qualities of the metric
- *
+ *
+ * @param dimension
+ * the dimension describing the qualities of the metric
+ *
* @return this {@code Builder} object
*/
public Builder dimension(Dimension dimension) {
@@ -149,9 +154,10 @@ public class MetricDatum {
/**
* The name of the metric.
- *
- * @param metricName the metric name
- *
+ *
+ * @param metricName
+ * the metric name
+ *
* @return this {@code Builder} object
*/
public Builder metricName(String metricName) {
@@ -161,34 +167,37 @@ public class MetricDatum {
/**
* The object describing the set of statistical values describing the metric.
- *
- * @param statisticValues the object describing the set of statistical values for the metric
- *
+ *
+ * @param statisticValues
+ * the object describing the set of statistical values for the metric
+ *
* @return this {@code Builder} object
*/
public Builder statisticValues(StatisticValues statisticValues) {
- this.statisticValues = statisticValues;
+ this.statisticValues = Optional.fromNullable(statisticValues);
return this;
}
/**
- * The time stamp used for the metric. If not specified, the default value is set to the time the metric data was
- * received.
- *
- * @param timestamp the time stamp used for the metric
- *
+ * The time stamp used for the metric. If not specified, the default value is set to the time
+ * the metric data was received.
+ *
+ * @param timestamp
+ * the time stamp used for the metric
+ *
* @return this {@code Builder} object
*/
public Builder timestamp(Date timestamp) {
- this.timestamp = timestamp;
+ this.timestamp = Optional.fromNullable(timestamp);
return this;
}
/**
* The unit for the metric.
- *
- * @param unit the unit for the metric
- *
+ *
+ * @param unit
+ * the unit for the metric
+ *
* @return this {@code Builder} object
*/
public Builder unit(Unit unit) {
@@ -198,13 +207,14 @@ public class MetricDatum {
/**
* The value for the metric.
- *
- * @param value the value for the metric
- *
+ *
+ * @param value
+ * the value for the metric
+ *
* @return this {@code Builder} object
*/
- public Builder value(double value) {
- this.value = value;
+ public Builder value(Double value) {
+ this.value = Optional.fromNullable(value);
return this;
}
@@ -212,7 +222,7 @@ public class MetricDatum {
* Returns a newly-created {@code MetricDatum} based on the contents of the {@code Builder}.
*/
public MetricDatum build() {
- return new MetricDatum(dimensions, metricName, statisticValues, timestamp, unit, value);
+ return new MetricDatum(dimensions.build(), metricName, statisticValues, timestamp, unit, value);
}
}
@@ -240,7 +250,8 @@ public class MetricDatum {
}
protected ToStringHelper string() {
- return Objects.toStringHelper("").add("dimensions", dimensions).add("metricName", metricName).add(
- "statisticValues", statisticValues).add("timestamp", timestamp).add("unit", unit).add("value", value);
+ return Objects.toStringHelper("").omitNullValues().add("dimensions", dimensions).add("metricName", metricName)
+ .add("statisticValues", statisticValues.orNull()).add("timestamp", timestamp.orNull()).add("unit", unit)
+ .add("value", value.orNull());
}
}
diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java
index 94dcac48f6..003fb90274 100644
--- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java
+++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/binders/MetricDataBinderTest.java
@@ -60,7 +60,6 @@ public class MetricDataBinderTest {
.statisticValues(ss)
.dimension(new Dimension("TestDimension", "FAKE"))
.unit(Unit.COUNT)
- .value(2)
.build();
HttpRequest request = binder.bindToRequest(request(), ImmutableSet.of(metricDatum));
@@ -73,8 +72,7 @@ public class MetricDataBinderTest {
"&MetricData.member.1.StatisticValues.Minimum=1.0" +
"&MetricData.member.1.StatisticValues.SampleCount=4.0" +
"&MetricData.member.1.StatisticValues.Sum=10.0" +
- "&MetricData.member.1.Unit=" + Unit.COUNT.toString() +
- "&MetricData.member.1.Value=2.0");
+ "&MetricData.member.1.Unit=" + Unit.COUNT.toString());
}
public void testMetricWithMultipleDimensions() throws Exception {