diff options
author | Valerij Fredriksen <valerijf@yahooinc.com> | 2022-03-14 23:28:54 +0100 |
---|---|---|
committer | Valerij Fredriksen <valerijf@yahooinc.com> | 2022-03-14 23:30:06 +0100 |
commit | 7c4fe97357fb5b4782bc56d631b6d11d8ce78664 (patch) | |
tree | f29a0705c0f2b9e6892670f11dafb65d6cf0f516 /controller-api | |
parent | 9ad7ce1756ee6f5b3045b7f1aa0361d43ac6b80d (diff) |
Extend contact
Diffstat (limited to 'controller-api')
-rw-r--r-- | controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContacts.java | 52 |
1 files changed, 18 insertions, 34 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContacts.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContacts.java index 25e91fe0700..8573beefbab 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContacts.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TenantContacts.java @@ -14,9 +14,9 @@ import java.util.Optional; * @author ogronnesby */ public class TenantContacts { - private final List<Contact<?>> contacts; + private final List<? extends Contact> contacts; - public TenantContacts(List<Contact<?>> contacts) { + public TenantContacts(List<? extends Contact> contacts) { this.contacts = List.copyOf(contacts); } @@ -24,7 +24,7 @@ public class TenantContacts { return new TenantContacts(List.of()); } - public List<Contact<?>> all() { + public List<? extends Contact> all() { return contacts; } @@ -52,55 +52,39 @@ public class TenantContacts { '}'; } - public static class Contact<T> { - private final Type type; + public abstract static class Contact { private final List<Audience> audiences; - protected final T data; - public Contact(Type type, List<Audience> audiences, T data) { - this.type = type; - this.audiences = audiences; - this.data = data; + public Contact(List<Audience> audiences) { + this.audiences = List.copyOf(audiences); if (audiences.isEmpty()) throw new IllegalArgumentException("audience cannot be empty"); } - public Type type() { return type; } public List<Audience> audiences() { return audiences; } - public T data() { return data; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Contact<?> contact = (Contact<?>) o; - return type == contact.type && audiences.equals(contact.audiences) && data.equals(contact.data); - } - - @Override - public int hashCode() { - return Objects.hash(type, audiences, data); - } + public abstract Type type(); - @Override - public String toString() { - return "Contact{" + - "type=" + type + - ", audience=" + audiences + - ", data=" + data + - '}'; - } + public abstract boolean equals(Object o); + public abstract int hashCode(); + public abstract String toString(); } - public static class EmailContact { + public static class EmailContact extends Contact { private final String email; - public EmailContact(String email) { + public EmailContact(List<Audience> audiences, String email) { + super(audiences); this.email = email; } public String email() { return email; } @Override + public Type type() { + return Type.EMAIL; + } + + @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; |