1 package org.apache.maven.project;
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
24 import java.util.Map;
25 import java.util.concurrent.ConcurrentHashMap;
26
27
28
29
30
31
32 class ReactorModelCache
33 implements ModelCache
34 {
35
36 private final Map<CacheKey, Object> models = new ConcurrentHashMap<>( 256 );
37
38 public Object get( String groupId, String artifactId, String version, String tag )
39 {
40 return models.get( new CacheKey( groupId, artifactId, version, tag ) );
41 }
42
43 public void put( String groupId, String artifactId, String version, String tag, Object data )
44 {
45 models.put( new CacheKey( groupId, artifactId, version, tag ), data );
46 }
47
48 private static final class CacheKey
49 {
50
51 private final String groupId;
52
53 private final String artifactId;
54
55 private final String version;
56
57 private final String tag;
58
59 private final int hashCode;
60
61 CacheKey( String groupId, String artifactId, String version, String tag )
62 {
63 this.groupId = ( groupId != null ) ? groupId : "";
64 this.artifactId = ( artifactId != null ) ? artifactId : "";
65 this.version = ( version != null ) ? version : "";
66 this.tag = ( tag != null ) ? tag : "";
67
68 int hash = 17;
69 hash = hash * 31 + this.groupId.hashCode();
70 hash = hash * 31 + this.artifactId.hashCode();
71 hash = hash * 31 + this.version.hashCode();
72 hash = hash * 31 + this.tag.hashCode();
73 hashCode = hash;
74 }
75
76 @Override
77 public boolean equals( Object obj )
78 {
79 if ( this == obj )
80 {
81 return true;
82 }
83
84 if ( !( obj instanceof CacheKey ) )
85 {
86 return false;
87 }
88
89 CacheKey that = (CacheKey) obj;
90
91 return artifactId.equals( that.artifactId ) && groupId.equals( that.groupId )
92 && version.equals( that.version ) && tag.equals( that.tag );
93 }
94
95 @Override
96 public int hashCode()
97 {
98 return hashCode;
99 }
100
101 }
102
103 }