diff options
Diffstat (limited to 'config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java')
-rw-r--r-- | config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java b/config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java index 90ac3651bb2..7702edccfd4 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java @@ -4,14 +4,17 @@ package com.yahoo.config.provision; import java.util.Collection; import java.util.List; +import java.util.Objects; /** * Models an immutable list of network port allocations + * * @author arnej */ public class NetworkPorts { public static class Allocation { + public final int port; public final String serviceType; public final String configId; @@ -19,10 +22,11 @@ public class NetworkPorts { public Allocation(int port, String serviceType, String configId, String portSuffix) { this.port = port; - this.serviceType = serviceType; - this.configId = configId; - this.portSuffix = portSuffix; + this.serviceType = Objects.requireNonNull(serviceType, "servceType cannot be null"); + this.configId = Objects.requireNonNull(configId, "configId cannot be null"); + this.portSuffix = Objects.requireNonNull(portSuffix, "portSuffix cannot be null"); } + public String key() { StringBuilder buf = new StringBuilder(); buf.append("t=").append(serviceType); @@ -30,6 +34,8 @@ public class NetworkPorts { buf.append(" suf=").append(portSuffix); return buf.toString(); } + + @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append("[port=").append(port); @@ -39,17 +45,47 @@ public class NetworkPorts { buf.append("]"); return buf.toString(); } + + @Override + public int hashCode() { + return Objects.hash(port, serviceType, configId, portSuffix); + } + + @Override + public boolean equals(Object o) { + if (o == this) return true; + if ( ! (o instanceof Allocation)) return false; + Allocation other = (Allocation)o; + if (other.port != this.port) return false; + if ( ! other.serviceType.equals(this.serviceType)) return false; + if ( ! other.configId.equals(this.configId)) return false; + if ( ! other.portSuffix.equals(this.portSuffix)) return false; + return true; + } + } - private final List<Allocation> allocations; + private final List<Allocation> allocations; // immutable list public NetworkPorts(Collection<Allocation> allocations) { this.allocations = List.copyOf(allocations); } + /** Returns a read only collection of the port allocations of this */ public Collection<Allocation> allocations() { return this.allocations; } public int size() { return allocations.size(); } + + @Override + public int hashCode() { return allocations.hashCode(); } + + @Override + public boolean equals(Object other) { + if (other == this) return true; + if ( ! (other instanceof NetworkPorts)) return false; + return ((NetworkPorts)other).allocations.equals(this.allocations); + } + } |