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 static com.google.common.base.Preconditions.checkNotNull;
22  
23  /**
24   * The IpRange element defines a range of IP addresses available on a network.
25   * 
26   */
27  public class IpRange {
28     private final String startAddress;
29     private final String endAddress;
30  
31     public IpRange(String startAddress, String endAddress) {
32        this.startAddress = checkNotNull(startAddress, "startAddress");
33        this.endAddress = checkNotNull(endAddress, "endAddress");
34     }
35  
36     /**
37      * @return lowest IP address in the range
38      * 
39      * @since vcloud api 0.9
40      */
41     public String getStartAddress() {
42        return startAddress;
43     }
44  
45     /**
46      * @return highest IP address in the range
47      * 
48      * @since vcloud api 0.9
49      */
50     public String getEndAddress() {
51        return endAddress;
52     }
53  
54     @Override
55     public int hashCode() {
56        final int prime = 31;
57        int result = 1;
58        result = prime * result + ((endAddress == null) ? 0 : endAddress.hashCode());
59        result = prime * result + ((startAddress == null) ? 0 : startAddress.hashCode());
60        return result;
61     }
62  
63     @Override
64     public boolean equals(Object obj) {
65        if (this == obj)
66           return true;
67        if (obj == null)
68           return false;
69        if (getClass() != obj.getClass())
70           return false;
71        IpRange other = (IpRange) obj;
72        if (endAddress == null) {
73           if (other.endAddress != null)
74              return false;
75        } else if (!endAddress.equals(other.endAddress))
76           return false;
77        if (startAddress == null) {
78           if (other.startAddress != null)
79              return false;
80        } else if (!startAddress.equals(other.startAddress))
81           return false;
82        return true;
83     }
84  
85     @Override
86     public String toString() {
87        return "[startAddress=" + startAddress + ", endAddress=" + endAddress + "]";
88     }
89  }