Class LocaleDistance


  • public class LocaleDistance
    extends java.lang.Object
    Offline-built data for LocaleMatcher. Mostly but not only the data for mapping locales to their maximized forms.
    • Field Detail

      • END_OF_SUBTAG

        public static final int END_OF_SUBTAG
        Bit flag used on the last character of a subtag in the trie. Must be set consistently by the builder and the lookup code.
        See Also:
        Constant Field Values
      • DISTANCE_SKIP_SCRIPT

        public static final int DISTANCE_SKIP_SCRIPT
        Distance value bit flag, set by the builder.
        See Also:
        Constant Field Values
      • DISTANCE_IS_FINAL

        private static final int DISTANCE_IS_FINAL
        Distance value bit flag, set by trieNext().
        See Also:
        Constant Field Values
      • DISTANCE_IS_FINAL_OR_SKIP_SCRIPT

        private static final int DISTANCE_IS_FINAL_OR_SKIP_SCRIPT
        See Also:
        Constant Field Values
      • DISTANCE_FRACTION_MASK

        private static final int DISTANCE_FRACTION_MASK
        See Also:
        Constant Field Values
      • regionToPartitionsIndex

        private final byte[] regionToPartitionsIndex
        Maps each region to zero or more single-character partitions.
      • partitionArrays

        private final java.lang.String[] partitionArrays
      • paradigmLSRs

        private final java.util.Set<LSR> paradigmLSRs
        Used to get the paradigm region for a cluster, if there is one.
      • defaultLanguageDistance

        private final int defaultLanguageDistance
      • defaultScriptDistance

        private final int defaultScriptDistance
      • defaultRegionDistance

        private final int defaultRegionDistance
      • minRegionDistance

        private final int minRegionDistance
      • defaultDemotionPerDesiredLocale

        private final int defaultDemotionPerDesiredLocale
    • Method Detail

      • shiftDistance

        public static final int shiftDistance​(int distance)
      • getShiftedDistance

        public static final int getShiftedDistance​(int indexAndDistance)
      • getDistanceDouble

        public static final double getDistanceDouble​(int indexAndDistance)
      • getDistanceFloor

        public static final int getDistanceFloor​(int indexAndDistance)
      • getIndex

        public static final int getIndex​(int indexAndDistance)
      • getBestIndexAndDistance

        public int getBestIndexAndDistance​(LSR desired,
                                           LSR[] supportedLSRs,
                                           int supportedLSRsLength,
                                           int shiftedThreshold,
                                           LocaleMatcher.FavorSubtag favorSubtag,
                                           LocaleMatcher.Direction direction)
        Finds the supported LSR with the smallest distance from the desired one. Equivalent LSR subtags must be normalized into a canonical form.

        Returns the index of the lowest-distance supported LSR in the high bits (negative if none has a distance below the threshold), and its distance (0..ABOVE_THRESHOLD) in the low bits.

      • getDesSuppScriptDistance

        private static final int getDesSuppScriptDistance​(BytesTrie iter,
                                                          long startState,
                                                          java.lang.String desired,
                                                          java.lang.String supported)
      • getRegionPartitionsDistance

        private static final int getRegionPartitionsDistance​(BytesTrie iter,
                                                             long startState,
                                                             java.lang.String desiredPartitions,
                                                             java.lang.String supportedPartitions,
                                                             int threshold)
      • getFallbackRegionDistance

        private static final int getFallbackRegionDistance​(BytesTrie iter,
                                                           long startState)
      • trieNext

        private static final int trieNext​(BytesTrie iter,
                                          java.lang.String s,
                                          boolean wantValue)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • partitionsForRegion

        private java.lang.String partitionsForRegion​(LSR lsr)
      • isParadigmLSR

        public boolean isParadigmLSR​(LSR lsr)
      • getDefaultScriptDistance

        public int getDefaultScriptDistance()
      • getDefaultRegionDistance

        int getDefaultRegionDistance()
      • getDefaultDemotionPerDesiredLocale

        public int getDefaultDemotionPerDesiredLocale()
      • testOnlyGetDistanceTable

        public java.util.Map<java.lang.String,​java.lang.Integer> testOnlyGetDistanceTable()
      • testOnlyPrintDistanceTable

        public void testOnlyPrintDistanceTable()