1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.vcloud.domain.network.nat.rules;
20
21 import static com.google.common.base.Preconditions.checkNotNull;
22
23 import javax.annotation.Nullable;
24
25 import org.jclouds.vcloud.domain.network.nat.NatProtocol;
26 import org.jclouds.vcloud.domain.network.nat.NatRule;
27
28
29
30
31
32
33
34
35
36
37 public class VmRule implements NatRule {
38 @Nullable
39 private final String externalIP;
40 private final int externalPort;
41 @Nullable
42 private final String vAppScopedLocalId;
43 private final int vmNicId;
44 private final int internalPort;
45 private final NatProtocol protocol;
46
47 public VmRule(@Nullable String externalIP, int externalPort, @Nullable String vAppScopedLocalId, int vmNicId,
48 int internalPort, NatProtocol protocol) {
49 this.externalIP = externalIP;
50 this.externalPort = externalPort;
51 this.vAppScopedLocalId = vAppScopedLocalId;
52 this.vmNicId = vmNicId;
53 this.internalPort = internalPort;
54 this.protocol = checkNotNull(protocol, "protocol");
55 }
56
57
58
59
60 @Nullable
61 public String getExternalIP() {
62 return externalIP;
63 }
64
65
66
67
68 public Integer getExternalPort() {
69 return externalPort;
70 }
71
72
73
74
75
76 @Nullable
77 public String getVAppScopedLocalId() {
78 return vAppScopedLocalId;
79 }
80
81
82
83
84
85 public int getVmNicId() {
86 return vmNicId;
87 }
88
89
90
91
92
93 public Integer getInternalPort() {
94 return internalPort;
95 }
96
97
98
99
100 public NatProtocol getProtocol() {
101 return protocol;
102 }
103
104 @Override
105 public int hashCode() {
106 final int prime = 31;
107 int result = 1;
108 result = prime * result + ((externalIP == null) ? 0 : externalIP.hashCode());
109 result = prime * result + externalPort;
110 result = prime * result + internalPort;
111 result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
112 result = prime * result + ((vAppScopedLocalId == null) ? 0 : vAppScopedLocalId.hashCode());
113 result = prime * result + vmNicId;
114 return result;
115 }
116
117 @Override
118 public boolean equals(Object obj) {
119 if (this == obj)
120 return true;
121 if (obj == null)
122 return false;
123 if (getClass() != obj.getClass())
124 return false;
125 VmRule other = (VmRule) obj;
126 if (externalIP == null) {
127 if (other.externalIP != null)
128 return false;
129 } else if (!externalIP.equals(other.externalIP))
130 return false;
131 if (externalPort != other.externalPort)
132 return false;
133 if (internalPort != other.internalPort)
134 return false;
135 if (protocol == null) {
136 if (other.protocol != null)
137 return false;
138 } else if (!protocol.equals(other.protocol))
139 return false;
140 if (vAppScopedLocalId == null) {
141 if (other.vAppScopedLocalId != null)
142 return false;
143 } else if (!vAppScopedLocalId.equals(other.vAppScopedLocalId))
144 return false;
145 if (vmNicId != other.vmNicId)
146 return false;
147 return true;
148 }
149
150 @Override
151 public String toString() {
152 return "[externalIP=" + externalIP + ", externalPort=" + externalPort + ", internalPort=" + internalPort
153 + ", protocol=" + protocol + ", vAppScopedLocalId=" + vAppScopedLocalId + ", vmNicId=" + vmNicId + "]";
154 }
155
156 }