View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * 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, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.cloudsigma.domain;
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.ImmutableSet;
28  
29  /**
30   * 
31   * @author Adrian Cole
32   */
33  public class StaticIPInfo {
34     public static class Builder {
35        protected String ip;
36        protected String user;
37        protected String netmask;
38        protected Set<String> nameservers = ImmutableSet.of();
39        protected String gateway;
40  
41        public Builder ip(String ip) {
42           this.ip = ip;
43           return this;
44        }
45  
46        public Builder user(String user) {
47           this.user = user;
48           return this;
49        }
50  
51        public Builder nameservers(Iterable<String> nameservers) {
52           this.nameservers = ImmutableSet.copyOf(checkNotNull(nameservers, "nameservers"));
53           return this;
54        }
55  
56        public Builder gateway(String gateway) {
57           this.gateway = gateway;
58           return this;
59        }
60  
61        public Builder netmask(String netmask) {
62           this.netmask = netmask;
63           return this;
64        }
65  
66        public StaticIPInfo build() {
67           return new StaticIPInfo(ip, user, netmask, nameservers, gateway);
68        }
69  
70        @Override
71        public int hashCode() {
72           final int prime = 31;
73           int result = 1;
74           result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
75           result = prime * result + ((nameservers == null) ? 0 : nameservers.hashCode());
76           result = prime * result + ((netmask == null) ? 0 : netmask.hashCode());
77           result = prime * result + ((user == null) ? 0 : user.hashCode());
78           result = prime * result + ((ip == null) ? 0 : ip.hashCode());
79           return result;
80        }
81  
82        @Override
83        public boolean equals(Object obj) {
84           if (this == obj)
85              return true;
86           if (obj == null)
87              return false;
88           if (getClass() != obj.getClass())
89              return false;
90           Builder other = (Builder) obj;
91           if (gateway == null) {
92              if (other.gateway != null)
93                 return false;
94           } else if (!gateway.equals(other.gateway))
95              return false;
96           if (nameservers == null) {
97              if (other.nameservers != null)
98                 return false;
99           } else if (!nameservers.equals(other.nameservers))
100             return false;
101          if (netmask == null) {
102             if (other.netmask != null)
103                return false;
104          } else if (!netmask.equals(other.netmask))
105             return false;
106          if (user == null) {
107             if (other.user != null)
108                return false;
109          } else if (!user.equals(other.user))
110             return false;
111          if (ip == null) {
112             if (other.ip != null)
113                return false;
114          } else if (!ip.equals(other.ip))
115             return false;
116          return true;
117       }
118    }
119 
120    protected final String ip;
121    protected final String user;
122    protected final String netmask;
123    protected final Set<String> nameservers;
124    protected final String gateway;
125 
126    public StaticIPInfo(String ip, String user, String netmask, Iterable<String> nameservers, String gateway) {
127       this.ip = checkNotNull(ip, "ip");
128       this.user = checkNotNull(user, "user");
129       this.netmask = checkNotNull(netmask, "netmask");
130       this.nameservers = ImmutableSet.copyOf(checkNotNull(nameservers, "nameservers"));
131       this.gateway = checkNotNull(gateway, "gateway");
132    }
133 
134    /**
135     * 
136     * @return ip of the ip.
137     */
138    @Nullable
139    public String getAddress() {
140       return ip;
141    }
142 
143    /**
144     * 
145     * @return user owning the ip
146     */
147    public String getUser() {
148       return user;
149    }
150 
151    /**
152     * 
153     * @return netmask of the ip
154     */
155    public String getNetmask() {
156       return netmask;
157    }
158 
159    /**
160     * 
161     * @return nameservers of the ip
162     */
163    public Set<String> getNameservers() {
164       return nameservers;
165    }
166 
167    /**
168     * 
169     * @return gateway of the ip
170     */
171    public String getGateway() {
172       return gateway;
173    }
174 
175    @Override
176    public int hashCode() {
177       final int prime = 31;
178       int result = 1;
179       result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
180       result = prime * result + ((nameservers == null) ? 0 : nameservers.hashCode());
181       result = prime * result + ((netmask == null) ? 0 : netmask.hashCode());
182       result = prime * result + ((user == null) ? 0 : user.hashCode());
183       result = prime * result + ((ip == null) ? 0 : ip.hashCode());
184       return result;
185    }
186 
187    @Override
188    public boolean equals(Object obj) {
189       if (this == obj)
190          return true;
191       if (obj == null)
192          return false;
193       if (getClass() != obj.getClass())
194          return false;
195       StaticIPInfo other = (StaticIPInfo) obj;
196       if (gateway == null) {
197          if (other.gateway != null)
198             return false;
199       } else if (!gateway.equals(other.gateway))
200          return false;
201       if (nameservers == null) {
202          if (other.nameservers != null)
203             return false;
204       } else if (!nameservers.equals(other.nameservers))
205          return false;
206       if (netmask == null) {
207          if (other.netmask != null)
208             return false;
209       } else if (!netmask.equals(other.netmask))
210          return false;
211       if (user == null) {
212          if (other.user != null)
213             return false;
214       } else if (!user.equals(other.user))
215          return false;
216       if (ip == null) {
217          if (other.ip != null)
218             return false;
219       } else if (!ip.equals(other.ip))
220          return false;
221       return true;
222    }
223 
224    @Override
225    public String toString() {
226       return "[ip=" + ip + ", user=" + user + ", netmask=" + netmask + ", nameservers="
227             + nameservers + ", gateway=" + gateway + "]";
228    }
229 
230 }