Class LocalePriorityList.Builder

  • Enclosing class:
    LocalePriorityList

    public static class LocalePriorityList.Builder
    extends java.lang.Object
    Class used for building LocalePriorityLists.
    • Field Detail

      • languageToWeight

        private java.util.Map<ULocale,​java.lang.Double> languageToWeight
        These store the input languages and weights, in chronological order, where later additions override previous ones.
      • built

        private LocalePriorityList built
        The builder is reusable but rarely reused. Avoid cloning the map when not needed. Exactly one of languageToWeight and built is null.
      • hasWeights

        private boolean hasWeights
    • Constructor Detail

      • Builder

        private Builder()
        Private constructor, only used by LocalePriorityList
    • Method Detail

      • build

        public LocalePriorityList build​(boolean preserveWeights)
        Creates a LocalePriorityList.
        Parameters:
        preserveWeights - when true, each locale's given weight is preserved.
        Returns:
        A LocalePriorityList
      • add

        public LocalePriorityList.Builder add​(ULocale locale)
        Adds a locale with weight 1.0.
        Parameters:
        locale - to add with weight 1.0
        Returns:
        this, for chaining
      • add

        public LocalePriorityList.Builder add​(ULocale... locales)
        Adds locales, each with weight 1.0.
        Parameters:
        locales - locales/languages to be added
        Returns:
        this, for chaining.
      • add

        public LocalePriorityList.Builder add​(ULocale locale,
                                              double weight)
        Adds a locale with a specified weight. Overrides any previous weight for the locale. A zero or negative weight leads to removing the locale. A weight greater than 1 is pinned to 1.
        Parameters:
        locale - language/locale to add
        weight - value between 0.0 and 1.1
        Returns:
        this, for chaining.
      • add

        public LocalePriorityList.Builder add​(java.lang.String acceptLanguageList)
        Parses the RFC 2616 string, and adds locales with weights accordingly.
        Parameters:
        acceptLanguageList - in RFC 2616 format (leniently parsed)
        Returns:
        this, for chaining.