| 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.deltacloud.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | |
| 25 | import org.jclouds.javax.annotation.Nullable; |
| 26 | |
| 27 | /** |
| 28 | * An image is a platonic form of a machine. Images are not directly executable, but are a template |
| 29 | * for creating actual instances of machines. |
| 30 | * |
| 31 | * @author Adrian Cole |
| 32 | */ |
| 33 | public class Image { |
| 34 | private final URI href; |
| 35 | private final String id; |
| 36 | private final String ownerId; |
| 37 | @Nullable |
| 38 | private final String name; |
| 39 | @Nullable |
| 40 | private final String description; |
| 41 | private final String architecture; |
| 42 | |
| 43 | public Image(URI href, String id, String ownerId, @Nullable String name, String description, String architecture) { |
| 44 | this.href = checkNotNull(href, "href"); |
| 45 | this.id = checkNotNull(id, "id"); |
| 46 | this.ownerId = checkNotNull(ownerId, "ownerId"); |
| 47 | this.name = name; |
| 48 | this.description = description; |
| 49 | this.architecture = checkNotNull(architecture, "architecture"); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * |
| 54 | * @return URL to manipulate a specific image |
| 55 | */ |
| 56 | public URI getHref() { |
| 57 | return href; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * |
| 62 | * @return A unique identifier for the image |
| 63 | */ |
| 64 | public String getId() { |
| 65 | return id; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * |
| 70 | * @return An opaque identifier which indicates the owner of an image |
| 71 | */ |
| 72 | public String getOwnerId() { |
| 73 | return ownerId; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * |
| 78 | * @return An optional short label describing the image |
| 79 | */ |
| 80 | @Nullable |
| 81 | public String getName() { |
| 82 | return name; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * |
| 87 | * @return An optional description describing the image more fully |
| 88 | */ |
| 89 | @Nullable |
| 90 | public String getDescription() { |
| 91 | return description; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * |
| 96 | * @return A description of the machine architecture of the image which may contain values such |
| 97 | * as: i386, x86_64 |
| 98 | */ |
| 99 | public String getArchitecture() { |
| 100 | return architecture; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public int hashCode() { |
| 105 | final int prime = 31; |
| 106 | int result = 1; |
| 107 | result = prime * result + ((architecture == null) ? 0 : architecture.hashCode()); |
| 108 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
| 109 | result = prime * result + ((href == null) ? 0 : href.hashCode()); |
| 110 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| 111 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 112 | result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode()); |
| 113 | return result; |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public boolean equals(Object obj) { |
| 118 | if (this == obj) |
| 119 | return true; |
| 120 | if (obj == null) |
| 121 | return false; |
| 122 | if (getClass() != obj.getClass()) |
| 123 | return false; |
| 124 | Image other = (Image) obj; |
| 125 | if (architecture == null) { |
| 126 | if (other.architecture != null) |
| 127 | return false; |
| 128 | } else if (!architecture.equals(other.architecture)) |
| 129 | return false; |
| 130 | if (description == null) { |
| 131 | if (other.description != null) |
| 132 | return false; |
| 133 | } else if (!description.equals(other.description)) |
| 134 | return false; |
| 135 | if (href == null) { |
| 136 | if (other.href != null) |
| 137 | return false; |
| 138 | } else if (!href.equals(other.href)) |
| 139 | return false; |
| 140 | if (id == null) { |
| 141 | if (other.id != null) |
| 142 | return false; |
| 143 | } else if (!id.equals(other.id)) |
| 144 | return false; |
| 145 | if (name == null) { |
| 146 | if (other.name != null) |
| 147 | return false; |
| 148 | } else if (!name.equals(other.name)) |
| 149 | return false; |
| 150 | if (ownerId == null) { |
| 151 | if (other.ownerId != null) |
| 152 | return false; |
| 153 | } else if (!ownerId.equals(other.ownerId)) |
| 154 | return false; |
| 155 | return true; |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public String toString() { |
| 160 | return "[href=" + href + ", id=" + id + ", ownerId=" + ownerId + ", name=" + name + ", description=" |
| 161 | + description + ", architecture=" + architecture + "]"; |
| 162 | } |
| 163 | } |