[Unicode]   Common Locale Data Repository : Bug Tracking Home | Site Map | Search
 

Changeset 9579


Ignore:
Timestamp:
12/20/13 03:25:20 (5 years ago)
Author:
markdavis
Message:

cldrbug 6426: fix the comparator (min/max problem)

Location:
trunk/tools/java/org/unicode/cldr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/java/org/unicode/cldr/unittest/TestBasic.java

    r9510 r9579  
    66import java.util.ArrayList; 
    77import java.util.Arrays; 
     8import java.util.Collection; 
    89import java.util.Collections; 
     10import java.util.Comparator; 
    911import java.util.EnumSet; 
    1012import java.util.HashSet; 
     
    4749import org.unicode.cldr.util.SupplementalDataInfo.PluralInfo; 
    4850import org.unicode.cldr.util.SupplementalDataInfo.PluralType; 
     51import org.unicode.cldr.util.With; 
    4952import org.unicode.cldr.util.XMLFileReader; 
    5053import org.unicode.cldr.util.XPathParts; 
     
    917920        } 
    918921    } 
     922     
     923    /** 
     924     * Compare each path to each other path 
     925     */ 
     926    public void TestDtdComparison() { 
     927        CLDRFile f = testInfo.getEnglish(); 
     928        DtdData dtdData = DtdData.getInstance(DtdType.ldml); 
     929        Comparator<String> dc = dtdData.getDtdComparator(null); 
     930        sortPaths(dc, Arrays.asList( 
     931            "//ldml/dates/calendars/calendar[@type=\"generic\"]/dateTimeFormats/dateTimeFormatLength[@type=\"full\"]/dateTimeFormat[@type=\"standard\"]/pattern[@type=\"standard\"]",  
     932            "//ldml/dates/calendars/calendar[@type=\"generic\"]/dateTimeFormats")); 
     933         
     934        List<String> paths = With.in(f).toList(); 
     935        sortPaths(dc, paths); 
     936        // TODO one file of each type 
     937//        Map<DtdType, String> samples = null; 
     938//        Map<DtdType, String> samples = null; 
     939//        for (DtdType type : DtdType.values()) { 
     940//            String sample = samples.get(type); 
     941//            DtdData dtdData = DtdData.getInstance(type); 
     942//            dtdData 
     943//        }  
     944    } 
     945 
     946    public void sortPaths(Comparator<String> dc, Collection<String> paths) { 
     947        Arrays.sort(paths.toArray(new String[paths.size()]), 0, paths.size(), dc); 
     948    } 
    919949} 
  • trunk/tools/java/org/unicode/cldr/util/DtdData.java

    r9531 r9579  
    437437            XPathParts a = XPathParts.getFrozenInstance(path1); 
    438438            XPathParts b = XPathParts.getFrozenInstance(path2); 
    439             int max = Math.max(a.size(), b.size()); 
     439            // there must always be at least one element 
    440440            String baseA = a.getElement(0); 
    441441            String baseB = b.getElement(0); 
     
    443443                throw new IllegalArgumentException("Comparing two different DTDs: " + baseA + ", " + baseB); 
    444444            } 
     445            int min = Math.min(a.size(), b.size()); 
    445446            Element parent = ROOT; 
    446447            Element elementA; 
    447             for (int i = 1; i < max; ++i, parent = elementA) { 
     448            for (int i = 1; i < min; ++i, parent = elementA) { 
    448449                elementA = nameToElement.get(a.getElement(i)); 
    449450                Element elementB = nameToElement.get(b.getElement(i)); 
Note: See TracChangeset for help on using the changeset viewer.