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.vcloud.domain.network;
20  
21  import javax.annotation.Nullable;
22  
23  /**
24   * specifies the properties of the network’s DHCP service
25   */
26  public class DhcpService {
27     private final boolean enabled;
28     @Nullable
29     private final Integer defaultLeaseTime;
30     @Nullable
31     private final Integer maxLeaseTime;
32     @Nullable
33     private final IpRange ipRange;
34  
35     public DhcpService(boolean enabled, @Nullable Integer defaultLeaseTime, @Nullable Integer maxLeaseTime,
36              @Nullable IpRange ipRange) {
37        this.enabled = enabled;
38        this.defaultLeaseTime = defaultLeaseTime;
39        this.maxLeaseTime = maxLeaseTime;
40        this.ipRange = ipRange;
41     }
42  
43     /**
44      * @return true if the service is enabled
45      * 
46      * @since vcloud api 0.8
47      */
48     public boolean isEnabled() {
49        return enabled;
50     }
51  
52     /**
53      * default duration of a DCHP address lease
54      * 
55      * @since vcloud api 0.9
56      */
57     @Nullable
58     public Integer getDefaultLeaseTime() {
59        return defaultLeaseTime;
60     }
61  
62     /**
63      * maximum duration of a DCHP address lease.
64      * 
65      * @since vcloud api 0.9
66      */
67     @Nullable
68     public Integer getMaxLeaseTime() {
69        return maxLeaseTime;
70     }
71  
72     /**
73      * @return range of IP addresses available to DHCP clients
74      * 
75      * @since vcloud api 0.9
76      */
77     @Nullable
78     public IpRange getIpRange() {
79        return ipRange;
80     }
81  
82     @Override
83     public int hashCode() {
84        final int prime = 31;
85        int result = 1;
86        result = prime * result + ((defaultLeaseTime == null) ? 0 : defaultLeaseTime.hashCode());
87        result = prime * result + (enabled ? 1231 : 1237);
88        result = prime * result + ((ipRange == null) ? 0 : ipRange.hashCode());
89        result = prime * result + ((maxLeaseTime == null) ? 0 : maxLeaseTime.hashCode());
90        return result;
91     }
92  
93     @Override
94     public boolean equals(Object obj) {
95        if (this == obj)
96           return true;
97        if (obj == null)
98           return false;
99        if (getClass() != obj.getClass())
100          return false;
101       DhcpService other = (DhcpService) obj;
102       if (defaultLeaseTime == null) {
103          if (other.defaultLeaseTime != null)
104             return false;
105       } else if (!defaultLeaseTime.equals(other.defaultLeaseTime))
106          return false;
107       if (enabled != other.enabled)
108          return false;
109       if (ipRange == null) {
110          if (other.ipRange != null)
111             return false;
112       } else if (!ipRange.equals(other.ipRange))
113          return false;
114       if (maxLeaseTime == null) {
115          if (other.maxLeaseTime != null)
116             return false;
117       } else if (!maxLeaseTime.equals(other.maxLeaseTime))
118          return false;
119       return true;
120    }
121 
122    @Override
123    public String toString() {
124       return "[defaultLeaseTime=" + defaultLeaseTime + ", enabled=" + enabled + ", ipRange=" + ipRange
125                + ", maxLeaseTime=" + maxLeaseTime + "]";
126    }
127 }