| 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.s3.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.io.ContentMetadata; |
| 27 | import org.jclouds.io.payloads.BaseImmutableContentMetadata; |
| 28 | import org.jclouds.s3.domain.CanonicalUser; |
| 29 | import org.jclouds.s3.domain.ObjectMetadata; |
| 30 | |
| 31 | import com.google.common.collect.ImmutableMap; |
| 32 | |
| 33 | /** |
| 34 | * Returns the metadata parsable from a bucket listing |
| 35 | * |
| 36 | * @author Adrian Cole |
| 37 | */ |
| 38 | public class CopyObjectResult implements Serializable, ObjectMetadata { |
| 39 | |
| 40 | /** The serialVersionUID */ |
| 41 | private static final long serialVersionUID = -4415449798024051115L; |
| 42 | |
| 43 | private final Date lastModified; |
| 44 | private final String eTag; |
| 45 | private final BaseImmutableContentMetadata contentMetadata; |
| 46 | |
| 47 | public CopyObjectResult(Date lastModified, String eTag) { |
| 48 | this.lastModified = lastModified; |
| 49 | this.eTag = eTag; |
| 50 | this.contentMetadata = new BaseImmutableContentMetadata(null, null, null, null, null, null); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | *{@inheritDoc} |
| 55 | */ |
| 56 | @Override |
| 57 | public String getKey() { |
| 58 | return null; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | *{@inheritDoc} |
| 63 | */ |
| 64 | @Override |
| 65 | public String getBucket() { |
| 66 | return null; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | *{@inheritDoc} |
| 71 | */ |
| 72 | @Override |
| 73 | public URI getUri() { |
| 74 | return null; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | *{@inheritDoc} |
| 79 | */ |
| 80 | @Override |
| 81 | public CanonicalUser getOwner() { |
| 82 | return null; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | *{@inheritDoc} |
| 87 | */ |
| 88 | @Override |
| 89 | public StorageClass getStorageClass() { |
| 90 | return null; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | *{@inheritDoc} |
| 95 | */ |
| 96 | @Override |
| 97 | public String getCacheControl() { |
| 98 | return null; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | *{@inheritDoc} |
| 103 | */ |
| 104 | @Override |
| 105 | public Date getLastModified() { |
| 106 | return lastModified; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | *{@inheritDoc} |
| 111 | */ |
| 112 | @Override |
| 113 | public String getETag() { |
| 114 | return eTag; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | *{@inheritDoc} |
| 119 | */ |
| 120 | @Override |
| 121 | public int compareTo(ObjectMetadata o) { |
| 122 | return (this == o) ? 0 : getETag().compareTo(o.getETag()); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | *{@inheritDoc} |
| 127 | */ |
| 128 | @Override |
| 129 | public Map<String, String> getUserMetadata() { |
| 130 | return ImmutableMap.of(); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | *{@inheritDoc} |
| 135 | */ |
| 136 | @Override |
| 137 | public ContentMetadata getContentMetadata() { |
| 138 | return contentMetadata; |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public int hashCode() { |
| 143 | final int prime = 31; |
| 144 | int result = 1; |
| 145 | result = prime * result + ((eTag == null) ? 0 : eTag.hashCode()); |
| 146 | result = prime * result + ((lastModified == null) ? 0 : lastModified.hashCode()); |
| 147 | return result; |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public boolean equals(Object obj) { |
| 152 | if (this == obj) |
| 153 | return true; |
| 154 | if (obj == null) |
| 155 | return false; |
| 156 | if (getClass() != obj.getClass()) |
| 157 | return false; |
| 158 | CopyObjectResult other = (CopyObjectResult) obj; |
| 159 | if (eTag == null) { |
| 160 | if (other.eTag != null) |
| 161 | return false; |
| 162 | } else if (!eTag.equals(other.eTag)) |
| 163 | return false; |
| 164 | if (lastModified == null) { |
| 165 | if (other.lastModified != null) |
| 166 | return false; |
| 167 | } else if (!lastModified.equals(other.lastModified)) |
| 168 | return false; |
| 169 | return true; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public String toString() { |
| 174 | return String.format("[eTag=%s, lastModified=%s]", eTag, lastModified); |
| 175 | } |
| 176 | |
| 177 | } |