1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl.collect;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.eclipse.aether.RepositorySystemSession;
25 import org.eclipse.aether.artifact.ArtifactType;
26 import org.eclipse.aether.artifact.ArtifactTypeRegistry;
27
28
29
30
31
32 public class CachingArtifactTypeRegistry implements ArtifactTypeRegistry {
33
34 private final ArtifactTypeRegistry delegate;
35
36 private final Map<String, ArtifactType> types;
37
38 public static ArtifactTypeRegistry newInstance(RepositorySystemSession session) {
39 return newInstance(session.getArtifactTypeRegistry());
40 }
41
42 public static ArtifactTypeRegistry newInstance(ArtifactTypeRegistry delegate) {
43 return (delegate != null) ? new CachingArtifactTypeRegistry(delegate) : null;
44 }
45
46 private CachingArtifactTypeRegistry(ArtifactTypeRegistry delegate) {
47 this.delegate = delegate;
48 types = new HashMap<>();
49 }
50
51 public ArtifactType get(String typeId) {
52 ArtifactType type = types.get(typeId);
53
54 if (type == null) {
55 type = delegate.get(typeId);
56 types.put(typeId, type);
57 }
58
59 return type;
60 }
61 }