Implement Comparable in GoGrid ErrorResponse

Gson collects errors in a TreeMap which requires a well-behaved
Comparable method.  This addresses a Java 7 GoGrid failure seen in
GridServerClientExpectTest.testGetServerCredentialsWhenNotFoundThrowsResourceNotFoundExceptionWithNiceMessage:

java.lang.ClassCastException: org.jclouds.gogrid.domain.internal.ErrorResponse cannot be cast to java.lang.Comparable
This commit is contained in:
Andrew Gaul 2012-11-03 14:38:33 -07:00 committed by Andrew Phillips
parent e7354c6f4a
commit 67b3f78838
1 changed files with 10 additions and 1 deletions

View File

@ -24,13 +24,14 @@ import java.beans.ConstructorProperties;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ComparisonChain;
/** /**
* Class ErrorResponse * Class ErrorResponse
* *
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
public class ErrorResponse { public class ErrorResponse implements Comparable<ErrorResponse> {
public static Builder<?> builder() { public static Builder<?> builder() {
return new ConcreteBuilder(); return new ConcreteBuilder();
@ -113,6 +114,14 @@ public class ErrorResponse {
&& Objects.equal(this.errorCode, that.errorCode); && Objects.equal(this.errorCode, that.errorCode);
} }
@Override
public int compareTo(ErrorResponse that) {
return ComparisonChain.start()
.compare(errorCode, that.errorCode)
.compare(message, that.message)
.result();
}
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper(this) return Objects.toStringHelper(this)
.add("message", message).add("errorCode", errorCode); .add("message", message).add("errorCode", errorCode);