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 7 * getStringValue, etc., are called. 8 * 9 * The first intended usage is for TestExampleDependencies, to identify all the paths on 10 * which a given example depends. Before calling ExampleGenerator.getExampleHtml, TestExampleDependencies 11 * calls clearRecordedPaths. After getting each example, TestExampleDependencies calls getRecordedPaths 12 * to get the set of all paths in this file that were accessed to generate the example. 13 */ 14 public class RecordingCLDRFile extends CLDRFile { 15 private HashSet<String> recordedPaths = new HashSet<>(); 16 RecordingCLDRFile(XMLSource dataSource)17 public RecordingCLDRFile(XMLSource dataSource) { 18 super(dataSource); 19 } 20 RecordingCLDRFile(XMLSource dataSource, XMLSource... resolvingParents)21 public RecordingCLDRFile(XMLSource dataSource, XMLSource... resolvingParents) { 22 super(dataSource, resolvingParents); 23 } 24 clearRecordedPaths()25 public void clearRecordedPaths() { 26 recordedPaths.clear(); 27 } 28 getRecordedPaths()29 public HashSet<String> getRecordedPaths() { 30 return recordedPaths; 31 } 32 33 @Override getStringValue(String xpath)34 public String getStringValue(String xpath) { 35 recordPath(xpath); 36 return super.getStringValue(xpath); 37 } 38 39 @Override getWinningValue(String xpath)40 public String getWinningValue(String xpath) { 41 recordPath(xpath); 42 return super.getWinningValue(xpath); 43 } 44 45 @Override getConstructedValue(String xpath)46 public String getConstructedValue(String xpath) { 47 recordPath(xpath); 48 return super.getConstructedValue(xpath); 49 } 50 recordPath(String xpath)51 private void recordPath(String xpath) { 52 recordedPaths.add(xpath); 53 } 54 } 55