| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.trmk.vcloud_0_8.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | |
| 25 | /** |
| 26 | * @author Adrian Cole |
| 27 | */ |
| 28 | public class NetworkExtendedInfo implements Comparable<NetworkExtendedInfo> { |
| 29 | public enum Type { |
| 30 | INTERNAL, DMZ, UNRECOGNIZED; |
| 31 | public static Type fromValue(String type) { |
| 32 | try { |
| 33 | return valueOf(checkNotNull(type, "type").toUpperCase()); |
| 34 | } catch (IllegalArgumentException e) { |
| 35 | return UNRECOGNIZED; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | } |
| 40 | |
| 41 | private final String id; |
| 42 | private final URI href; |
| 43 | private final String name; |
| 44 | private final String rnatAddress; |
| 45 | private final String address; |
| 46 | private final String broadcastAddress; |
| 47 | private final String gatewayAddress; |
| 48 | private final Type networkType; |
| 49 | private final String vlan; |
| 50 | private final String friendlyName; |
| 51 | |
| 52 | public NetworkExtendedInfo(String id, URI href, String name, String rnatAddress, String address, |
| 53 | String broadcastAddress, String gatewayAddress, Type networkType, String vlan, String friendlyName) { |
| 54 | this.id = id; |
| 55 | this.href = href; |
| 56 | this.name = name; |
| 57 | this.rnatAddress = rnatAddress; |
| 58 | this.address = address; |
| 59 | this.broadcastAddress = broadcastAddress; |
| 60 | this.gatewayAddress = gatewayAddress; |
| 61 | this.networkType = networkType; |
| 62 | this.vlan = vlan; |
| 63 | this.friendlyName = friendlyName; |
| 64 | } |
| 65 | |
| 66 | public int compareTo(NetworkExtendedInfo that) { |
| 67 | return (this == that) ? 0 : getHref().compareTo(that.getHref()); |
| 68 | } |
| 69 | |
| 70 | public String getId() { |
| 71 | return id; |
| 72 | } |
| 73 | |
| 74 | public URI getHref() { |
| 75 | return href; |
| 76 | } |
| 77 | |
| 78 | public String getName() { |
| 79 | return name; |
| 80 | } |
| 81 | |
| 82 | public String getRnatAddress() { |
| 83 | return rnatAddress; |
| 84 | } |
| 85 | |
| 86 | public String getAddress() { |
| 87 | return address; |
| 88 | } |
| 89 | |
| 90 | public String getBroadcastAddress() { |
| 91 | return broadcastAddress; |
| 92 | } |
| 93 | |
| 94 | public String getGatewayAddress() { |
| 95 | return gatewayAddress; |
| 96 | } |
| 97 | |
| 98 | public Type getNetworkType() { |
| 99 | return networkType; |
| 100 | } |
| 101 | |
| 102 | public String getVlan() { |
| 103 | return vlan; |
| 104 | } |
| 105 | |
| 106 | public String getFriendlyName() { |
| 107 | return friendlyName; |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public int hashCode() { |
| 112 | final int prime = 31; |
| 113 | int result = 1; |
| 114 | result = prime * result + ((address == null) ? 0 : address.hashCode()); |
| 115 | result = prime * result + ((broadcastAddress == null) ? 0 : broadcastAddress.hashCode()); |
| 116 | result = prime * result + ((friendlyName == null) ? 0 : friendlyName.hashCode()); |
| 117 | result = prime * result + ((gatewayAddress == null) ? 0 : gatewayAddress.hashCode()); |
| 118 | result = prime * result + ((href == null) ? 0 : href.hashCode()); |
| 119 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| 120 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 121 | result = prime * result + ((networkType == null) ? 0 : networkType.hashCode()); |
| 122 | result = prime * result + ((rnatAddress == null) ? 0 : rnatAddress.hashCode()); |
| 123 | result = prime * result + ((vlan == null) ? 0 : vlan.hashCode()); |
| 124 | return result; |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public boolean equals(Object obj) { |
| 129 | if (this == obj) |
| 130 | return true; |
| 131 | if (obj == null) |
| 132 | return false; |
| 133 | if (getClass() != obj.getClass()) |
| 134 | return false; |
| 135 | NetworkExtendedInfo other = (NetworkExtendedInfo) obj; |
| 136 | if (address == null) { |
| 137 | if (other.address != null) |
| 138 | return false; |
| 139 | } else if (!address.equals(other.address)) |
| 140 | return false; |
| 141 | if (broadcastAddress == null) { |
| 142 | if (other.broadcastAddress != null) |
| 143 | return false; |
| 144 | } else if (!broadcastAddress.equals(other.broadcastAddress)) |
| 145 | return false; |
| 146 | if (friendlyName == null) { |
| 147 | if (other.friendlyName != null) |
| 148 | return false; |
| 149 | } else if (!friendlyName.equals(other.friendlyName)) |
| 150 | return false; |
| 151 | if (gatewayAddress == null) { |
| 152 | if (other.gatewayAddress != null) |
| 153 | return false; |
| 154 | } else if (!gatewayAddress.equals(other.gatewayAddress)) |
| 155 | return false; |
| 156 | if (href == null) { |
| 157 | if (other.href != null) |
| 158 | return false; |
| 159 | } else if (!href.equals(other.href)) |
| 160 | return false; |
| 161 | if (id == null) { |
| 162 | if (other.id != null) |
| 163 | return false; |
| 164 | } else if (!id.equals(other.id)) |
| 165 | return false; |
| 166 | if (name == null) { |
| 167 | if (other.name != null) |
| 168 | return false; |
| 169 | } else if (!name.equals(other.name)) |
| 170 | return false; |
| 171 | if (networkType == null) { |
| 172 | if (other.networkType != null) |
| 173 | return false; |
| 174 | } else if (!networkType.equals(other.networkType)) |
| 175 | return false; |
| 176 | if (rnatAddress == null) { |
| 177 | if (other.rnatAddress != null) |
| 178 | return false; |
| 179 | } else if (!rnatAddress.equals(other.rnatAddress)) |
| 180 | return false; |
| 181 | if (vlan == null) { |
| 182 | if (other.vlan != null) |
| 183 | return false; |
| 184 | } else if (!vlan.equals(other.vlan)) |
| 185 | return false; |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public String toString() { |
| 191 | return "[address=" + address + ", broadcastAddress=" + broadcastAddress + ", friendlyName=" + friendlyName |
| 192 | + ", gatewayAddress=" + gatewayAddress + ", href=" + href + ", id=" + id + ", name=" + name |
| 193 | + ", networkType=" + networkType + ", rnatAddress=" + rnatAddress + ", vlan=" + vlan + "]"; |
| 194 | } |
| 195 | } |