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;
20
21 import static com.google.common.base.Preconditions.checkNotNull;
22
23 import java.util.Set;
24
25 import javax.annotation.Nullable;
26
27 import com.google.common.collect.Iterables;
28 import com.google.common.collect.Sets;
29
30
31
32
33
34
35 public class IpScope {
36 private final boolean inherited;
37 @Nullable
38 private final String gateway;
39 @Nullable
40 private final String netmask;
41 @Nullable
42 private final String dns1;
43 @Nullable
44 private final String dns2;
45 @Nullable
46 private final String dnsSuffix;
47 private final Set<IpRange> ipRanges = Sets.newLinkedHashSet();
48 private final Set<String> allocatedIpAddresses = Sets.newLinkedHashSet();
49
50 public IpScope(boolean inherited, @Nullable String gateway, @Nullable String netmask, @Nullable String dns1,
51 @Nullable String dns2, @Nullable String dnsSuffix, Iterable<IpRange> ipRanges,
52 Iterable<String> allocatedIpAddresses) {
53 this.inherited = inherited;
54 this.gateway = gateway;
55 this.netmask = netmask;
56 this.dns1 = dns1;
57 this.dns2 = dns2;
58 this.dnsSuffix = dnsSuffix;
59 Iterables.addAll(this.ipRanges, checkNotNull(ipRanges, "ipRanges"));
60 Iterables.addAll(this.allocatedIpAddresses, checkNotNull(allocatedIpAddresses, "allocatedIpAddresses"));
61 }
62
63
64
65
66
67
68 public boolean isInherited() {
69 return inherited;
70 }
71
72
73
74
75
76
77 @Nullable
78 public String getGateway() {
79 return gateway;
80 }
81
82
83
84
85
86
87 @Nullable
88 public String getNetmask() {
89 return netmask;
90 }
91
92
93
94
95
96
97 @Nullable
98 public String getDns1() {
99 return dns1;
100 }
101
102
103
104
105
106
107 @Nullable
108 public String getDns2() {
109 return dns2;
110 }
111
112
113
114
115
116
117 @Nullable
118 public String getDnsSuffix() {
119 return dnsSuffix;
120 }
121
122
123
124
125
126
127 public Set<IpRange> getIpRanges() {
128 return ipRanges;
129 }
130
131
132
133
134
135
136 public Set<String> getAllocatedIpAddresses() {
137 return allocatedIpAddresses;
138 }
139
140 @Override
141 public int hashCode() {
142 final int prime = 31;
143 int result = 1;
144 result = prime * result + ((allocatedIpAddresses == null) ? 0 : allocatedIpAddresses.hashCode());
145 result = prime * result + ((dns1 == null) ? 0 : dns1.hashCode());
146 result = prime * result + ((dns2 == null) ? 0 : dns2.hashCode());
147 result = prime * result + ((dnsSuffix == null) ? 0 : dnsSuffix.hashCode());
148 result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
149 result = prime * result + (inherited ? 1231 : 1237);
150 result = prime * result + ((ipRanges == null) ? 0 : ipRanges.hashCode());
151 result = prime * result + ((netmask == null) ? 0 : netmask.hashCode());
152 return result;
153 }
154
155 @Override
156 public boolean equals(Object obj) {
157 if (this == obj)
158 return true;
159 if (obj == null)
160 return false;
161 if (getClass() != obj.getClass())
162 return false;
163 IpScope other = (IpScope) obj;
164 if (allocatedIpAddresses == null) {
165 if (other.allocatedIpAddresses != null)
166 return false;
167 } else if (!allocatedIpAddresses.equals(other.allocatedIpAddresses))
168 return false;
169 if (dns1 == null) {
170 if (other.dns1 != null)
171 return false;
172 } else if (!dns1.equals(other.dns1))
173 return false;
174 if (dns2 == null) {
175 if (other.dns2 != null)
176 return false;
177 } else if (!dns2.equals(other.dns2))
178 return false;
179 if (dnsSuffix == null) {
180 if (other.dnsSuffix != null)
181 return false;
182 } else if (!dnsSuffix.equals(other.dnsSuffix))
183 return false;
184 if (gateway == null) {
185 if (other.gateway != null)
186 return false;
187 } else if (!gateway.equals(other.gateway))
188 return false;
189 if (inherited != other.inherited)
190 return false;
191 if (ipRanges == null) {
192 if (other.ipRanges != null)
193 return false;
194 } else if (!ipRanges.equals(other.ipRanges))
195 return false;
196 if (netmask == null) {
197 if (other.netmask != null)
198 return false;
199 } else if (!netmask.equals(other.netmask))
200 return false;
201 return true;
202 }
203
204 @Override
205 public String toString() {
206 return "[allocatedIpAddresses=" + allocatedIpAddresses + ", dns1=" + dns1 + ", dns2=" + dns2 + ", dnsSuffix="
207 + dnsSuffix + ", gateway=" + gateway + ", inherited=" + inherited + ", ipRanges=" + ipRanges
208 + ", netmask=" + netmask + "]";
209 }
210 }