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.trmk.vcloud_0_8.domain.internal;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import java.net.URI;
24  import java.util.Map;
25  
26  import javax.annotation.Nullable;
27  
28  import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
29  import org.jclouds.trmk.vcloud_0_8.domain.VDC;
30  
31  import com.google.common.collect.ImmutableMap;
32  
33  /**
34   * Locations of resources in vCloud
35   * 
36   * @author Adrian Cole
37   * 
38   */
39  public class VDCImpl extends ReferenceTypeImpl implements VDC {
40  
41     @Nullable
42     private final String description;
43     private final ReferenceType catalog;
44     private final ReferenceType publicIps;
45     private final ReferenceType internetServices;
46     private final Map<String, ReferenceType> resourceEntities;
47     private final Map<String, ReferenceType> availableNetworks;
48  
49     public VDCImpl(String name, String type, URI href, @Nullable String description, ReferenceType catalog,
50           ReferenceType publicIps, ReferenceType internetServices, Map<String, ReferenceType> resourceEntities,
51           Map<String, ReferenceType> availableNetworks) {
52        super(name, type, href);
53        this.description = description;
54        this.catalog = checkNotNull(catalog, "catalog");
55        this.publicIps = checkNotNull(publicIps, "publicIps");
56        this.internetServices = checkNotNull(internetServices, "internetServices");
57        this.resourceEntities = ImmutableMap.copyOf(checkNotNull(resourceEntities, "resourceEntities"));
58        this.availableNetworks = ImmutableMap.copyOf(checkNotNull(availableNetworks, "availableNetworks"));
59     }
60  
61     /**
62      * @InheritDoc
63      */
64     @Override
65     public String getDescription() {
66        return description;
67     }
68  
69     /**
70      * @InheritDoc
71      */
72     @Override
73     public ReferenceType getCatalog() {
74        return catalog;
75     }
76  
77     /**
78      * @InheritDoc
79      */
80     @Override
81     public ReferenceType getPublicIps() {
82        return publicIps;
83     }
84  
85     /**
86      * @InheritDoc
87      */
88     @Override
89     public ReferenceType getInternetServices() {
90        return internetServices;
91     }
92  
93     /**
94      * @InheritDoc
95      */
96     @Override
97     public Map<String, ReferenceType> getResourceEntities() {
98        return resourceEntities;
99     }
100 
101    /**
102     * @InheritDoc
103     */
104    @Override
105    public Map<String, ReferenceType> getAvailableNetworks() {
106       return availableNetworks;
107    }
108 
109    @Override
110    public int hashCode() {
111       final int prime = 31;
112       int result = super.hashCode();
113       result = prime * result + ((availableNetworks == null) ? 0 : availableNetworks.hashCode());
114       result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
115       result = prime * result + ((description == null) ? 0 : description.hashCode());
116       result = prime * result + ((internetServices == null) ? 0 : internetServices.hashCode());
117       result = prime * result + ((publicIps == null) ? 0 : publicIps.hashCode());
118       result = prime * result + ((resourceEntities == null) ? 0 : resourceEntities.hashCode());
119       return result;
120    }
121 
122    @Override
123    public boolean equals(Object obj) {
124       if (this == obj)
125          return true;
126       if (!super.equals(obj))
127          return false;
128       if (getClass() != obj.getClass())
129          return false;
130       VDCImpl other = (VDCImpl) obj;
131       if (availableNetworks == null) {
132          if (other.availableNetworks != null)
133             return false;
134       } else if (!availableNetworks.equals(other.availableNetworks))
135          return false;
136       if (catalog == null) {
137          if (other.catalog != null)
138             return false;
139       } else if (!catalog.equals(other.catalog))
140          return false;
141       if (description == null) {
142          if (other.description != null)
143             return false;
144       } else if (!description.equals(other.description))
145          return false;
146       if (internetServices == null) {
147          if (other.internetServices != null)
148             return false;
149       } else if (!internetServices.equals(other.internetServices))
150          return false;
151       if (publicIps == null) {
152          if (other.publicIps != null)
153             return false;
154       } else if (!publicIps.equals(other.publicIps))
155          return false;
156       if (resourceEntities == null) {
157          if (other.resourceEntities != null)
158             return false;
159       } else if (!resourceEntities.equals(other.resourceEntities))
160          return false;
161       return true;
162    }
163 
164    @Override
165    public String toString() {
166       return "[name=" + getName() + ", href=" + getHref() + ", description=" + description + ", catalog=" + catalog
167             + ", publicIps=" + publicIps + ", internetServices=" + internetServices + ", resourceEntities="
168             + resourceEntities + ", availableNetworks=" + availableNetworks + "]";
169    }
170 
171 }