1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.trendmicro.grid.acl.ds.cache.translation;
18
19 import com.trendmicro.grid.acl.ds.cache.CacheSettings;
20 import com.trendmicro.grid.acl.l0.datatypes.FileIdentifier;
21 import com.trendmicro.grid.acl.l0.datatypes.PackageDetails;
22 import com.trendmicro.grid.acl.l0.datatypes.PackageInformation;
23
24 import java.util.Map;
25
26
27
28
29
30
31
32 public class IdentifierToNameTranslator<V> extends Translator<FileIdentifier, V, String, V> {
33
34 Map<FileIdentifier, String> identifiersToNames;
35
36
37
38
39
40
41 public IdentifierToNameTranslator(Map<FileIdentifier, String> identifiersToNames) {
42 this.identifiersToNames = identifiersToNames;
43 }
44
45
46
47
48 @Override
49 protected String toDelegateKey(FileIdentifier key, V value) {
50 if (value instanceof PackageDetails) {
51 PackageInformation info = ((PackageDetails) value).getPackageInformation();
52 return info == null ? null : info.getName();
53 }
54
55 if (value instanceof PackageInformation) {
56 return ((PackageInformation) value).getName();
57 }
58
59 return identifiersToNames.get(key);
60 }
61
62
63
64
65 @Override
66 protected V toDelegateValue(FileIdentifier key, String delegateKey, V delegateValue) {
67 if (!CacheSettings.DISABLED && key != null && delegateKey != null)
68 identifiersToNames.put(key, delegateKey);
69 return delegateValue;
70 }
71 }