View Javadoc

1   /**
2    * Licensed to jclouds, Inc. (jclouds) under one or more
3    * contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  jclouds licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.jclouds.trmk.vcloud_0_8.domain.internal;
20  
21  import java.net.URI;
22  import java.util.Map;
23  
24  import com.google.common.collect.ImmutableMap;
25  import org.jclouds.javax.annotation.Nullable;
26  import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
27  import org.jclouds.trmk.vcloud_0_8.domain.VDC;
28  
29  import static com.google.common.base.Preconditions.checkNotNull;
30  
31  /**
32   * Locations of resources in vCloud
33   * 
34   * @author Adrian Cole
35   * 
36   */
37  public class VDCImpl extends ReferenceTypeImpl implements VDC {
38  
39     @Nullable
40     private final String description;
41     private final ReferenceType catalog;
42     private final ReferenceType publicIps;
43     private final ReferenceType internetServices;
44     private final Map<String, ReferenceType> resourceEntities;
45     private final Map<String, ReferenceType> availableNetworks;
46  
47     public VDCImpl(String name, String type, URI href, @Nullable String description, ReferenceType catalog,
48           ReferenceType publicIps, ReferenceType internetServices, Map<String, ReferenceType> resourceEntities,
49           Map<String, ReferenceType> availableNetworks) {
50        super(name, type, href);
51        this.description = description;
52        this.catalog = checkNotNull(catalog, "catalog");
53        this.publicIps = checkNotNull(publicIps, "publicIps");
54        this.internetServices = checkNotNull(internetServices, "internetServices");
55        this.resourceEntities = ImmutableMap.copyOf(checkNotNull(resourceEntities, "resourceEntities"));
56        this.availableNetworks = ImmutableMap.copyOf(checkNotNull(availableNetworks, "availableNetworks"));
57     }
58  
59     /**
60      * @InheritDoc
61      */
62     @Override
63     public String getDescription() {
64        return description;
65     }
66  
67     /**
68      * @InheritDoc
69      */
70     @Override
71     public ReferenceType getCatalog() {
72        return catalog;
73     }
74  
75     /**
76      * @InheritDoc
77      */
78     @Override
79     public ReferenceType getPublicIps() {
80        return publicIps;
81     }
82  
83     /**
84      * @InheritDoc
85      */
86     @Override
87     public ReferenceType getInternetServices() {
88        return internetServices;
89     }
90  
91     /**
92      * @InheritDoc
93      */
94     @Override
95     public Map<String, ReferenceType> getResourceEntities() {
96        return resourceEntities;
97     }
98  
99     /**
100     * @InheritDoc
101     */
102    @Override
103    public Map<String, ReferenceType> getAvailableNetworks() {
104       return availableNetworks;
105    }
106 
107    @Override
108    public int hashCode() {
109       final int prime = 31;
110       int result = super.hashCode();
111       result = prime * result + ((availableNetworks == null) ? 0 : availableNetworks.hashCode());
112       result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
113       result = prime * result + ((description == null) ? 0 : description.hashCode());
114       result = prime * result + ((internetServices == null) ? 0 : internetServices.hashCode());
115       result = prime * result + ((publicIps == null) ? 0 : publicIps.hashCode());
116       result = prime * result + ((resourceEntities == null) ? 0 : resourceEntities.hashCode());
117       return result;
118    }
119 
120    @Override
121    public boolean equals(Object obj) {
122       if (this == obj)
123          return true;
124       if (!super.equals(obj))
125          return false;
126       if (getClass() != obj.getClass())
127          return false;
128       VDCImpl other = (VDCImpl) obj;
129       if (availableNetworks == null) {
130          if (other.availableNetworks != null)
131             return false;
132       } else if (!availableNetworks.equals(other.availableNetworks))
133          return false;
134       if (catalog == null) {
135          if (other.catalog != null)
136             return false;
137       } else if (!catalog.equals(other.catalog))
138          return false;
139       if (description == null) {
140          if (other.description != null)
141             return false;
142       } else if (!description.equals(other.description))
143          return false;
144       if (internetServices == null) {
145          if (other.internetServices != null)
146             return false;
147       } else if (!internetServices.equals(other.internetServices))
148          return false;
149       if (publicIps == null) {
150          if (other.publicIps != null)
151             return false;
152       } else if (!publicIps.equals(other.publicIps))
153          return false;
154       if (resourceEntities == null) {
155          if (other.resourceEntities != null)
156             return false;
157       } else if (!resourceEntities.equals(other.resourceEntities))
158          return false;
159       return true;
160    }
161 
162    @Override
163    public String toString() {
164       return "[name=" + getName() + ", href=" + getHref() + ", description=" + description + ", catalog=" + catalog
165             + ", publicIps=" + publicIps + ", internetServices=" + internetServices + ", resourceEntities="
166             + resourceEntities + ", availableNetworks=" + availableNetworks + "]";
167    }
168 
169 }