| 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 static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import javax.inject.Inject; |
| 24 | |
| 25 | import org.jclouds.azureblob.domain.AzureBlob; |
| 26 | import org.jclouds.azureblob.domain.MutableBlobProperties; |
| 27 | import org.jclouds.http.internal.PayloadEnclosingImpl; |
| 28 | import org.jclouds.io.Payload; |
| 29 | |
| 30 | import com.google.common.collect.LinkedHashMultimap; |
| 31 | import com.google.common.collect.Multimap; |
| 32 | |
| 33 | /** |
| 34 | * Default Implementation of {@link AzureBlob}. |
| 35 | * |
| 36 | * @author Adrian Cole |
| 37 | */ |
| 38 | public class AzureBlobImpl extends PayloadEnclosingImpl implements AzureBlob, Comparable<AzureBlob> { |
| 39 | |
| 40 | private final MutableBlobProperties properties; |
| 41 | private Multimap<String, String> allHeaders = LinkedHashMultimap.create(); |
| 42 | |
| 43 | @Inject |
| 44 | public AzureBlobImpl(MutableBlobProperties properties) { |
| 45 | super(); |
| 46 | this.properties = properties; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * {@inheritDoc} |
| 51 | */ |
| 52 | @Override |
| 53 | public MutableBlobProperties getProperties() { |
| 54 | return properties; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * {@inheritDoc} |
| 59 | */ |
| 60 | @Override |
| 61 | public Multimap<String, String> getAllHeaders() { |
| 62 | return allHeaders; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * {@inheritDoc} |
| 67 | */ |
| 68 | @Override |
| 69 | public void setAllHeaders(Multimap<String, String> allHeaders) { |
| 70 | this.allHeaders = checkNotNull(allHeaders, "allHeaders"); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * {@inheritDoc} |
| 75 | */ |
| 76 | @Override |
| 77 | public int compareTo(AzureBlob o) { |
| 78 | if (getProperties().getName() == null) |
| 79 | return -1; |
| 80 | return (this == o) ? 0 : getProperties().getName().compareTo(o.getProperties().getName()); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public int hashCode() { |
| 85 | final int prime = 31; |
| 86 | int result = super.hashCode(); |
| 87 | result = prime * result + ((properties == null) ? 0 : properties.hashCode()); |
| 88 | return result; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public boolean equals(Object obj) { |
| 93 | if (this == obj) |
| 94 | return true; |
| 95 | if (!super.equals(obj)) |
| 96 | return false; |
| 97 | if (getClass() != obj.getClass()) |
| 98 | return false; |
| 99 | AzureBlobImpl other = (AzureBlobImpl) obj; |
| 100 | if (properties == null) { |
| 101 | if (other.properties != null) |
| 102 | return false; |
| 103 | } else if (!properties.equals(other.properties)) |
| 104 | return false; |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public String toString() { |
| 110 | return "[properties=" + properties + "]"; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public void setPayload(Payload data) { |
| 115 | super.setPayload(data); |
| 116 | properties.setContentMetadata(data.getContentMetadata()); |
| 117 | } |
| 118 | |
| 119 | } |