This project has retired. For details please refer to its
Attic page.
ArtifactMetadata xref
1 package org.apache.archiva.metadata.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.archiva.checksum.ChecksumAlgorithm;
23 import org.apache.commons.collections4.bidimap.DualHashBidiMap;
24
25 import javax.xml.bind.annotation.XmlRootElement;
26 import java.time.Instant;
27 import java.time.ZonedDateTime;
28 import java.time.temporal.ChronoUnit;
29 import java.time.temporal.TemporalUnit;
30 import java.util.Map;
31 import java.util.Set;
32 import java.util.stream.Collectors;
33
34
35
36
37
38
39
40
41
42 @XmlRootElement(name = "artifactMetadata")
43 public class ArtifactMetadata
44 extends FacetedMetadata {
45
46
47
48
49
50
51 private String id;
52
53
54
55
56 private String repositoryId;
57
58
59
60
61
62
63 private String namespace;
64
65
66
67
68
69
70 private String project;
71
72
73
74
75
76
77 private String projectVersion;
78
79
80
81
82
83
84 private String version;
85
86
87
88
89 private ZonedDateTime fileLastModified;
90
91
92
93
94 private long size;
95
96
97
98
99 private Map<ChecksumAlgorithm, String> checksums = new DualHashBidiMap<>( );
100
101 private String toStringValue = "";
102 private int lastHash = 0;
103
104
105
106
107 private ZonedDateTime whenGathered;
108
109 public String getId() {
110 return id;
111 }
112
113 public void setId(String id) {
114 this.id = id;
115 }
116
117 public long getSize() {
118 return size;
119 }
120
121 public void setSize(long size) {
122 this.size = size;
123 }
124
125 public String getVersion() {
126 return version;
127 }
128
129 public void setVersion(String version) {
130 this.version = version;
131 }
132
133 public String getProjectVersion() {
134 return projectVersion;
135 }
136
137 public void setProjectVersion(String projectVersion) {
138 this.projectVersion = projectVersion;
139 }
140
141 public void setFileLastModified(long fileLastModified) {
142 this.fileLastModified = ZonedDateTime.ofInstant(Instant.ofEpochMilli(fileLastModified), ModelInfo.STORAGE_TZ);
143 }
144
145 public void setWhenGathered(ZonedDateTime whenGathered) {
146
147 this.whenGathered = whenGathered.withZoneSameInstant(ModelInfo.STORAGE_TZ).truncatedTo(ChronoUnit.MILLIS);
148 }
149
150 public void setMd5(String md5) {
151 this.checksums.put(ChecksumAlgorithm.MD5, md5);
152 }
153
154 public void setSha1(String sha1) {
155 this.checksums.put(ChecksumAlgorithm.SHA1, sha1);
156 }
157
158 public ZonedDateTime getWhenGathered() {
159 return whenGathered;
160 }
161
162 public String getChecksum(ChecksumAlgorithm checksumAlgorithm) {
163 return checksums.get(checksumAlgorithm);
164 }
165
166 public void setChecksum(ChecksumAlgorithm algorithm, String checksumValue) {
167 this.checksums.put(algorithm, checksumValue);
168 }
169
170 public Set<ChecksumAlgorithm> getChecksumTypes() {
171 return checksums.keySet();
172 }
173
174 public Map<ChecksumAlgorithm,String> getChecksums() {
175 return this.checksums;
176 }
177
178 public boolean hasChecksum(String checksum) {
179 return this.checksums.containsValue( checksum );
180 }
181
182 public void setChecksums(Map<ChecksumAlgorithm,String> checksums) {
183 this.checksums = checksums;
184 }
185
186 public String getMd5() {
187 return checksums.get(ChecksumAlgorithm.MD5);
188 }
189
190 public String getSha1() {
191 return checksums.get(ChecksumAlgorithm.SHA1);
192 }
193
194 public ZonedDateTime getFileLastModified() {
195
196 return fileLastModified;
197 }
198
199 public String getNamespace() {
200 return namespace;
201 }
202
203 public void setNamespace(String namespace) {
204 this.namespace = namespace;
205 }
206
207 public void setProject(String project) {
208 this.project = project;
209 }
210
211 public String getProject() {
212 return project;
213 }
214
215 public String getRepositoryId() {
216 return repositoryId;
217 }
218
219 public void setRepositoryId(String repositoryId) {
220 this.repositoryId = repositoryId;
221 }
222
223 @Override
224 public boolean equals(Object o) {
225 if (this == o) {
226 return true;
227 }
228 if (o == null || getClass() != o.getClass()) {
229 return false;
230 }
231
232 ArtifactMetadata/../../org/apache/archiva/metadata/model/ArtifactMetadata.html#ArtifactMetadata">ArtifactMetadata that = (ArtifactMetadata) o;
233
234 if (size != that.size) {
235 return false;
236 }
237
238 if (fileLastModified != null
239 ? !fileLastModified.toInstant().equals(that.fileLastModified.toInstant())
240 : that.fileLastModified != null) {
241 return false;
242 }
243 if (!id.equals(that.id)) {
244 return false;
245 }
246 for ( Map.Entry<ChecksumAlgorithm, String> entry : this.checksums.entrySet()) {
247 String thatChecksum = that.checksums.get(entry.getKey());
248 if (entry.getValue()!=null ? !entry.getValue().equals(thatChecksum) : thatChecksum!=null) {
249 return false;
250 }
251 }
252 if (namespace != null ? !namespace.equals(that.namespace) : that.namespace != null) {
253 return false;
254 }
255 if (project != null ? !project.equals(that.project) : that.project != null) {
256 return false;
257 }
258 if (projectVersion != null ? !projectVersion.equals(that.projectVersion) : that.projectVersion != null) {
259 return false;
260 }
261
262
263
264
265
266
267
268 if (version != null ? !version.equals(that.version) : that.version != null) {
269 return false;
270 }
271 if (whenGathered != null ? !whenGathered.toInstant().equals(that.whenGathered.toInstant()) : that.whenGathered != null) {
272 return false;
273 }
274
275 return true;
276 }
277
278 @Override
279 public int hashCode() {
280 int result = id != null ? id.hashCode() : 0;
281 result = 31 * result + (repositoryId != null ? repositoryId.hashCode() : 0);
282 result = 31 * result + (namespace != null ? namespace.hashCode() : 0);
283 result = 31 * result + (project != null ? project.hashCode() : 0);
284 result = 31 * result + (projectVersion != null ? projectVersion.hashCode() : 0);
285 result = 31 * result + (version != null ? version.hashCode() : 0);
286 result = 31 * result + (fileLastModified != null ? fileLastModified.hashCode() : 0);
287 result = 31 * result + (int) (size ^ (size >>> 32));
288 for (String checksum : checksums.values()) {
289 result = 31 * result + (checksum != null ? checksum.hashCode() : 0);
290 }
291 result = 31 * result + (whenGathered != null ? whenGathered.hashCode() : 0);
292 return result;
293 }
294
295
296
297
298 @Override
299 public String toString() {
300 final int hashCode=hashCode();
301 if (hashCode!=lastHash) {
302 toStringValue = "ArtifactMetadata{" + "id='" + id + '\'' + ", size=" + size + ", version='" + version + '\'' +
303 ", fileLastModified=" + fileLastModified + ", whenGathered=" + whenGathered +
304 ", namespace='" + namespace + '\'' + ", project='" + project + '\'' +
305 ", projectVersion='" + projectVersion + '\'' + ", repositoryId='" + repositoryId + '\'' +
306 ", checksums=" + checksums.entrySet().stream().map(e -> e.getKey() + ":" + e.getValue()).collect(Collectors.joining(",")) +
307 '}';
308 lastHash=hashCode;
309 }
310 return toStringValue;
311 }
312 }