Follow up to e58d91e that addresses pull request comments.

This commit is contained in:
Jeremy Whitlock 2012-04-30 22:00:25 -06:00
parent 270dfcbff2
commit f06d273764
6 changed files with 84 additions and 174 deletions

View File

@ -18,10 +18,11 @@
*/ */
package org.jclouds.cloudwatch.domain; package org.jclouds.cloudwatch.domain;
import java.util.Date; import com.google.common.base.Objects;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import java.util.Date;
/** /**
* @see <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/index.html?DT_Datapoint.html" * @see <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/index.html?DT_Datapoint.html"
* /> * />
@ -118,17 +119,7 @@ public class Datapoint {
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; return Objects.hashCode(super.hashCode(), average, customUnit, maximum, minimum, samples, sum, timestamp, unit);
int result = 1;
result = prime * result + ((average == null) ? 0 : average.hashCode());
result = prime * result + ((customUnit == null) ? 0 : customUnit.hashCode());
result = prime * result + ((maximum == null) ? 0 : maximum.hashCode());
result = prime * result + ((minimum == null) ? 0 : minimum.hashCode());
result = prime * result + ((samples == null) ? 0 : samples.hashCode());
result = prime * result + ((sum == null) ? 0 : sum.hashCode());
result = prime * result + ((timestamp == null) ? 0 : timestamp.hashCode());
result = prime * result + ((unit == null) ? 0 : unit.hashCode());
return result;
} }
@Override @Override
@ -140,53 +131,27 @@ public class Datapoint {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
Datapoint other = (Datapoint) obj; Datapoint other = (Datapoint) obj;
if (average == null) { return Objects.equal(this.average, other.average) &&
if (other.average != null) Objects.equal(this.customUnit, other.maximum) &&
return false; Objects.equal(this.maximum, other.maximum) &&
} else if (!average.equals(other.average)) Objects.equal(this.minimum, other.minimum) &&
return false; Objects.equal(this.samples, other.samples) &&
if (customUnit == null) { Objects.equal(this.sum, other.sum) &&
if (other.customUnit != null) Objects.equal(this.timestamp, other.timestamp) &&
return false; Objects.equal(this.unit, other.unit);
} else if (!customUnit.equals(other.customUnit))
return false;
if (maximum == null) {
if (other.maximum != null)
return false;
} else if (!maximum.equals(other.maximum))
return false;
if (minimum == null) {
if (other.minimum != null)
return false;
} else if (!minimum.equals(other.minimum))
return false;
if (samples == null) {
if (other.samples != null)
return false;
} else if (!samples.equals(other.samples))
return false;
if (sum == null) {
if (other.sum != null)
return false;
} else if (!sum.equals(other.sum))
return false;
if (timestamp == null) {
if (other.timestamp != null)
return false;
} else if (!timestamp.equals(other.timestamp))
return false;
if (unit == null) {
if (other.unit != null)
return false;
} else if (!unit.equals(other.unit))
return false;
return true;
} }
@Override @Override
public String toString() { public String toString() {
return "[average=" + average + ", customUnit=" + customUnit + ", maximum=" + maximum + ", minimum=" + minimum return Objects.toStringHelper(this)
+ ", samples=" + samples + ", sum=" + sum + ", timestamp=" + timestamp + ", unit=" + unit + "]"; .add("timestamp", timestamp)
.add("customUnit", customUnit)
.add("maximum", maximum)
.add("minimum", minimum)
.add("average", average)
.add("sum", sum)
.add("samples", samples)
.add("unit", unit).toString();
} }
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.cloudwatch.domain; package org.jclouds.cloudwatch.domain;
import com.google.common.base.Objects;
/** /**
* @see <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_Dimension.html" /> * @see <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_Dimension.html" />
* *
@ -47,6 +49,14 @@ public class Dimension {
return value; return value;
} }
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), name, value);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -59,17 +69,8 @@ public class Dimension {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
Dimension other = (Dimension)obj; Dimension other = (Dimension)obj;
if (name == null) { return Objects.equal(this.name, other.name) &&
if (other.name != null) Objects.equal(this.value, other.value);
return false;
} else if (!name.equals(other.name))
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
} }
/** /**
@ -77,7 +78,9 @@ public class Dimension {
*/ */
@Override @Override
public String toString() { public String toString() {
return "[name=" + name + ", value=" + value + "]"; return Objects.toStringHelper(this)
.add("name", name)
.add("value", value).toString();
} }
} }

View File

@ -18,10 +18,10 @@
*/ */
package org.jclouds.cloudwatch.domain; package org.jclouds.cloudwatch.domain;
import com.google.common.base.Objects;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
/** /**
@ -61,6 +61,14 @@ public class GetMetricStatisticsResponse {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), datapoints, label);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;
@ -69,17 +77,8 @@ public class GetMetricStatisticsResponse {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
GetMetricStatisticsResponse other = (GetMetricStatisticsResponse)obj; GetMetricStatisticsResponse other = (GetMetricStatisticsResponse)obj;
if (datapoints == null) { return Objects.equal(this.datapoints, other.datapoints) &&
if (other.datapoints != null) Objects.equal(this.label, other.label);
return false;
} else if (!datapoints.equals(other.datapoints))
return false;
if (label == null) {
if (other.label != null)
return false;
} else if (!label.equals(other.label))
return false;
return true;
} }
/** /**
@ -87,25 +86,9 @@ public class GetMetricStatisticsResponse {
*/ */
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); return Objects.toStringHelper(this)
.add("label", label)
builder.append("[label=") .add("datapoints", datapoints).toString();
.append(label)
.append(", datapoints=[");
Iterator<Datapoint> iterator = datapoints.iterator();
while (iterator.hasNext()) {
builder.append(iterator.next());
if (iterator.hasNext()) {
builder.append(", ");
}
}
builder.append("]]");
return builder.toString();
} }
} }

View File

@ -18,10 +18,10 @@
*/ */
package org.jclouds.cloudwatch.domain; package org.jclouds.cloudwatch.domain;
import com.google.common.base.Objects;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
/** /**
@ -63,6 +63,14 @@ public class ListMetricsResponse {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), metrics, nextToken);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;
@ -71,17 +79,8 @@ public class ListMetricsResponse {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
ListMetricsResponse other = (ListMetricsResponse)obj; ListMetricsResponse other = (ListMetricsResponse)obj;
if (metrics == null) { return Objects.equal(this.metrics, other.metrics) &&
if (other.metrics != null) Objects.equal(this.nextToken, other.nextToken);
return false;
} else if (!metrics.equals(other.metrics))
return false;
if (nextToken == null) {
if (other.nextToken != null)
return false;
} else if (!nextToken.equals(other.nextToken))
return false;
return true;
} }
/** /**
@ -89,27 +88,9 @@ public class ListMetricsResponse {
*/ */
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); return Objects.toStringHelper(this)
.add("metrics", metrics)
builder.append("[metrics=["); .add("nextToken", nextToken).toString();
Iterator<Metric> iterator = metrics.iterator();
while (iterator.hasNext()) {
builder.append(iterator.next());
if (iterator.hasNext()) {
builder.append(", ");
}
}
builder.append("]");
builder.append(", nextToken=")
.append(nextToken)
.append("]");
return builder.toString();
} }
} }

View File

@ -18,10 +18,10 @@
*/ */
package org.jclouds.cloudwatch.domain; package org.jclouds.cloudwatch.domain;
import com.google.common.base.Objects;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
/** /**
@ -73,30 +73,8 @@ public class Metric {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public String toString() { public int hashCode() {
StringBuilder builder = new StringBuilder(); return Objects.hashCode(super.hashCode(), dimensions, metricName, namespace);
builder.append("[metricName=")
.append(metricName)
.append(", namespace=")
.append(namespace);
builder.append(", dimensions=[");
Iterator<Dimension> iterator = dimensions.iterator();
while (iterator.hasNext()) {
builder.append(iterator.next());
if (iterator.hasNext()) {
builder.append(", ");
}
}
builder.append("]]");
return builder.toString();
} }
/** /**
@ -111,22 +89,20 @@ public class Metric {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
Metric other = (Metric)obj; Metric other = (Metric)obj;
if (metricName == null) { return Objects.equal(this.dimensions, other.dimensions) &&
if (other.metricName != null) Objects.equal(this.metricName, other.metricName) &&
return false; Objects.equal(this.namespace, other.namespace);
} else if (!metricName.equals(other.metricName)) }
return false;
if (namespace == null) { /**
if (other.namespace != null) * {@inheritDoc}
return false; */
} else if (!namespace.equals(other.namespace)) @Override
return false; public String toString() {
if (dimensions == null) { return Objects.toStringHelper(this)
if (other.dimensions != null) .add("namespace", namespace)
return false; .add("metricName", metricName)
} else if (!dimensions.equals(other.dimensions)) .add("dimension", dimensions).toString();
return false;
return true;
} }
} }

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.cloudwatch.options; package org.jclouds.cloudwatch.options;
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.jclouds.cloudwatch.domain.Dimension; import org.jclouds.cloudwatch.domain.Dimension;
@ -38,6 +39,7 @@ import java.util.Set;
* *
* @author Jeremy Whitlock * @author Jeremy Whitlock
*/ */
@Beta
public class GetMetricStatisticsOptionsV2 extends BaseHttpRequestOptions { public class GetMetricStatisticsOptionsV2 extends BaseHttpRequestOptions {
private static final DateService dateService = new SimpleDateFormatDateService(); private static final DateService dateService = new SimpleDateFormatDateService();