2424import com .google .common .collect .Lists ;
2525
2626import java .io .Serializable ;
27-
2827import java .util .LinkedList ;
2928import java .util .List ;
3029import java .util .Objects ;
3130
3231/**
33- * A class that represents Google Cloud DNS record set.
32+ * A class that represents a Google Cloud DNS record set.
3433 *
35- * <p>A DnsRecord is the unit of data that will be returned by the DNS servers upon a DNS request
36- * for a specific domain. The DnsRecord holds the current state of the DNS records that make up a
37- * managed zone. You can read the records but you do not modify them directly. Rather, you edit
38- * the records in a managed zone by creating a {@link ChangeRequest} .
34+ * <p>A {@code DnsRecord} is the unit of data that will be returned by the DNS servers upon a DNS
35+ * request for a specific domain. The {@code DnsRecord} holds the current state of the DNS records
36+ * that make up a managed zone. You can read the records but you do not modify them directly.
37+ * Rather, you edit the records in a managed zone by creating a ChangeRequest.
3938 *
4039 * @see <a href="https://cloud.google.com/dns/api/v1/resourceRecordSets">Google Cloud DNS
4140 * documentation</a>
@@ -117,8 +116,8 @@ private Builder() {
117116 }
118117
119118 /**
120- * Creates a builder and pre-populates attributes with the values from the provided DnsRecord
121- * instance.
119+ * Creates a builder and pre-populates attributes with the values from the provided {@code
120+ * DnsRecord} instance.
122121 */
123122 private Builder (DnsRecord record ) {
124123 this .name = record .name ;
@@ -142,15 +141,15 @@ public Builder addRecord(String record) {
142141 /**
143142 * Removes a record from the set. An exact match is required.
144143 */
145- public Builder removerRecord (String record ) {
144+ public Builder removeRecord (String record ) {
146145 this .rrdatas .remove (checkNotNull (record ));
147146 return this ;
148147 }
149148
150149 /**
151150 * Removes a record on the given index from the set.
152151 */
153- public Builder removerRecord (int index ) {
152+ public Builder removeRecord (int index ) {
154153 checkArgument (index >= 0 && index < this .rrdatas .size (), "The index is out of bounds. An " +
155154 "integer between 0 and " + (this .rrdatas .size () - 1 ) + " is required. The provided " +
156155 "value was " + index + "." );
@@ -225,10 +224,10 @@ public Builder toBuilder() {
225224 }
226225
227226 /**
228- * Creates an empty builder.
227+ * Creates a builder for {@code DnsRecord} with mandatorily set name and type of the record .
229228 */
230- public static Builder builder () {
231- return new Builder ();
229+ public static Builder builder (String name , DnsRecordType type ) {
230+ return new Builder (). name ( name ). type ( type ) ;
232231 }
233232
234233 /**
@@ -279,6 +278,17 @@ com.google.api.services.dns.model.ResourceRecordSet toPb() {
279278 return pb ;
280279 }
281280
281+ static DnsRecord fromPb (com .google .api .services .dns .model .ResourceRecordSet pb ) {
282+ Builder b = builder (pb .getName (), DnsRecordType .valueOf (pb .getType ()));
283+ if (pb .getRrdatas () != null ) {
284+ b .records (pb .getRrdatas ());
285+ }
286+ if (pb .getTtl () != null ) {
287+ b .ttl (pb .getTtl ());
288+ }
289+ return b .build ();
290+ }
291+
282292 @ Override
283293 public String toString () {
284294 return MoreObjects .toStringHelper (this )
@@ -288,5 +298,4 @@ public String toString() {
288298 .add ("type" , type ())
289299 .toString ();
290300 }
291-
292301}
0 commit comments