View Javadoc

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.azureblob.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.azureblob.domain.BlobProperties;
31  import org.jclouds.azureblob.domain.BlobType;
32  import org.jclouds.azureblob.domain.LeaseStatus;
33  import org.jclouds.io.ContentMetadata;
34  import org.jclouds.io.payloads.BaseImmutableContentMetadata;
35  
36  import com.google.common.collect.Maps;
37  
38  /**
39   * Allows you to manipulate metadata.
40   * 
41   * @author Adrian Cole
42   */
43  public class BlobPropertiesImpl implements Serializable, BlobProperties {
44  
45     /** The serialVersionUID */
46     private static final long serialVersionUID = -4648755473986695062L;
47     private final BlobType type;
48     private final String name;
49     private final String container;
50     private final URI url;
51     private final Date lastModified;
52     private final String eTag;
53     private final Map<String, String> metadata = Maps.newLinkedHashMap();
54     private final LeaseStatus leaseStatus;
55     private final BaseImmutableContentMetadata contentMetadata;
56  
57     public BlobPropertiesImpl(BlobType type, String name, String container, URI url, Date lastModified, String eTag,
58              long size, String contentType, @Nullable byte[] contentMD5, @Nullable String contentMetadata,
59              @Nullable String contentLanguage, LeaseStatus leaseStatus, Map<String, String> metadata) {
60        this.type = checkNotNull(type, "type");
61        this.leaseStatus = checkNotNull(leaseStatus, "leaseStatus");
62        this.name = checkNotNull(name, "name");
63        this.container = checkNotNull(container, "container");
64        this.url = checkNotNull(url, "url");
65        this.lastModified = checkNotNull(lastModified, "lastModified");
66        this.eTag = checkNotNull(eTag, "eTag");
67        this.contentMetadata = new BaseImmutableContentMetadata(contentType, size, contentMD5, null, contentLanguage,
68                 contentMetadata);
69        this.metadata.putAll(checkNotNull(metadata, "metadata"));
70     }
71  
72     /**
73      *{@inheritDoc}
74      */
75     @Override
76     public BlobType getType() {
77        return type;
78     }
79  
80     /**
81      *{@inheritDoc}
82      */
83     @Override
84     public String getName() {
85        return name;
86     }
87  
88     /**
89      *{@inheritDoc}
90      */
91     @Override
92     public String getContainer() {
93        return container;
94     }
95  
96     /**
97      *{@inheritDoc}
98      */
99     @Override
100    public Date getLastModified() {
101       return lastModified;
102    }
103 
104    /**
105     *{@inheritDoc}
106     */
107    @Override
108    public String getETag() {
109       return eTag;
110    }
111 
112    /**
113     *{@inheritDoc}
114     */
115    @Override
116    public int compareTo(BlobProperties o) {
117       return (this == o) ? 0 : getName().compareTo(o.getName());
118    }
119 
120    /**
121     *{@inheritDoc}
122     */
123    @Override
124    public Map<String, String> getMetadata() {
125       return metadata;
126    }
127 
128    /**
129     *{@inheritDoc}
130     */
131    @Override
132    public URI getUrl() {
133       return url;
134    }
135 
136    /**
137     *{@inheritDoc}
138     */
139    @Override
140    public LeaseStatus getLeaseStatus() {
141       return leaseStatus;
142    }
143 
144    /**
145     *{@inheritDoc}
146     */
147    @Override
148    public ContentMetadata getContentMetadata() {
149       return contentMetadata;
150    }
151 
152    @Override
153    public int hashCode() {
154       final int prime = 31;
155       int result = 1;
156       result = prime * result + ((url == null) ? 0 : url.hashCode());
157       return result;
158    }
159 
160    @Override
161    public boolean equals(Object obj) {
162       if (this == obj)
163          return true;
164       if (obj == null)
165          return false;
166       if (getClass() != obj.getClass())
167          return false;
168       BlobPropertiesImpl other = (BlobPropertiesImpl) obj;
169       if (url == null) {
170          if (other.url != null)
171             return false;
172       } else if (!url.equals(other.url))
173          return false;
174       return true;
175    }
176 
177    @Override
178    public String toString() {
179       return String
180                .format(
181                         "[name=%s, container=%s, url=%s, contentMetadata=%s, eTag=%s, lastModified=%s, leaseStatus=%s, metadata=%s, type=%s]",
182                         name, container, url, contentMetadata, eTag, lastModified, leaseStatus, metadata, type);
183    }
184 }