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 @Deprecated(since = "4.0.0")
31 class DefaultModelCache implements ModelCache {
32
33 private final RepositorySystemSession session;
34
35 private final RepositoryCache cache;
36
37 public static ModelCache newInstance(RepositorySystemSession session) {
38 if (session.getCache() == null) {
39 return null;
40 } else {
41 return new DefaultModelCache(session);
42 }
43 }
44
45 private DefaultModelCache(RepositorySystemSession session) {
46 this.session = session;
47 this.cache = session.getCache();
48 }
49
50 @Override
51 public Object get(String groupId, String artifactId, String version, String tag) {
52 return cache.get(session, new Key(groupId, artifactId, version, tag));
53 }
54
55 @Override
56 public void put(String groupId, String artifactId, String version, String tag, Object data) {
57 cache.put(session, new Key(groupId, artifactId, version, tag), data);
58 }
59
60 static class Key {
61
62 private final String groupId;
63
64 private final String artifactId;
65
66 private final String version;
67
68 private final String tag;
69
70 private final int hash;
71
72 Key(String groupId, String artifactId, String version, String tag) {
73 this.groupId = groupId;
74 this.artifactId = artifactId;
75 this.version = version;
76 this.tag = tag;
77
78 int h = 17;
79 h = h * 31 + this.groupId.hashCode();
80 h = h * 31 + this.artifactId.hashCode();
81 h = h * 31 + this.version.hashCode();
82 h = h * 31 + this.tag.hashCode();
83 hash = h;
84 }
85
86 @Override
87 public boolean equals(Object obj) {
88 if (this == obj) {
89 return true;
90 }
91 if (null == obj || !getClass().equals(obj.getClass())) {
92 return false;
93 }
94
95 Key that = (Key) obj;
96 return artifactId.equals(that.artifactId)
97 && groupId.equals(that.groupId)
98 && version.equals(that.version)
99 && tag.equals(that.tag);
100 }
101
102 @Override
103 public int hashCode() {
104 return hash;
105 }
106 }
107 }