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