/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IPForwardingRule.java

https://github.com/irshad84/jclouds · Java · 294 lines · 198 code · 33 blank · 63 comment · 51 complexity · 6a41f5d895ba012a4d52882bee267bf6 MD5 · raw file

  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.cloudstack.domain;
  20. import com.google.gson.annotations.SerializedName;
  21. /**
  22. *
  23. * @author Adrian Cole
  24. */
  25. public class IPForwardingRule implements Comparable<IPForwardingRule> {
  26. public static Builder builder() {
  27. return new Builder();
  28. }
  29. public static class Builder {
  30. private long id;
  31. private String IPAddress;
  32. private long IPAddressId;
  33. private int startPort;
  34. private String protocol;
  35. public int endPort;
  36. private String state;
  37. private String virtualMachineDisplayName;
  38. public long virtualMachineId;
  39. private String virtualMachineName;
  40. public Builder id(long id) {
  41. this.id = id;
  42. return this;
  43. }
  44. public Builder IPAddress(String IPAddress) {
  45. this.IPAddress = IPAddress;
  46. return this;
  47. }
  48. public Builder IPAddressId(long IPAddressId) {
  49. this.IPAddressId = IPAddressId;
  50. return this;
  51. }
  52. public Builder startPort(int startPort) {
  53. this.startPort = startPort;
  54. return this;
  55. }
  56. public Builder protocol(String protocol) {
  57. this.protocol = protocol;
  58. return this;
  59. }
  60. public Builder endPort(int endPort) {
  61. this.endPort = endPort;
  62. return this;
  63. }
  64. public Builder state(String state) {
  65. this.state = state;
  66. return this;
  67. }
  68. public Builder virtualMachineDisplayName(String virtualMachineDisplayName) {
  69. this.virtualMachineDisplayName = virtualMachineDisplayName;
  70. return this;
  71. }
  72. public Builder virtualMachineId(long virtualMachineId) {
  73. this.virtualMachineId = virtualMachineId;
  74. return this;
  75. }
  76. public Builder virtualMachineName(String virtualMachineName) {
  77. this.virtualMachineName = virtualMachineName;
  78. return this;
  79. }
  80. public IPForwardingRule build() {
  81. return new IPForwardingRule(id, IPAddress, IPAddressId, startPort, protocol, endPort, state,
  82. virtualMachineDisplayName, virtualMachineId, virtualMachineName);
  83. }
  84. }
  85. private long id;
  86. @SerializedName("ipaddress")
  87. private String IPAddress;
  88. @SerializedName("ipaddressid")
  89. private long IPAddressId;
  90. @SerializedName("startport")
  91. private int startPort;
  92. private String protocol;
  93. @SerializedName("endport")
  94. public int endPort;
  95. private String state;
  96. @SerializedName("virtualmachinedisplayname")
  97. private String virtualMachineDisplayName;
  98. @SerializedName("virtualmachineid")
  99. public long virtualMachineId;
  100. @SerializedName("virtualmachinename")
  101. private String virtualMachineName;
  102. // for deserializer
  103. IPForwardingRule() {
  104. }
  105. public IPForwardingRule(long id, String iPAddress, long iPAddressId, int startPort, String protocol, int endPort,
  106. String state, String virtualMachineDisplayName, long virtualMachineId, String virtualMachineName) {
  107. this.id = id;
  108. this.IPAddress = iPAddress;
  109. this.IPAddressId = iPAddressId;
  110. this.startPort = startPort;
  111. this.protocol = protocol;
  112. this.endPort = endPort;
  113. this.state = state;
  114. this.virtualMachineDisplayName = virtualMachineDisplayName;
  115. this.virtualMachineId = virtualMachineId;
  116. this.virtualMachineName = virtualMachineName;
  117. }
  118. @Override
  119. public int compareTo(IPForwardingRule arg0) {
  120. return new Long(id).compareTo(arg0.getId());
  121. }
  122. /**
  123. *
  124. * @return the ID of the ip forwarding rule
  125. */
  126. public long getId() {
  127. return id;
  128. }
  129. /**
  130. *
  131. * @return the public ip address for the ip forwarding rule
  132. */
  133. public String getIPAddress() {
  134. return IPAddress;
  135. }
  136. /**
  137. *
  138. * @return the public ip address id for the ip forwarding rule
  139. */
  140. public long getIPAddressId() {
  141. return IPAddressId;
  142. }
  143. /**
  144. *
  145. * @return the private port for the ip forwarding rule
  146. */
  147. public int getStartPort() {
  148. return startPort;
  149. }
  150. /**
  151. *
  152. * @return the protocol of the ip forwarding rule
  153. */
  154. public String getProtocol() {
  155. return protocol;
  156. }
  157. /**
  158. *
  159. * @return the public port for the ip forwarding rule
  160. */
  161. public int getEndPort() {
  162. return endPort;
  163. }
  164. /**
  165. *
  166. * @return the state of the rule
  167. */
  168. public String getState() {
  169. return state;
  170. }
  171. /**
  172. *
  173. * @return the VM display name for the ip forwarding rule
  174. */
  175. public String getVirtualMachineDisplayName() {
  176. return virtualMachineDisplayName;
  177. }
  178. /**
  179. *
  180. * @return the VM ID for the ip forwarding rule
  181. */
  182. public long getVirtualMachineId() {
  183. return virtualMachineId;
  184. }
  185. /**
  186. *
  187. * @return the VM name for the ip forwarding rule
  188. */
  189. public String getVirtualMachineName() {
  190. return virtualMachineName;
  191. }
  192. @Override
  193. public int hashCode() {
  194. final int prime = 31;
  195. int result = 1;
  196. result = prime * result + ((IPAddress == null) ? 0 : IPAddress.hashCode());
  197. result = prime * result + (int) (IPAddressId ^ (IPAddressId >>> 32));
  198. result = prime * result + endPort;
  199. result = prime * result + (int) (id ^ (id >>> 32));
  200. result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
  201. result = prime * result + startPort;
  202. result = prime * result + ((state == null) ? 0 : state.hashCode());
  203. result = prime * result + ((virtualMachineDisplayName == null) ? 0 : virtualMachineDisplayName.hashCode());
  204. result = prime * result + (int) (virtualMachineId ^ (virtualMachineId >>> 32));
  205. result = prime * result + ((virtualMachineName == null) ? 0 : virtualMachineName.hashCode());
  206. return result;
  207. }
  208. @Override
  209. public boolean equals(Object obj) {
  210. if (this == obj)
  211. return true;
  212. if (obj == null)
  213. return false;
  214. if (getClass() != obj.getClass())
  215. return false;
  216. IPForwardingRule other = (IPForwardingRule) obj;
  217. if (IPAddress == null) {
  218. if (other.IPAddress != null)
  219. return false;
  220. } else if (!IPAddress.equals(other.IPAddress))
  221. return false;
  222. if (IPAddressId != other.IPAddressId)
  223. return false;
  224. if (endPort != other.endPort)
  225. return false;
  226. if (id != other.id)
  227. return false;
  228. if (protocol == null) {
  229. if (other.protocol != null)
  230. return false;
  231. } else if (!protocol.equals(other.protocol))
  232. return false;
  233. if (startPort != other.startPort)
  234. return false;
  235. if (state == null) {
  236. if (other.state != null)
  237. return false;
  238. } else if (!state.equals(other.state))
  239. return false;
  240. if (virtualMachineDisplayName == null) {
  241. if (other.virtualMachineDisplayName != null)
  242. return false;
  243. } else if (!virtualMachineDisplayName.equals(other.virtualMachineDisplayName))
  244. return false;
  245. if (virtualMachineId != other.virtualMachineId)
  246. return false;
  247. if (virtualMachineName == null) {
  248. if (other.virtualMachineName != null)
  249. return false;
  250. } else if (!virtualMachineName.equals(other.virtualMachineName))
  251. return false;
  252. return true;
  253. }
  254. @Override
  255. public String toString() {
  256. return "[IPAddress=" + IPAddress + ", IPAddressId=" + IPAddressId + ", id=" + id + ", startPort=" + startPort
  257. + ", protocol=" + protocol + ", endPort=" + endPort + ", state=" + state + ", virtualMachineDisplayName="
  258. + virtualMachineDisplayName + ", virtualMachineId=" + virtualMachineId + ", virtualMachineName="
  259. + virtualMachineName + "]";
  260. }
  261. }