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