1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.project;
20
21 import java.util.Map;
22 import java.util.concurrent.ConcurrentHashMap;
23
24 import org.apache.maven.model.building.ModelCache;
25
26
27
28
29
30
31 class ReactorModelCache implements ModelCache {
32
33 private final Map<CacheKey, Object> models = new ConcurrentHashMap<>(256);
34
35 public Object get(String groupId, String artifactId, String version, String tag) {
36 return models.get(new CacheKey(groupId, artifactId, version, tag));
37 }
38
39 public void put(String groupId, String artifactId, String version, String tag, Object data) {
40 models.put(new CacheKey(groupId, artifactId, version, tag), data);
41 }
42
43 private static final class CacheKey {
44
45 private final String groupId;
46
47 private final String artifactId;
48
49 private final String version;
50
51 private final String tag;
52
53 private final int hashCode;
54
55 CacheKey(String groupId, String artifactId, String version, String tag) {
56 this.groupId = (groupId != null) ? groupId : "";
57 this.artifactId = (artifactId != null) ? artifactId : "";
58 this.version = (version != null) ? version : "";
59 this.tag = (tag != null) ? tag : "";
60
61 int hash = 17;
62 hash = hash * 31 + this.groupId.hashCode();
63 hash = hash * 31 + this.artifactId.hashCode();
64 hash = hash * 31 + this.version.hashCode();
65 hash = hash * 31 + this.tag.hashCode();
66 hashCode = hash;
67 }
68
69 @Override
70 public boolean equals(Object obj) {
71 if (this == obj) {
72 return true;
73 }
74
75 if (!(obj instanceof CacheKey)) {
76 return false;
77 }
78
79 CacheKey that = (CacheKey) obj;
80
81 return artifactId.equals(that.artifactId)
82 && groupId.equals(that.groupId)
83 && version.equals(that.version)
84 && tag.equals(that.tag);
85 }
86
87 @Override
88 public int hashCode() {
89 return hashCode;
90 }
91 }
92 }