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