| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * 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, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 18 | */ |
| 19 | package org.jclouds.blobstore.domain.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.io.Serializable; |
| 24 | import java.net.URI; |
| 25 | import java.util.Date; |
| 26 | import java.util.Map; |
| 27 | |
| 28 | import javax.annotation.Nullable; |
| 29 | |
| 30 | import org.jclouds.blobstore.domain.StorageMetadata; |
| 31 | import org.jclouds.blobstore.domain.StorageType; |
| 32 | import org.jclouds.domain.Location; |
| 33 | import org.jclouds.domain.internal.ResourceMetadataImpl; |
| 34 | |
| 35 | /** |
| 36 | * Idpayload of the object |
| 37 | * |
| 38 | * @author Adrian Cole |
| 39 | */ |
| 40 | public class StorageMetadataImpl extends ResourceMetadataImpl<StorageType> implements StorageMetadata, Serializable { |
| 41 | |
| 42 | /** The serialVersionUID */ |
| 43 | private static final long serialVersionUID = -280558162576368264L; |
| 44 | |
| 45 | @Nullable |
| 46 | private final String eTag; |
| 47 | @Nullable |
| 48 | private final Date lastModified; |
| 49 | private final StorageType type; |
| 50 | |
| 51 | public StorageMetadataImpl(StorageType type, @Nullable String id, @Nullable String name, |
| 52 | @Nullable Location location, @Nullable URI uri, @Nullable String eTag, @Nullable Date lastModified, |
| 53 | Map<String, String> userMetadata) { |
| 54 | super(id, name, location, uri, userMetadata); |
| 55 | this.eTag = eTag; |
| 56 | this.lastModified = lastModified; |
| 57 | this.type = checkNotNull(type, "type"); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * {@inheritDoc} |
| 62 | */ |
| 63 | @Override |
| 64 | public StorageType getType() { |
| 65 | return type; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int hashCode() { |
| 70 | final int prime = 31; |
| 71 | int result = super.hashCode(); |
| 72 | result = prime * result + ((eTag == null) ? 0 : eTag.hashCode()); |
| 73 | result = prime * result + ((lastModified == null) ? 0 : lastModified.hashCode()); |
| 74 | result = prime * result + ((type == null) ? 0 : type.hashCode()); |
| 75 | return result; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public boolean equals(Object obj) { |
| 80 | if (this == obj) |
| 81 | return true; |
| 82 | if (!super.equals(obj)) |
| 83 | return false; |
| 84 | if (getClass() != obj.getClass()) |
| 85 | return false; |
| 86 | StorageMetadataImpl other = (StorageMetadataImpl) obj; |
| 87 | if (eTag == null) { |
| 88 | if (other.eTag != null) |
| 89 | return false; |
| 90 | } else if (!eTag.equals(other.eTag)) |
| 91 | return false; |
| 92 | if (lastModified == null) { |
| 93 | if (other.lastModified != null) |
| 94 | return false; |
| 95 | } else if (!lastModified.equals(other.lastModified)) |
| 96 | return false; |
| 97 | if (type != other.type) |
| 98 | return false; |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * {@inheritDoc} |
| 104 | */ |
| 105 | @Override |
| 106 | public String getETag() { |
| 107 | return eTag; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * {@inheritDoc} |
| 112 | */ |
| 113 | @Override |
| 114 | public Date getLastModified() { |
| 115 | return lastModified; |
| 116 | } |
| 117 | |
| 118 | } |