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.compute.domain.internal;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import org.jclouds.compute.domain.Image;
24  import org.jclouds.compute.domain.Hardware;
25  import org.jclouds.compute.domain.Template;
26  import org.jclouds.compute.options.TemplateOptions;
27  import org.jclouds.domain.Location;
28  
29  /**
30   * 
31   * @author Adrian Cole
32   */
33  public class TemplateImpl implements Template {
34  
35     private final Image image;
36     private final Hardware size;
37     private final Location location;
38     private final TemplateOptions options;
39  
40     public TemplateImpl(Image image, Hardware size, Location location, TemplateOptions options) {
41        this.image = checkNotNull(image, "image");
42        this.size = checkNotNull(size, "size");
43        this.location = checkNotNull(location, "location");
44        this.options = checkNotNull(options, "options");
45     }
46  
47     /**
48      * {@inheritDoc}
49      */
50     @Override
51     public Image getImage() {
52        return image;
53     }
54  
55     /**
56      * {@inheritDoc}
57      */
58     @Override
59     public Hardware getHardware() {
60        return size;
61     }
62  
63     /**
64      * {@inheritDoc}
65      */
66     @Override
67     public Location getLocation() {
68        return location;
69     }
70  
71     /**
72      * {@inheritDoc}
73      */
74     @Override
75     public TemplateOptions getOptions() {
76        return options;
77     }
78  
79     @Override
80     public int hashCode() {
81        final int prime = 31;
82        int result = 1;
83        result = prime * result + ((image == null) ? 0 : image.hashCode());
84        result = prime * result + ((location == null) ? 0 : location.hashCode());
85        result = prime * result + ((options == null) ? 0 : options.hashCode());
86        result = prime * result + ((size == null) ? 0 : size.hashCode());
87        return result;
88     }
89  
90     @Override
91     public boolean equals(Object obj) {
92        if (this == obj)
93           return true;
94        if (obj == null)
95           return false;
96        if (getClass() != obj.getClass())
97           return false;
98        TemplateImpl other = (TemplateImpl) obj;
99        if (image == null) {
100          if (other.image != null)
101             return false;
102       } else if (!image.equals(other.image))
103          return false;
104       if (location == null) {
105          if (other.location != null)
106             return false;
107       } else if (!location.equals(other.location))
108          return false;
109       if (options == null) {
110          if (other.options != null)
111             return false;
112       } else if (!options.equals(other.options))
113          return false;
114       if (size == null) {
115          if (other.size != null)
116             return false;
117       } else if (!size.equals(other.size))
118          return false;
119       return true;
120    }
121 
122    @Override
123    public String toString() {
124       return "[location=" + location + ", image=" + image + ", size=" + size + ", options="
125                + options + "]";
126    }
127 
128    /**
129     * {@inheritDoc}
130     */
131    @Override
132    protected Object clone() throws CloneNotSupportedException {
133       return new TemplateImpl(image, size, location, options);
134    }
135 
136 }