1 package org.kuali.common.dns.model; 2 3 import static com.google.common.base.Optional.absent; 4 import static org.kuali.common.dns.model.DnsRecordType.CNAME; 5 6 import org.kuali.common.core.build.ValidatingBuilder; 7 import org.kuali.common.core.validate.annotation.IdiotProofImmutable; 8 9 import com.google.common.base.Optional; 10 11 @IdiotProofImmutable 12 public final class DnsRecordSearchCriteria { 13 14 private final Optional<String> nameContains; 15 private final Optional<DnsRecordType> type; 16 private final Optional<String> valueContains; 17 18 private DnsRecordSearchCriteria(Builder builder) { 19 this.nameContains = builder.nameContains; 20 this.type = builder.type; 21 this.valueContains = builder.valueContains; 22 } 23 24 public static DnsRecordSearchCriteria allCNAMERecords() { 25 return newDnsRecordSearchCriteria(CNAME); 26 } 27 28 public static DnsRecordSearchCriteria newDnsRecordSearchCriteria(DnsRecordType type) { 29 return builder().type(type).build(); 30 } 31 32 public static DnsRecordSearchCriteria newDnsRecordSearchCriteria() { 33 return builder().build(); 34 } 35 36 public static Builder builder() { 37 return new Builder(); 38 } 39 40 public static class Builder extends ValidatingBuilder<DnsRecordSearchCriteria> { 41 42 private Optional<String> nameContains = absent(); 43 private Optional<DnsRecordType> type = absent(); 44 private Optional<String> valueContains = absent(); 45 46 public Builder nameContains(Optional<String> nameContains) { 47 this.nameContains = nameContains; 48 return this; 49 } 50 51 public Builder type(Optional<DnsRecordType> type) { 52 this.type = type; 53 return this; 54 } 55 56 public Builder type(DnsRecordType type) { 57 return type(Optional.of(type)); 58 } 59 60 public Builder valueContains(Optional<String> valueContains) { 61 this.valueContains = valueContains; 62 return this; 63 } 64 65 @Override 66 public DnsRecordSearchCriteria build() { 67 return validate(new DnsRecordSearchCriteria(this)); 68 } 69 70 } 71 72 public Optional<String> getNameContains() { 73 return nameContains; 74 } 75 76 public Optional<DnsRecordType> getType() { 77 return type; 78 } 79 80 public Optional<String> getValueContains() { 81 return valueContains; 82 } 83 84 }