com.spotify.docker.client.messages.NetworkSettings Maven / Gradle / Ivy
/*-
* -\-\-
* docker-client
* --
* Copyright (C) 2016 Spotify AB
* --
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* -/-/-
*/
package com.spotify.docker.client.messages;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE)
public class NetworkSettings {
@JsonProperty("IPAddress")
private String ipAddress;
@JsonProperty("IPPrefixLen")
private Integer ipPrefixLen;
@JsonProperty("Gateway")
private String gateway;
@JsonProperty("Bridge")
private String bridge;
@JsonProperty("PortMapping")
private ImmutableMap> portMapping;
@JsonProperty("Ports")
private Map> ports;
@JsonProperty("MacAddress")
private String macAddress;
@JsonProperty("Networks")
private ImmutableMap networks;
private NetworkSettings(final Builder builder) {
this.ipAddress = builder.ipAddress;
this.ipPrefixLen = builder.ipPrefixLen;
this.gateway = builder.gateway;
this.bridge = builder.bridge;
this.portMapping = builder.portMapping;
this.ports = builder.ports;
this.macAddress = builder.macAddress;
this.networks = builder.networks;
}
@SuppressWarnings("unused")
public NetworkSettings() {
}
public String ipAddress() {
return ipAddress;
}
public Integer ipPrefixLen() {
return ipPrefixLen;
}
public String gateway() {
return gateway;
}
public String bridge() {
return bridge;
}
public Map> portMapping() {
return portMapping;
}
public Map> ports() {
return (ports == null) ? null : Collections.unmodifiableMap(ports);
}
public String macAddress() {
return macAddress;
}
public Map networks() {
return (networks == null) ? null : Collections.unmodifiableMap(networks);
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final NetworkSettings that = (NetworkSettings) obj;
return Objects.equals(this.ipAddress, that.ipAddress)
&& Objects.equals(this.ipPrefixLen, that.ipPrefixLen)
&& Objects.equals(this.gateway, that.gateway)
&& Objects.equals(this.bridge, that.bridge)
&& Objects.equals(this.portMapping, that.portMapping)
&& Objects.equals(this.ports, that.ports)
&& Objects.equals(this.macAddress, that.macAddress)
&& Objects.equals(this.networks, that.networks);
}
@Override
public int hashCode() {
return Objects.hash(ipAddress, ipPrefixLen, gateway, bridge, portMapping, ports, macAddress,
networks);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("ipAddress", ipAddress)
.add("ipPrefixLen", ipPrefixLen)
.add("gateway", gateway)
.add("bridge", bridge)
.add("portMapping", portMapping)
.add("ports", ports)
.add("macAddress", macAddress)
.add("networks", networks)
.toString();
}
public Builder toBuilder() {
return new Builder(this);
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String ipAddress;
private Integer ipPrefixLen;
private String gateway;
private String bridge;
private ImmutableMap> portMapping;
private Map> ports;
private String macAddress;
private ImmutableMap networks;
private Builder() {
}
private Builder(final NetworkSettings networkSettings) {
this.ipAddress = networkSettings.ipAddress;
this.ipPrefixLen = networkSettings.ipPrefixLen;
this.gateway = networkSettings.gateway;
this.bridge = networkSettings.bridge;
this.portMapping = networkSettings.portMapping;
this.ports = networkSettings.ports;
this.macAddress = networkSettings.macAddress;
this.networks = networkSettings.networks;
}
public Builder ipAddress(final String ipAddress) {
this.ipAddress = ipAddress;
return this;
}
public Builder ipPrefixLen(final Integer ipPrefixLen) {
this.ipPrefixLen = ipPrefixLen;
return this;
}
public Builder gateway(final String gateway) {
this.gateway = gateway;
return this;
}
public Builder bridge(final String bridge) {
this.bridge = bridge;
return this;
}
public Builder portMapping(final Map> portMapping) {
final ImmutableMap.Builder> builder = ImmutableMap.builder();
for (final Map.Entry> entry : portMapping.entrySet()) {
builder.put(entry.getKey(), ImmutableMap.copyOf(entry.getValue()));
}
this.portMapping = builder.build();
return this;
}
public Builder ports(final Map> ports) {
this.ports = (ports == null) ? null : Maps.newHashMap(ports);
return this;
}
public Builder macAddress(final String macAddress) {
this.macAddress = macAddress;
return this;
}
public Builder networks(final Map networks) {
if (networks != null) {
this.networks = ImmutableMap.copyOf(networks);
}
return this;
}
public NetworkSettings build() {
return new NetworkSettings(this);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy