| 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.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 | } |