| 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.azureblob.domain.internal; |
| 20 | |
| 21 | import java.io.Serializable; |
| 22 | import java.net.URI; |
| 23 | import java.util.Date; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | import org.jclouds.azureblob.domain.ContainerProperties; |
| 27 | import org.jclouds.azureblob.domain.MutableContainerPropertiesWithMetadata; |
| 28 | |
| 29 | import com.google.common.collect.Maps; |
| 30 | |
| 31 | /** |
| 32 | * Allows you to manipulate metadata. |
| 33 | * |
| 34 | * @author Adrian Cole |
| 35 | */ |
| 36 | public class MutableContainerPropertiesWithMetadataImpl implements Serializable, |
| 37 | MutableContainerPropertiesWithMetadata { |
| 38 | |
| 39 | /** The serialVersionUID */ |
| 40 | private static final long serialVersionUID = -4648755473986695062L; |
| 41 | |
| 42 | private String name; |
| 43 | private URI url; |
| 44 | private Date lastModified; |
| 45 | private String eTag; |
| 46 | |
| 47 | private Map<String, String> metadata = Maps.newHashMap(); |
| 48 | |
| 49 | public MutableContainerPropertiesWithMetadataImpl() { |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | *{@inheritDoc} |
| 54 | */ |
| 55 | public String getName() { |
| 56 | return name; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | *{@inheritDoc} |
| 61 | */ |
| 62 | public Date getLastModified() { |
| 63 | return lastModified; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | *{@inheritDoc} |
| 68 | */ |
| 69 | public String getETag() { |
| 70 | return eTag; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | *{@inheritDoc} |
| 75 | */ |
| 76 | public int compareTo(ContainerProperties o) { |
| 77 | return (this == o) ? 0 : getName().compareTo(o.getName()); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | *{@inheritDoc} |
| 82 | */ |
| 83 | public Map<String, String> getMetadata() { |
| 84 | return metadata; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | *{@inheritDoc} |
| 89 | */ |
| 90 | public void setETag(String eTag) { |
| 91 | this.eTag = eTag; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | *{@inheritDoc} |
| 96 | */ |
| 97 | public void setName(String name) { |
| 98 | this.name = name; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | *{@inheritDoc} |
| 103 | */ |
| 104 | public void setLastModified(Date lastModified) { |
| 105 | this.lastModified = lastModified; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | *{@inheritDoc} |
| 110 | */ |
| 111 | public void setMetadata(Map<String, String> metadata) { |
| 112 | this.metadata = metadata; |
| 113 | } |
| 114 | |
| 115 | public void setUrl(URI url) { |
| 116 | this.url = url; |
| 117 | } |
| 118 | |
| 119 | public URI getUrl() { |
| 120 | return url; |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public int hashCode() { |
| 125 | final int prime = 31; |
| 126 | int result = 1; |
| 127 | result = prime * result + ((eTag == null) ? 0 : eTag.hashCode()); |
| 128 | result = prime * result + ((lastModified == null) ? 0 : lastModified.hashCode()); |
| 129 | result = prime * result + ((metadata == null) ? 0 : metadata.hashCode()); |
| 130 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 131 | result = prime * result + ((url == null) ? 0 : url.hashCode()); |
| 132 | return result; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public boolean equals(Object obj) { |
| 137 | if (this == obj) |
| 138 | return true; |
| 139 | if (obj == null) |
| 140 | return false; |
| 141 | if (getClass() != obj.getClass()) |
| 142 | return false; |
| 143 | MutableContainerPropertiesWithMetadataImpl other = (MutableContainerPropertiesWithMetadataImpl) obj; |
| 144 | if (eTag == null) { |
| 145 | if (other.eTag != null) |
| 146 | return false; |
| 147 | } else if (!eTag.equals(other.eTag)) |
| 148 | return false; |
| 149 | if (lastModified == null) { |
| 150 | if (other.lastModified != null) |
| 151 | return false; |
| 152 | } else if (!lastModified.equals(other.lastModified)) |
| 153 | return false; |
| 154 | if (metadata == null) { |
| 155 | if (other.metadata != null) |
| 156 | return false; |
| 157 | } else if (!metadata.equals(other.metadata)) |
| 158 | return false; |
| 159 | if (name == null) { |
| 160 | if (other.name != null) |
| 161 | return false; |
| 162 | } else if (!name.equals(other.name)) |
| 163 | return false; |
| 164 | if (url == null) { |
| 165 | if (other.url != null) |
| 166 | return false; |
| 167 | } else if (!url.equals(other.url)) |
| 168 | return false; |
| 169 | return true; |
| 170 | } |
| 171 | } |