1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.internal;
20
21 import org.apache.maven.model.building.ModelCache;
22 import org.eclipse.aether.RepositoryCache;
23 import org.eclipse.aether.RepositorySystemSession;
24
25
26
27
28
29
30 class DefaultModelCache implements ModelCache {
31
32 private final RepositorySystemSession session;
33
34 private final RepositoryCache cache;
35
36 public static ModelCache newInstance(RepositorySystemSession session) {
37 if (session.getCache() == null) {
38 return null;
39 } else {
40 return new DefaultModelCache(session);
41 }
42 }
43
44 private DefaultModelCache(RepositorySystemSession session) {
45 this.session = session;
46 this.cache = session.getCache();
47 }
48
49 public Object get(String groupId, String artifactId, String version, String tag) {
50 return cache.get(session, new Key(groupId, artifactId, version, tag));
51 }
52
53 public void put(String groupId, String artifactId, String version, String tag, Object data) {
54 cache.put(session, new Key(groupId, artifactId, version, tag), data);
55 }
56
57 static class Key {
58
59 private final String groupId;
60
61 private final String artifactId;
62
63 private final String version;
64
65 private final String tag;
66
67 private final int hash;
68
69 Key(String groupId, String artifactId, String version, String tag) {
70 this.groupId = groupId;
71 this.artifactId = artifactId;
72 this.version = version;
73 this.tag = tag;
74
75 int h = 17;
76 h = h * 31 + this.groupId.hashCode();
77 h = h * 31 + this.artifactId.hashCode();
78 h = h * 31 + this.version.hashCode();
79 h = h * 31 + this.tag.hashCode();
80 hash = h;
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj) {
86 return true;
87 }
88 if (null == obj || !getClass().equals(obj.getClass())) {
89 return false;
90 }
91
92 Key that = (Key) obj;
93 return artifactId.equals(that.artifactId)
94 && groupId.equals(that.groupId)
95 && version.equals(that.version)
96 && tag.equals(that.tag);
97 }
98
99 @Override
100 public int hashCode() {
101 return hash;
102 }
103 }
104 }