From aeee6ceb31bf2946ba6770ec0ddf42af37628fb1 Mon Sep 17 00:00:00 2001 From: adriancole Date: Mon, 11 Mar 2013 14:55:10 -0700 Subject: [PATCH] dynect: replace usage of UnsignedInteger with int and fixed serialized form of rdata classes --- .../dynect/v3/config/DynECTParserModule.java | 12 -- .../dynect/v3/domain/CreateRecord.java | 23 ++-- .../org/jclouds/dynect/v3/domain/Record.java | 22 ++-- .../jclouds/dynect/v3/domain/SOARecord.java | 3 +- .../dynect/v3/domain/rdata/AAAAData.java | 17 +-- .../jclouds/dynect/v3/domain/rdata/AData.java | 16 ++- .../dynect/v3/domain/rdata/CNAMEData.java | 18 +-- .../dynect/v3/domain/rdata/MXData.java | 41 +++--- .../dynect/v3/domain/rdata/NSData.java | 18 +-- .../dynect/v3/domain/rdata/PTRData.java | 18 +-- .../dynect/v3/domain/rdata/SOAData.java | 118 ++++++++---------- .../dynect/v3/domain/rdata/SRVData.java | 86 ++++++------- .../dynect/v3/domain/rdata/TXTData.java | 18 +-- .../dynect/v3/features/RecordAsyncApi.java | 2 +- 14 files changed, 192 insertions(+), 220 deletions(-) diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java index 250a858c0a..9d52117038 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java @@ -26,12 +26,8 @@ import javax.inject.Singleton; import org.jclouds.dynect.v3.domain.SessionCredentials; import com.google.common.collect.ImmutableMap; -import com.google.common.primitives.UnsignedInteger; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.google.inject.AbstractModule; @@ -51,7 +47,6 @@ public class DynECTParserModule extends AbstractModule { public Map provideCustomAdapterBindings() { return new ImmutableMap.Builder() .put(SessionCredentials.class, new SessionCredentialsTypeAdapter()) - .put(UnsignedInteger.class, new UnsignedIntegerAdapter()) .build(); } @@ -64,11 +59,4 @@ public class DynECTParserModule extends AbstractModule { return metadataObject; } } - - private static class UnsignedIntegerAdapter implements JsonDeserializer { - public UnsignedInteger deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) - throws JsonParseException { - return UnsignedInteger.fromIntBits(jsonElement.getAsBigInteger().intValue()); - } - } } diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/CreateRecord.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/CreateRecord.java index 4f298a5c55..58081f728d 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/CreateRecord.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/CreateRecord.java @@ -20,12 +20,12 @@ package org.jclouds.dynect.v3.domain; import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.toStringHelper; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Map; import com.google.common.base.Objects; -import com.google.common.primitives.UnsignedInteger; /** * @author Adrian Cole @@ -34,13 +34,14 @@ public class CreateRecord> { private final String fqdn; private final String type; - private final UnsignedInteger ttl; + private final int ttl; private final D rdata; - private CreateRecord(String fqdn, String type, UnsignedInteger ttl, D rdata) { + private CreateRecord(String fqdn, String type, int ttl, D rdata) { this.fqdn = checkNotNull(fqdn, "fqdn"); this.type = checkNotNull(type, "type of %s", fqdn); - this.ttl = checkNotNull(ttl, "ttl of %s", fqdn); + checkArgument(ttl >= 0, "ttl of %s must be unsigned", fqdn); + this.ttl = ttl; this.rdata = checkNotNull(rdata, "rdata of %s", fqdn); } @@ -63,7 +64,7 @@ public class CreateRecord> { * * @see Record#getTTL() */ - public UnsignedInteger getTTL() { + public int getTTL() { return ttl; } @@ -106,7 +107,8 @@ public class CreateRecord> { public static class Builder> { protected String fqdn; protected String type; - protected UnsignedInteger ttl = UnsignedInteger.ZERO; + // default of zone is implied when ttl is set to zero + protected int ttl = 0; protected D rdata; /** @@ -128,18 +130,11 @@ public class CreateRecord> { /** * @see CreateRecord#getTTL() */ - public Builder ttl(UnsignedInteger ttl) { + public Builder ttl(int ttl) { this.ttl = ttl; return this; } - /** - * @see CreateRecord#getTTL() - */ - public Builder ttl(int ttl) { - return ttl(UnsignedInteger.fromIntBits(ttl)); - } - /** * @see CreateRecord#getRData() */ diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java index b68b7d4d28..438ae289f2 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java @@ -18,6 +18,7 @@ */ package org.jclouds.dynect.v3.domain; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; @@ -26,28 +27,28 @@ import java.util.Map; import javax.inject.Named; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.primitives.UnsignedInteger; /** * @author Adrian Cole */ public class Record> extends RecordId { - private final UnsignedInteger ttl; + private final int ttl; @Named("rdata") private final D rdata; @ConstructorProperties({ "zone", "fqdn", "record_type", "record_id", "ttl", "rdata" }) - protected Record(String zone, String fqdn, String type, long id, UnsignedInteger ttl, D rdata) { + protected Record(String zone, String fqdn, String type, long id, int ttl, D rdata) { super(zone, fqdn, type, id); - this.ttl = checkNotNull(ttl, "ttl of %s", id); + checkArgument(ttl >= 0, "ttl of %s must be unsigned", fqdn); + this.ttl = ttl; this.rdata = checkNotNull(rdata, "rdata of %s", id); } /** * The current ttl of the record or zero if default for the zone */ - public UnsignedInteger getTTL() { + public int getTTL() { return ttl; } @@ -74,24 +75,17 @@ public class Record> extends RecordId { public abstract static class Builder, B extends Builder> extends RecordId.Builder { - protected UnsignedInteger ttl; + protected int ttl = -1; protected D rdata; /** * @see Record#getTTL() */ - public B ttl(UnsignedInteger ttl) { + public B ttl(int ttl) { this.ttl = ttl; return self(); } - /** - * @see Record#getTTL() - */ - public B ttl(int ttl) { - return ttl(UnsignedInteger.fromIntBits(ttl)); - } - /** * @see Record#getRData() */ diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java index 9df446857d..ec8593a786 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java @@ -28,7 +28,6 @@ import org.jclouds.dynect.v3.domain.Zone.SerialStyle; import org.jclouds.dynect.v3.domain.rdata.SOAData; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.primitives.UnsignedInteger; /** * Start of Authority per RFC 1035 @@ -41,7 +40,7 @@ public final class SOARecord extends Record { private final SerialStyle serialStyle; @ConstructorProperties({ "zone", "fqdn", "record_type", "record_id", "ttl", "rdata", "serial_style" }) - private SOARecord(String zone, String fqdn, String type, long id, UnsignedInteger ttl, SOAData rdata, SerialStyle serialStyle) { + private SOARecord(String zone, String fqdn, String type, long id, int ttl, SOAData rdata, SerialStyle serialStyle) { super(zone, fqdn, type, id, ttl, rdata); this.serialStyle = checkNotNull(serialStyle, "serialStyle of %s", id); } diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java index 22f9a3dc6c..f297481453 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java @@ -40,22 +40,25 @@ import com.google.common.collect.ImmutableMap; * @see RFC 3596 */ public class AAAAData extends ForwardingMap { - private final ImmutableMap delegate; + private final String address; @ConstructorProperties("address") private AAAAData(String address) { - this.delegate = ImmutableMap. of("address", checkNotNull(address, "address")); - } - - protected Map delegate() { - return delegate; + this.address = checkNotNull(address, "address"); + this.delegate = ImmutableMap. of("address", address); } /** * a 128 bit IPv6 address */ public String getAddress() { - return get("address").toString(); + return address; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static AAAAData aaaa(String address) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java index 64deaa0afa..6ecd18d186 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java @@ -40,22 +40,26 @@ import com.google.common.collect.ImmutableMap; * @see RFC 1035 */ public class AData extends ForwardingMap { - private final ImmutableMap delegate; + + private final String address; @ConstructorProperties("address") private AData(String address) { + this.address = checkNotNull(address, "address"); this.delegate = ImmutableMap. of("address", checkNotNull(address, "address")); } - protected Map delegate() { - return delegate; - } - /** * a 32-bit internet address */ public String getAddress() { - return get("address").toString(); + return address; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static AData a(String address) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.java index be8c0eda8b..33709ecc0b 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.java @@ -40,15 +40,13 @@ import com.google.common.collect.ImmutableMap; * @see RFC 1035 */ public class CNAMEData extends ForwardingMap { - private final ImmutableMap delegate; + + private final String cname; @ConstructorProperties("cname") private CNAMEData(String cname) { - this.delegate = ImmutableMap. of("cname", checkNotNull(cname, "cname")); - } - - protected Map delegate() { - return delegate; + this.cname = checkNotNull(cname, "cname"); + this.delegate = ImmutableMap. of("cname", cname); } /** @@ -56,7 +54,13 @@ public class CNAMEData extends ForwardingMap { * The owner name is an alias. */ public String getCname() { - return get("cname").toString(); + return cname; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static CNAMEData cname(String cname) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java index c37f719a10..f6104a3353 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java @@ -18,6 +18,7 @@ */ package org.jclouds.dynect.v3.domain.rdata; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; @@ -25,7 +26,6 @@ import java.util.Map; import com.google.common.collect.ForwardingMap; import com.google.common.collect.ImmutableMap; -import com.google.common.primitives.UnsignedInteger; /** * Corresponds to the binary representation of the {@code MX} (Mail Exchange) @@ -43,24 +43,24 @@ import com.google.common.primitives.UnsignedInteger; */ public class MXData extends ForwardingMap { + private final int preference; + private final String exchange; + @ConstructorProperties({ "preference", "exchange" }) - private MXData(UnsignedInteger preference, String exchange) { - this.delegate = ImmutableMap. builder().put("preference", checkNotNull(preference, "preference")) - .put("exchange", checkNotNull(exchange, "exchange")).build(); - } - - private final ImmutableMap delegate; - - protected Map delegate() { - return delegate; + private MXData(int preference, String exchange) { + checkArgument(preference >= 0, "preference of %s must be unsigned", exchange); + this.preference = preference; + this.exchange = checkNotNull(exchange, "exchange"); + this.delegate = ImmutableMap. builder().put("preference", preference).put("exchange", exchange) + .build(); } /** * specifies the preference given to this RR among others at the same owner. * Lower values are preferred. */ - public UnsignedInteger getPreference() { - return UnsignedInteger.class.cast(get("preference")); + public int getPreference() { + return preference; } /** @@ -68,7 +68,13 @@ public class MXData extends ForwardingMap { * the owner name. */ public String getExchange() { - return String.class.cast(get("exchange")); + return exchange; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static MXData mx(int preference, String exchange) { @@ -84,20 +90,13 @@ public class MXData extends ForwardingMap { } public final static class Builder { - private UnsignedInteger preference; + private int preference = -1; private String exchange; /** * @see MXData#getPreference() */ public MXData.Builder preference(int preference) { - return preference(UnsignedInteger.fromIntBits(preference)); - } - - /** - * @see MXData#getPreference() - */ - public MXData.Builder preference(UnsignedInteger preference) { this.preference = preference; return this; } diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.java index f1752fec52..73e2c3415f 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.java @@ -40,15 +40,13 @@ import com.google.common.collect.ImmutableMap; * @see RFC 1035 */ public class NSData extends ForwardingMap { - private final ImmutableMap delegate; + + private final String nsdname; @ConstructorProperties("nsdname") private NSData(String nsdname) { - this.delegate = ImmutableMap. of("nsdname", checkNotNull(nsdname, "nsdname")); - } - - protected Map delegate() { - return delegate; + this.nsdname = checkNotNull(nsdname, "nsdname"); + this.delegate = ImmutableMap. of("nsdname", nsdname); } /** @@ -56,7 +54,13 @@ public class NSData extends ForwardingMap { * specified class and domain. */ public String getNsdname() { - return get("nsdname").toString(); + return nsdname; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static NSData ns(String nsdname) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java index 57d2e74826..2abdd2ea27 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java @@ -40,22 +40,26 @@ import com.google.common.collect.ImmutableMap; * @see RFC 1035 */ public class PTRData extends ForwardingMap { - private final ImmutableMap delegate; + + private final String ptrdname; @ConstructorProperties("ptrdname") private PTRData(String ptrdname) { - this.delegate = ImmutableMap. of("ptrdname", checkNotNull(ptrdname, "ptrdname")); - } - - protected Map delegate() { - return delegate; + this.ptrdname = checkNotNull(ptrdname, "ptrdname"); + this.delegate = ImmutableMap. of("ptrdname", ptrdname); } /** * domain-name which points to some location in the domain name space. */ public String getPtrdname() { - return get("ptrdname").toString(); + return ptrdname; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static PTRData ptr(String ptrdname) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java index e24ac92154..3a5dd30722 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java @@ -18,6 +18,7 @@ */ package org.jclouds.dynect.v3.domain.rdata; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; @@ -25,7 +26,6 @@ import java.util.Map; import com.google.common.collect.ForwardingMap; import com.google.common.collect.ImmutableMap; -import com.google.common.primitives.UnsignedInteger; /** * Corresponds to the binary representation of the {@code SOA} (Start of Authority) RData @@ -46,10 +46,29 @@ import com.google.common.primitives.UnsignedInteger; * @see RFC 1035 */ public class SOAData extends ForwardingMap { + private final String mname; + private final String rname; + private final int serial; + private final int refresh; + private final int retry; + private final int expire; + private final int minimum; @ConstructorProperties({ "mname", "rname", "serial", "refresh", "retry", "expire", "minimum" }) - private SOAData(String mname, String rname, UnsignedInteger serial, UnsignedInteger refresh, UnsignedInteger retry, - UnsignedInteger expire, UnsignedInteger minimum) { + private SOAData(String mname, String rname, int serial, int refresh, int retry, + int expire, int minimum) { + this.mname = checkNotNull(mname, "mname"); + this.rname = checkNotNull(rname, "rname of %s", mname); + checkArgument(serial >= 0, "serial of %s must be unsigned", mname); + this.serial = serial; + checkArgument(refresh >= 0, "refresh of %s must be unsigned", mname); + this.refresh = refresh; + checkArgument(retry >= 0, "retry of %s must be unsigned", mname); + this.retry = retry; + checkArgument(expire >= 0, "expire of %s must be unsigned", mname); + this.expire = expire; + checkArgument(minimum >= 0, "minimum of %s must be unsigned", mname); + this.minimum = minimum; this.delegate = ImmutableMap. builder() .put("mname", checkNotNull(mname, "mname")) .put("rname", checkNotNull(rname, "rname of %s", mname)) @@ -60,18 +79,12 @@ public class SOAData extends ForwardingMap { .put("minimum", checkNotNull(minimum, "minimum of %s", mname)).build(); } - private final ImmutableMap delegate; - - protected Map delegate() { - return delegate; - } - /** * domain-name of the name server that was the original or primary source of * data for this zone */ public String getMname() { - return String.class.cast(get("mname")); + return mname; } /** @@ -79,43 +92,49 @@ public class SOAData extends ForwardingMap { * zone. */ public String getRname() { - return String.class.cast(get("rname")); + return rname; } /** * version number of the original copy of the zone. */ - public UnsignedInteger getSerial() { - return UnsignedInteger.class.cast(get("serial")); + public int getSerial() { + return serial; } /** * time interval before the zone should be refreshed */ - public UnsignedInteger getRefresh() { - return UnsignedInteger.class.cast(get("refresh")); + public int getRefresh() { + return refresh; } /** * time interval that should elapse before a failed refresh should be retried */ - public UnsignedInteger getRetry() { - return UnsignedInteger.class.cast(get("retry")); + public int getRetry() { + return retry; } /** * time value that specifies the upper limit on the time interval that can * elapse before the zone is no longer authoritative. */ - public UnsignedInteger getExpire() { - return UnsignedInteger.class.cast(get("expire")); + public int getExpire() { + return expire; } /** * minimum TTL field that should be exported with any RR from this zone. */ - public UnsignedInteger getMinimum() { - return UnsignedInteger.class.cast(get("minimum")); + public int getMinimum() { + return minimum; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static SOAData.Builder builder() { @@ -129,11 +148,11 @@ public class SOAData extends ForwardingMap { public final static class Builder { private String mname; private String rname; - private UnsignedInteger serial; - private UnsignedInteger refresh; - private UnsignedInteger retry; - private UnsignedInteger expire; - private UnsignedInteger minimum; + private int serial = -1; + private int refresh = -1; + private int retry = -1; + private int expire = -1; + private int minimum = -1; /** * @see SOAData#getMname() @@ -151,26 +170,11 @@ public class SOAData extends ForwardingMap { return this; } - /** - * @see SOAData#getSerial() - */ - public SOAData.Builder serial(UnsignedInteger serial) { - this.serial = serial; - return this; - } - /** * @see SOAData#getSerial() */ public SOAData.Builder serial(int serial) { - return serial(UnsignedInteger.fromIntBits(serial)); - } - - /** - * @see SOAData#getRefresh() - */ - public SOAData.Builder refresh(UnsignedInteger refresh) { - this.refresh = refresh; + this.serial = serial; return this; } @@ -178,14 +182,7 @@ public class SOAData extends ForwardingMap { * @see SOAData#getRefresh() */ public SOAData.Builder refresh(int refresh) { - return refresh(UnsignedInteger.fromIntBits(refresh)); - } - - /** - * @see SOAData#getRetry() - */ - public SOAData.Builder retry(UnsignedInteger retry) { - this.retry = retry; + this.refresh = refresh; return this; } @@ -193,14 +190,7 @@ public class SOAData extends ForwardingMap { * @see SOAData#getRetry() */ public SOAData.Builder retry(int retry) { - return retry(UnsignedInteger.fromIntBits(retry)); - } - - /** - * @see SOAData#getExpire() - */ - public SOAData.Builder expire(UnsignedInteger expire) { - this.expire = expire; + this.retry = retry; return this; } @@ -208,14 +198,7 @@ public class SOAData extends ForwardingMap { * @see SOAData#getExpire() */ public SOAData.Builder expire(int expire) { - return expire(UnsignedInteger.fromIntBits(expire)); - } - - /** - * @see SOAData#getMinimum() - */ - public SOAData.Builder minimum(UnsignedInteger minimum) { - this.minimum = minimum; + this.expire = expire; return this; } @@ -223,7 +206,8 @@ public class SOAData extends ForwardingMap { * @see SOAData#getMinimum() */ public SOAData.Builder minimum(int minimum) { - return minimum(UnsignedInteger.fromIntBits(minimum)); + this.minimum = minimum; + return this; } public SOAData build() { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java index 6fd6758b92..ee963e5b3a 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java @@ -18,6 +18,7 @@ */ package org.jclouds.dynect.v3.domain.rdata; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; @@ -25,7 +26,6 @@ import java.util.Map; import com.google.common.collect.ForwardingMap; import com.google.common.collect.ImmutableMap; -import com.google.common.primitives.UnsignedInteger; /** * Corresponds to the binary representation of the {@code SRV} (Service) RData @@ -43,31 +43,36 @@ import com.google.common.primitives.UnsignedInteger; * @see RFC 2782 */ public class SRVData extends ForwardingMap { - + private final int priority; + private final int weight; + private final int port; + private final String target; + @ConstructorProperties({ "priority", "weight", "port", "target" }) - private SRVData(UnsignedInteger priority, UnsignedInteger weight, UnsignedInteger port, String target) { + private SRVData(int priority, int weight, int port, String target) { + checkArgument(checkNotNull(priority, "priority of %s", target).intValue() <= 0xFFFF, "priority must be 0-65535"); + this.priority = priority; + checkArgument(checkNotNull(weight, "weight of %s", target).intValue() <= 0xFFFF, "weight must be 0-65535"); + this.weight = weight; + checkArgument(checkNotNull(port, "port of %s", target).intValue() <= 0xFFFF, "port must be 0-65535"); + this.port = port; + this.target = checkNotNull(target, "target"); this.delegate = ImmutableMap. builder() - .put("priority", checkNotNull(priority, "priority of %s", target)) - .put("weight", checkNotNull(weight, "weight of %s", target)) - .put("port", checkNotNull(port, "port of %s", target)) - .put("target", checkNotNull(target, "target")) + .put("priority", priority) + .put("weight", weight) + .put("port", weight) + .put("target", weight) .build(); } - private final ImmutableMap delegate; - - protected Map delegate() { - return delegate; - } - /** * The priority of this target host. A client MUST attempt to contact the * target host with the lowest-numbered priority it can reach; target hosts * with the same priority SHOULD be tried in an order defined by the weight * field. */ - public UnsignedInteger getPriority() { - return UnsignedInteger.class.cast(get("priority")); + public int getPriority() { + return priority; } /** @@ -75,15 +80,15 @@ public class SRVData extends ForwardingMap { * priority. Larger weights SHOULD be given a proportionately higher * probability of being selected. */ - public UnsignedInteger getWeight() { - return UnsignedInteger.class.cast(get("weight")); + public int getWeight() { + return weight; } /** * The port on this target host of this service. */ - public UnsignedInteger getPort() { - return UnsignedInteger.class.cast(get("port")); + public int getPort() { + return port; } /** @@ -91,7 +96,13 @@ public class SRVData extends ForwardingMap { * records for this name, the name MUST NOT be an alias. */ public String getTarget() { - return String.class.cast(get("target")); + return target; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static SRVData.Builder builder() { @@ -103,31 +114,16 @@ public class SRVData extends ForwardingMap { } public final static class Builder { - private UnsignedInteger priority; - private UnsignedInteger weight; - private UnsignedInteger port; + private int priority = -1; + private int weight = -1; + private int port = -1; private String target; - /** - * @see SRVData#getPriority() - */ - public SRVData.Builder priority(UnsignedInteger priority) { - this.priority = priority; - return this; - } - /** * @see SRVData#getPriority() */ public SRVData.Builder priority(int priority) { - return priority(UnsignedInteger.fromIntBits(priority)); - } - - /** - * @see SRVData#getWeight() - */ - public SRVData.Builder weight(UnsignedInteger weight) { - this.weight = weight; + this.priority = priority; return this; } @@ -135,14 +131,7 @@ public class SRVData extends ForwardingMap { * @see SRVData#getWeight() */ public SRVData.Builder weight(int weight) { - return weight(UnsignedInteger.fromIntBits(weight)); - } - - /** - * @see SRVData#getPort() - */ - public SRVData.Builder port(UnsignedInteger port) { - this.port = port; + this.weight = weight; return this; } @@ -150,7 +139,8 @@ public class SRVData extends ForwardingMap { * @see SRVData#getPort() */ public SRVData.Builder port(int port) { - return port(UnsignedInteger.fromIntBits(port)); + this.port = port; + return this; } /** diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java index e20837906b..0113f41fc2 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java @@ -40,22 +40,26 @@ import com.google.common.collect.ImmutableMap; * @see RFC 1035 */ public class TXTData extends ForwardingMap { - private final ImmutableMap delegate; + + private final String txtdata; @ConstructorProperties("txtdata") private TXTData(String txtdata) { - this.delegate = ImmutableMap. of("txtdata", checkNotNull(txtdata, "txtdata")); - } - - protected Map delegate() { - return delegate; + this.txtdata = checkNotNull(txtdata, "txtdata"); + this.delegate = ImmutableMap. of("txtdata", txtdata); } /** * One or more character-strings. */ public String getTxtdata() { - return get("txtdata").toString(); + return txtdata; + } + + private final transient ImmutableMap delegate; + + protected Map delegate() { + return delegate; } public static TXTData txt(String txtdata) { diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java index 57e763460c..aa26198700 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java @@ -128,7 +128,7 @@ public interface RecordAsyncApi { .put("fqdn", in.getFQDN()).build()); return (R) request.toBuilder() .endpoint(path) - .payload(json.toJson(ImmutableMap.of("rdata", ImmutableMap.copyOf(in.getRData()), "ttl", in.getTTL().intValue()))).build(); + .payload(json.toJson(ImmutableMap.of("rdata", in.getRData(), "ttl", in.getTTL()))).build(); } }