2020
2121import com .google .gcloud .Page ;
2222
23- import java .io .Serializable ;
23+ import java .util .List ;
24+ import java .util .Objects ;
2425
2526/**
2627 * A Google Cloud DNS Zone object.
3334 * @see <a href="https://cloud.google.com/dns/zones/">Google Cloud DNS managed zone
3435 * documentation</a>
3536 */
36- public class Zone implements Serializable {
37+ public class Zone extends ZoneInfo {
3738
38- // TODO(mderka) Zone and zoneInfo to be merged. Opened issue #605.
39+ private static final long serialVersionUID = 564454483894599281L ;
40+ private transient Dns dns ;
3941
40- private static final long serialVersionUID = 6847890192129375500L ;
41- private final ZoneInfo zoneInfo ;
42- private final Dns dns ;
42+ /**
43+ * Builder for {@code Zone}.
44+ */
45+ public static class Builder extends ZoneInfo .Builder {
46+ private final Dns dns ;
47+ private final ZoneInfo .BuilderImpl infoBuilder ;
48+
49+ private Builder (Zone zone ) {
50+ this .dns = zone .dns ;
51+ this .infoBuilder = new ZoneInfo .BuilderImpl (zone );
52+ }
53+
54+ @ Override
55+ public Builder name (String name ) {
56+ infoBuilder .name (name );
57+ return this ;
58+ }
59+
60+ @ Override
61+ Builder id (String id ) {
62+ infoBuilder .id (id );
63+ return this ;
64+ }
65+
66+ @ Override
67+ Builder creationTimeMillis (long creationTimeMillis ) {
68+ infoBuilder .creationTimeMillis (creationTimeMillis );
69+ return this ;
70+ }
71+
72+ @ Override
73+ public Builder dnsName (String dnsName ) {
74+ infoBuilder .dnsName (dnsName );
75+ return this ;
76+ }
77+
78+ @ Override
79+ public Builder description (String description ) {
80+ infoBuilder .description (description );
81+ return this ;
82+ }
83+
84+ @ Override
85+ public Builder nameServerSet (String nameServerSet ) {
86+ infoBuilder .nameServerSet (nameServerSet );
87+ return this ;
88+ }
89+
90+ @ Override
91+ Builder nameServers (List <String > nameServers ) {
92+ infoBuilder .nameServers (nameServers ); // infoBuilder makes a copy
93+ return this ;
94+ }
95+
96+ @ Override
97+ public Zone build () {
98+ return new Zone (dns , infoBuilder );
99+ }
100+ }
101+
102+ Zone (Dns dns , ZoneInfo .BuilderImpl infoBuilder ) {
103+ super (infoBuilder );
104+ this .dns = dns ;
105+ }
106+
107+ @ Override
108+ public Builder toBuilder () {
109+ return new Builder (this );
110+ }
43111
44112 /**
45113 * Constructs a {@code Zone} object that contains the given {@code zoneInfo}.
46114 */
47115 public Zone (Dns dns , ZoneInfo zoneInfo ) {
48- this . zoneInfo = checkNotNull (zoneInfo );
49- this .dns = checkNotNull ( dns ) ;
116+ super ( new BuilderImpl (zoneInfo ) );
117+ this .dns = dns ;
50118 }
51119
52120 /**
@@ -61,8 +129,7 @@ public Zone(Dns dns, ZoneInfo zoneInfo) {
61129 public static Zone get (Dns dnsService , String zoneName , Dns .ZoneOption ... options ) {
62130 checkNotNull (zoneName );
63131 checkNotNull (dnsService );
64- ZoneInfo zoneInfo = dnsService .getZone (zoneName , options );
65- return zoneInfo == null ? null : new Zone (dnsService , zoneInfo );
132+ return dnsService .getZone (zoneName , options );
66133 }
67134
68135 /**
@@ -73,7 +140,7 @@ public static Zone get(Dns dnsService, String zoneName, Dns.ZoneOption... option
73140 * @throws DnsException upon failure
74141 */
75142 public Zone reload (Dns .ZoneOption ... options ) {
76- return Zone . get ( dns , zoneInfo . name (), options );
143+ return dns . getZone ( name (), options );
77144 }
78145
79146 /**
@@ -83,7 +150,7 @@ public Zone reload(Dns.ZoneOption... options) {
83150 * @throws DnsException upon failure
84151 */
85152 public boolean delete () {
86- return dns .delete (zoneInfo . name ());
153+ return dns .delete (name ());
87154 }
88155
89156 /**
@@ -94,7 +161,7 @@ public boolean delete() {
94161 * @throws DnsException upon failure or if the zone is not found
95162 */
96163 public Page <DnsRecord > listDnsRecords (Dns .DnsRecordListOption ... options ) {
97- return dns .listDnsRecords (zoneInfo . name (), options );
164+ return dns .listDnsRecords (name (), options );
98165 }
99166
100167 /**
@@ -108,7 +175,7 @@ public Page<DnsRecord> listDnsRecords(Dns.DnsRecordListOption... options) {
108175 public ChangeRequest applyChangeRequest (ChangeRequest changeRequest ,
109176 Dns .ChangeRequestOption ... options ) {
110177 checkNotNull (changeRequest );
111- return dns .applyChangeRequest (zoneInfo . name (), changeRequest , options );
178+ return dns .applyChangeRequest (name (), changeRequest , options );
112179 }
113180
114181 /**
@@ -124,7 +191,7 @@ public ChangeRequest applyChangeRequest(ChangeRequest changeRequest,
124191 public ChangeRequest getChangeRequest (String changeRequestId ,
125192 Dns .ChangeRequestOption ... options ) {
126193 checkNotNull (changeRequestId );
127- return dns .getChangeRequest (zoneInfo . name (), changeRequestId , options );
194+ return dns .getChangeRequest (name (), changeRequestId , options );
128195 }
129196
130197 /**
@@ -136,14 +203,7 @@ public ChangeRequest getChangeRequest(String changeRequestId,
136203 * @throws DnsException upon failure or if the zone is not found
137204 */
138205 public Page <ChangeRequest > listChangeRequests (Dns .ChangeRequestListOption ... options ) {
139- return dns .listChangeRequests (zoneInfo .name (), options );
140- }
141-
142- /**
143- * Returns the {@link ZoneInfo} object containing information about this zone.
144- */
145- public ZoneInfo info () {
146- return zoneInfo ;
206+ return dns .listChangeRequests (name (), options );
147207 }
148208
149209 /**
@@ -152,4 +212,19 @@ public ZoneInfo info() {
152212 public Dns dns () {
153213 return this .dns ;
154214 }
215+
216+ @ Override
217+ public boolean equals (Object obj ) {
218+ return obj instanceof Zone && Objects .equals (toPb (), ((Zone ) obj ).toPb ());
219+ }
220+
221+ @ Override
222+ public int hashCode () {
223+ return super .hashCode ();
224+ }
225+
226+ static Zone fromPb (Dns dns , com .google .api .services .dns .model .ManagedZone zone ) {
227+ ZoneInfo info = ZoneInfo .fromPb (zone );
228+ return new Zone (dns , info );
229+ }
155230}
0 commit comments