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.openstack.swift.domain.internal; |
20 | |
21 | import java.util.Arrays; |
22 | import java.util.Date; |
23 | import java.util.Map; |
24 | |
25 | import javax.ws.rs.core.MediaType; |
26 | |
27 | import org.jclouds.openstack.swift.domain.MutableObjectInfoWithMetadata; |
28 | import org.jclouds.openstack.swift.domain.ObjectInfo; |
29 | |
30 | import com.google.common.collect.Maps; |
31 | |
32 | /** |
33 | * |
34 | * @author Adrian Cole |
35 | * |
36 | */ |
37 | public class MutableObjectInfoWithMetadataImpl implements MutableObjectInfoWithMetadata { |
38 | private String name; |
39 | private Long bytes; |
40 | private byte[] hash; |
41 | private String contentType = MediaType.APPLICATION_OCTET_STREAM; |
42 | private Date lastModified; |
43 | private final Map<String, String> metadata = Maps.newHashMap(); |
44 | |
45 | public Map<String, String> getMetadata() { |
46 | return metadata; |
47 | } |
48 | |
49 | public void setBytes(Long bytes) { |
50 | this.bytes = bytes; |
51 | } |
52 | |
53 | public void setContentType(String contentType) { |
54 | this.contentType = contentType; |
55 | } |
56 | |
57 | public void setHash(byte[] hash) { |
58 | this.hash = hash; |
59 | } |
60 | |
61 | public void setName(String name) { |
62 | this.name = name; |
63 | } |
64 | |
65 | public Long getBytes() { |
66 | return bytes; |
67 | } |
68 | |
69 | public String getContentType() { |
70 | return contentType; |
71 | } |
72 | |
73 | public byte[] getHash() { |
74 | return hash; |
75 | } |
76 | |
77 | public Date getLastModified() { |
78 | return lastModified; |
79 | } |
80 | |
81 | @Override |
82 | public int hashCode() { |
83 | final int prime = 31; |
84 | int result = 1; |
85 | result = prime * result + ((bytes == null) ? 0 : bytes.hashCode()); |
86 | result = prime * result + ((contentType == null) ? 0 : contentType.hashCode()); |
87 | result = prime * result + Arrays.hashCode(hash); |
88 | result = prime * result + ((lastModified == null) ? 0 : lastModified.hashCode()); |
89 | result = prime * result + ((metadata == null) ? 0 : metadata.hashCode()); |
90 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
91 | return result; |
92 | } |
93 | |
94 | @Override |
95 | public boolean equals(Object obj) { |
96 | if (this == obj) |
97 | return true; |
98 | if (obj == null) |
99 | return false; |
100 | if (getClass() != obj.getClass()) |
101 | return false; |
102 | MutableObjectInfoWithMetadataImpl other = (MutableObjectInfoWithMetadataImpl) obj; |
103 | if (bytes == null) { |
104 | if (other.bytes != null) |
105 | return false; |
106 | } else if (!bytes.equals(other.bytes)) |
107 | return false; |
108 | if (contentType == null) { |
109 | if (other.contentType != null) |
110 | return false; |
111 | } else if (!contentType.equals(other.contentType)) |
112 | return false; |
113 | if (!Arrays.equals(hash, other.hash)) |
114 | return false; |
115 | if (lastModified == null) { |
116 | if (other.lastModified != null) |
117 | return false; |
118 | } else if (!lastModified.equals(other.lastModified)) |
119 | return false; |
120 | if (metadata == null) { |
121 | if (other.metadata != null) |
122 | return false; |
123 | } else if (!metadata.equals(other.metadata)) |
124 | return false; |
125 | if (name == null) { |
126 | if (other.name != null) |
127 | return false; |
128 | } else if (!name.equals(other.name)) |
129 | return false; |
130 | return true; |
131 | } |
132 | |
133 | public String getName() { |
134 | return name; |
135 | } |
136 | |
137 | public int compareTo(ObjectInfo o) { |
138 | return (this == o) ? 0 : getName().compareTo(o.getName()); |
139 | } |
140 | |
141 | public void setLastModified(Date lastModified) { |
142 | this.lastModified = lastModified; |
143 | } |
144 | |
145 | } |