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