diff options
author | Martin Polden <mpolden@mpolden.no> | 2022-09-14 13:06:42 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2022-09-14 13:06:42 +0200 |
commit | fc575b417879ea295993b5614b222185623554a7 (patch) | |
tree | f89e7238eec9e73ef8c4732f7a7c15329cf74ed4 | |
parent | d3299a9d515f6c10c1690e8d3b903bbf7ed3e9f7 (diff) |
Use record
3 files changed, 19 insertions, 67 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/Record.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/Record.java index 8c6decd6158..2f9312b2f89 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/Record.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/Record.java @@ -10,22 +10,20 @@ import java.util.Objects; * * @author mpolden */ -public class Record implements Comparable<Record> { +public record Record(Type type, + Duration ttl, + RecordName name, + RecordData data) implements Comparable<Record> { private static final Comparator<Record> comparator = Comparator.comparing(Record::type) .thenComparing(Record::name) .thenComparing(Record::data); - private final Type type; - private final Duration ttl; - private final RecordName name; - private final RecordData data; - - public Record(Type type, Duration ttl, RecordName name, RecordData data) { - this.type = Objects.requireNonNull(type, "type cannot be null"); - this.ttl = Objects.requireNonNull(ttl, "ttl cannot be null"); - this.name = Objects.requireNonNull(name, "name cannot be null"); - this.data = Objects.requireNonNull(data, "data cannot be null"); + public Record { + Objects.requireNonNull(type, "type cannot be null"); + Objects.requireNonNull(ttl, "ttl cannot be null"); + Objects.requireNonNull(name, "name cannot be null"); + Objects.requireNonNull(data, "data cannot be null"); } public Record(Type type, RecordName name, RecordData data) { @@ -74,22 +72,6 @@ public class Record implements Comparable<Record> { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Record record = (Record) o; - return type == record.type && - ttl.equals(record.ttl) && - name.equals(record.name) && - data.equals(record.data); - } - - @Override - public int hashCode() { - return Objects.hash(type, ttl, name, data); - } - - @Override public int compareTo(Record that) { return comparator.compare(this, that); } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordData.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordData.java index 90759d911dd..e2d142b10f8 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordData.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordData.java @@ -10,12 +10,10 @@ import java.util.Objects; * * @author mpolden */ -public class RecordData implements Comparable<RecordData> { +public record RecordData(String data) implements Comparable<RecordData> { - private final String data; - - private RecordData(String data) { - this.data = Objects.requireNonNull(data, "data cannot be null"); + public RecordData { + Objects.requireNonNull(data, "data cannot be null"); } public String asString() { @@ -23,19 +21,6 @@ public class RecordData implements Comparable<RecordData> { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RecordData that = (RecordData) o; - return Objects.equals(data, that.data); - } - - @Override - public int hashCode() { - return Objects.hash(data); - } - - @Override public String toString() { return data; } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordName.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordName.java index 72f0933896d..e2548a7f283 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordName.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/dns/RecordName.java @@ -8,12 +8,10 @@ import java.util.Objects; * * @author mpolden */ -public class RecordName implements Comparable<RecordName> { +public record RecordName(String name) implements Comparable<RecordName> { - private final String name; - - private RecordName(String name) { - this.name = Objects.requireNonNull(name, "name cannot be null"); + public RecordName { + Objects.requireNonNull(name, "name cannot be null"); } public String asString() { @@ -31,21 +29,13 @@ public class RecordName implements Comparable<RecordName> { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RecordName that = (RecordName) o; - return Objects.equals(name, that.name); - } - - @Override - public int hashCode() { - return Objects.hash(name); + public String toString() { + return name; } @Override - public String toString() { - return name; + public int compareTo(RecordName that) { + return this.name.compareTo(that.name); } public static RecordName from(String name) { @@ -56,9 +46,4 @@ public class RecordName implements Comparable<RecordName> { return from(name).asFqdn(); } - @Override - public int compareTo(RecordName that) { - return this.name.compareTo(that.name); - } - } |