| 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.elasticstack.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.util.Map; |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import org.jclouds.javax.annotation.Nullable; |
| 27 | |
| 28 | import com.google.common.collect.ImmutableMap; |
| 29 | import com.google.common.collect.ImmutableSet; |
| 30 | |
| 31 | /** |
| 32 | * |
| 33 | * @author Adrian Cole |
| 34 | */ |
| 35 | public class Item { |
| 36 | public static class Builder { |
| 37 | protected String uuid; |
| 38 | protected String name; |
| 39 | protected Set<String> tags = ImmutableSet.of(); |
| 40 | protected Map<String, String> userMetadata = ImmutableMap.of(); |
| 41 | |
| 42 | public Builder uuid(String uuid) { |
| 43 | this.uuid = uuid; |
| 44 | return this; |
| 45 | } |
| 46 | |
| 47 | public Builder name(String name) { |
| 48 | this.name = name; |
| 49 | return this; |
| 50 | } |
| 51 | |
| 52 | public Builder tags(Iterable<String> tags) { |
| 53 | this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags")); |
| 54 | return this; |
| 55 | } |
| 56 | |
| 57 | public Builder userMetadata(Map<String, String> userMetadata) { |
| 58 | this.userMetadata = ImmutableMap.copyOf(checkNotNull(userMetadata, "userMetadata")); |
| 59 | return this; |
| 60 | } |
| 61 | |
| 62 | public Item build() { |
| 63 | return new Item(uuid, name, tags, userMetadata); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public int hashCode() { |
| 68 | final int prime = 31; |
| 69 | int result = 1; |
| 70 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 71 | result = prime * result + ((tags == null) ? 0 : tags.hashCode()); |
| 72 | result = prime * result + ((userMetadata == null) ? 0 : userMetadata.hashCode()); |
| 73 | result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); |
| 74 | return result; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public boolean equals(Object obj) { |
| 79 | if (this == obj) |
| 80 | return true; |
| 81 | if (obj == null) |
| 82 | return false; |
| 83 | if (getClass() != obj.getClass()) |
| 84 | return false; |
| 85 | Builder other = (Builder) obj; |
| 86 | if (name == null) { |
| 87 | if (other.name != null) |
| 88 | return false; |
| 89 | } else if (!name.equals(other.name)) |
| 90 | return false; |
| 91 | if (tags == null) { |
| 92 | if (other.tags != null) |
| 93 | return false; |
| 94 | } else if (!tags.equals(other.tags)) |
| 95 | return false; |
| 96 | if (userMetadata == null) { |
| 97 | if (other.userMetadata != null) |
| 98 | return false; |
| 99 | } else if (!userMetadata.equals(other.userMetadata)) |
| 100 | return false; |
| 101 | if (uuid == null) { |
| 102 | if (other.uuid != null) |
| 103 | return false; |
| 104 | } else if (!uuid.equals(other.uuid)) |
| 105 | return false; |
| 106 | return true; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | @Nullable |
| 111 | protected final String uuid; |
| 112 | protected final String name; |
| 113 | protected final Set<String> tags; |
| 114 | protected final Map<String, String> userMetadata; |
| 115 | |
| 116 | public Item(@Nullable String uuid, String name, Iterable<String> tags, Map<String, String> userMetadata) { |
| 117 | this.uuid = uuid; |
| 118 | this.name = checkNotNull(name, "name"); |
| 119 | this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags")); |
| 120 | this.userMetadata = ImmutableMap.copyOf(checkNotNull(userMetadata, "userMetadata")); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * |
| 125 | * @return uuid of the item. |
| 126 | */ |
| 127 | @Nullable |
| 128 | public String getUuid() { |
| 129 | return uuid; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * |
| 134 | * @return name of the item |
| 135 | */ |
| 136 | public String getName() { |
| 137 | return name; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * |
| 142 | * @return list of tags |
| 143 | */ |
| 144 | public Set<String> getTags() { |
| 145 | return tags; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * |
| 150 | * @return user-defined KEY VALUE pairs |
| 151 | */ |
| 152 | public Map<String, String> getUserMetadata() { |
| 153 | return userMetadata; |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public int hashCode() { |
| 158 | final int prime = 31; |
| 159 | int result = 1; |
| 160 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 161 | result = prime * result + ((tags == null) ? 0 : tags.hashCode()); |
| 162 | result = prime * result + ((userMetadata == null) ? 0 : userMetadata.hashCode()); |
| 163 | return result; |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public boolean equals(Object obj) { |
| 168 | if (this == obj) |
| 169 | return true; |
| 170 | if (obj == null) |
| 171 | return false; |
| 172 | if (getClass() != obj.getClass()) |
| 173 | return false; |
| 174 | Item other = (Item) obj; |
| 175 | if (name == null) { |
| 176 | if (other.name != null) |
| 177 | return false; |
| 178 | } else if (!name.equals(other.name)) |
| 179 | return false; |
| 180 | if (tags == null) { |
| 181 | if (other.tags != null) |
| 182 | return false; |
| 183 | } else if (!tags.equals(other.tags)) |
| 184 | return false; |
| 185 | if (userMetadata == null) { |
| 186 | if (other.userMetadata != null) |
| 187 | return false; |
| 188 | } else if (!userMetadata.equals(other.userMetadata)) |
| 189 | return false; |
| 190 | return true; |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public String toString() { |
| 195 | return "[uuid=" + uuid + ", name=" + name + ", tags=" + tags + ", userMetadata=" + userMetadata + "]"; |
| 196 | } |
| 197 | |
| 198 | } |