| 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.atmos.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 com.google.common.collect.Maps; |
| 27 | import com.google.common.collect.Sets; |
| 28 | |
| 29 | /** |
| 30 | * User metadata |
| 31 | * |
| 32 | * @author Adrian Cole |
| 33 | */ |
| 34 | public class UserMetadata { |
| 35 | private final Map<String, String> metadata; |
| 36 | private final Map<String, String> listableMetadata; |
| 37 | private final Set<String> tags; |
| 38 | private final Set<String> listableTags; |
| 39 | |
| 40 | public UserMetadata(Map<String, String> metadata, Map<String, String> listableMetadata, Iterable<String> tags, |
| 41 | Iterable<String> listableTags) { |
| 42 | this.metadata = Maps.newLinkedHashMap(checkNotNull(metadata, "metadata")); |
| 43 | this.listableMetadata = Maps.newLinkedHashMap(checkNotNull(listableMetadata, "listableMetadata")); |
| 44 | this.tags = Sets.newLinkedHashSet(checkNotNull(tags, "tags")); |
| 45 | this.listableTags = Sets.newLinkedHashSet(checkNotNull(listableTags, "listableTags")); |
| 46 | } |
| 47 | |
| 48 | public UserMetadata() { |
| 49 | this.metadata = Maps.newLinkedHashMap(); |
| 50 | this.listableMetadata = Maps.newLinkedHashMap(); |
| 51 | this.tags = Sets.newLinkedHashSet(); |
| 52 | this.listableTags = Sets.newLinkedHashSet(); |
| 53 | } |
| 54 | |
| 55 | public Map<String, String> getMetadata() { |
| 56 | return metadata; |
| 57 | } |
| 58 | |
| 59 | public Map<String, String> getListableMetadata() { |
| 60 | return listableMetadata; |
| 61 | } |
| 62 | |
| 63 | public Set<String> getTags() { |
| 64 | return tags; |
| 65 | } |
| 66 | |
| 67 | public Set<String> getListableTags() { |
| 68 | return listableTags; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public String toString() { |
| 73 | return "[metadata=" + metadata + ", listableMetadata=" + listableMetadata + ", tags=" + tags + ", listableTags=" |
| 74 | + listableTags + "]"; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public int hashCode() { |
| 79 | final int prime = 31; |
| 80 | int result = 1; |
| 81 | result = prime * result + ((listableMetadata == null) ? 0 : listableMetadata.hashCode()); |
| 82 | result = prime * result + ((listableTags == null) ? 0 : listableTags.hashCode()); |
| 83 | result = prime * result + ((metadata == null) ? 0 : metadata.hashCode()); |
| 84 | result = prime * result + ((tags == null) ? 0 : tags.hashCode()); |
| 85 | return result; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public boolean equals(Object obj) { |
| 90 | if (this == obj) |
| 91 | return true; |
| 92 | if (obj == null) |
| 93 | return false; |
| 94 | if (getClass() != obj.getClass()) |
| 95 | return false; |
| 96 | UserMetadata other = (UserMetadata) obj; |
| 97 | if (listableMetadata == null) { |
| 98 | if (other.listableMetadata != null) |
| 99 | return false; |
| 100 | } else if (!listableMetadata.equals(other.listableMetadata)) |
| 101 | return false; |
| 102 | if (listableTags == null) { |
| 103 | if (other.listableTags != null) |
| 104 | return false; |
| 105 | } else if (!listableTags.equals(other.listableTags)) |
| 106 | return false; |
| 107 | if (metadata == null) { |
| 108 | if (other.metadata != null) |
| 109 | return false; |
| 110 | } else if (!metadata.equals(other.metadata)) |
| 111 | return false; |
| 112 | if (tags == null) { |
| 113 | if (other.tags != null) |
| 114 | return false; |
| 115 | } else if (!tags.equals(other.tags)) |
| 116 | return false; |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | } |