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 @Override
50 public Object get(String groupId, String artifactId, String version, String tag) {
51 return cache.get(session, new Key(groupId, artifactId, version, tag));
52 }
53
54 @Override
55 public void put(String groupId, String artifactId, String version, String tag, Object data) {
56 cache.put(session, new Key(groupId, artifactId, version, tag), data);
57 }
58
59 static class Key {
60
61 private final String groupId;
62
63 private final String artifactId;
64
65 private final String version;
66
67 private final String tag;
68
69 private final int hash;
70
71 Key(String groupId, String artifactId, String version, String tag) {
72 this.groupId = groupId;
73 this.artifactId = artifactId;
74 this.version = version;
75 this.tag = tag;
76
77 int h = 17;
78 h = h * 31 + this.groupId.hashCode();
79 h = h * 31 + this.artifactId.hashCode();
80 h = h * 31 + this.version.hashCode();
81 h = h * 31 + this.tag.hashCode();
82 hash = h;
83 }
84
85 @Override
86 public boolean equals(Object obj) {
87 if (this == obj) {
88 return true;
89 }
90 if (null == obj || !getClass().equals(obj.getClass())) {
91 return false;
92 }
93
94 Key that = (Key) obj;
95 return artifactId.equals(that.artifactId)
96 && groupId.equals(that.groupId)
97 && version.equals(that.version)
98 && tag.equals(that.tag);
99 }
100
101 @Override
102 public int hashCode() {
103 return hash;
104 }
105 }
106 }