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.io.File;
22 import java.util.HashMap;
23 import java.util.Map;
24
25
26
27
28
29
30
31 class ReactorModelPool {
32
33 private final Map<CacheKey, File> pomFiles = new HashMap<>();
34
35 public File get(String groupId, String artifactId, String version) {
36 return pomFiles.get(new CacheKey(groupId, artifactId, version));
37 }
38
39 public void put(String groupId, String artifactId, String version, File pomFile) {
40 pomFiles.put(new CacheKey(groupId, artifactId, version), pomFile);
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 int hashCode;
52
53 CacheKey(String groupId, String artifactId, String version) {
54 this.groupId = (groupId != null) ? groupId : "";
55 this.artifactId = (artifactId != null) ? artifactId : "";
56 this.version = (version != null) ? version : "";
57
58 int hash = 17;
59 hash = hash * 31 + this.groupId.hashCode();
60 hash = hash * 31 + this.artifactId.hashCode();
61 hash = hash * 31 + this.version.hashCode();
62 hashCode = hash;
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70
71 if (!(obj instanceof CacheKey)) {
72 return false;
73 }
74
75 CacheKey that = (CacheKey) obj;
76
77 return artifactId.equals(that.artifactId) && groupId.equals(that.groupId) && version.equals(that.version);
78 }
79
80 @Override
81 public int hashCode() {
82 return hashCode;
83 }
84
85 @Override
86 public String toString() {
87 StringBuilder buffer = new StringBuilder(128);
88 buffer.append(groupId).append(':').append(artifactId).append(':').append(version);
89 return buffer.toString();
90 }
91 }
92 }