xref: /aosp_15_r20/external/cldr/tools/cldr-code/src/main/java/org/unicode/cldr/util/RecordingCLDRFile.java (revision 912701f9769bb47905792267661f0baf2b85bed5)
1 package org.unicode.cldr.util;
2 
3 import java.util.HashSet;
4 
5 /**
6  * Like CLDRFile, with an added feature for recording the paths for which getStringValue, etc., are
7  * called.
8  *
9  * <p>The first intended usage is for GenerateExampleDependencies, to identify all the paths on
10  * which a given example depends. Before calling ExampleGenerator.getExampleHtml,
11  * GenerateExampleDependencies calls clearRecordedPaths. After getting each example,
12  * GenerateExampleDependencies calls getRecordedPaths to get the set of all paths in this file that
13  * were accessed to generate the example.
14  */
15 public class RecordingCLDRFile extends CLDRFile {
16     private HashSet<String> recordedPaths = new HashSet<>();
17 
RecordingCLDRFile(XMLSource dataSource)18     public RecordingCLDRFile(XMLSource dataSource) {
19         super(dataSource);
20     }
21 
RecordingCLDRFile(XMLSource dataSource, XMLSource... resolvingParents)22     public RecordingCLDRFile(XMLSource dataSource, XMLSource... resolvingParents) {
23         super(dataSource, resolvingParents);
24     }
25 
clearRecordedPaths()26     public void clearRecordedPaths() {
27         recordedPaths.clear();
28     }
29 
getRecordedPaths()30     public HashSet<String> getRecordedPaths() {
31         return recordedPaths;
32     }
33 
34     @Override
getStringValue(String xpath)35     public String getStringValue(String xpath) {
36         recordPath(xpath);
37         return super.getStringValue(xpath);
38     }
39 
40     @Override
getWinningValue(String xpath)41     public String getWinningValue(String xpath) {
42         recordPath(xpath);
43         return super.getWinningValue(xpath);
44     }
45 
46     @Override
getConstructedValue(String xpath)47     public String getConstructedValue(String xpath) {
48         recordPath(xpath);
49         return super.getConstructedValue(xpath);
50     }
51 
recordPath(String xpath)52     private void recordPath(String xpath) {
53         recordedPaths.add(xpath);
54     }
55 }
56