public abstract Builder relatedLocalesForFormatting()

in locales-common/src/main/java/com/spotify/i18n/locales/common/model/SupportedLocale.java [190:243]


    public abstract Builder relatedLocalesForFormatting(
        final Set<ULocale> relatedLocalesForFormatting);

    abstract SupportedLocale autoBuild(); // not public

    /**
     * Builds a {@link SupportedLocale} out of this builder.
     *
     * <ul>
     *   <li>All provided locales will be validated as normalized and canonicalized.
     *   <li>Their availability in CLDR will be checked and enforced
     *   <li>Locales hierarchy will be validated for all
     * </ul>
     *
     * <p>This is safe to be called several times on the same builder.
     *
     * @throws IllegalStateException if any of the builder property does not match the requirements.
     */
    public final SupportedLocale build() {
      SupportedLocale sl = autoBuild();

      Preconditions.checkState(
          !sl.localeForTranslations().equals(ULocale.ROOT),
          "The given localeForTranslations cannot be the root.");

      Preconditions.checkState(
          ALL_AVAILABLE_LOCALES.contains(sl.localeForTranslations()),
          "The given localeForTranslations %s must be canonical and available in CLDR.",
          sl.localeForTranslations().toLanguageTag());

      Preconditions.checkState(
          sl.relatedLocalesForFormatting().contains(sl.localeForTranslations()),
          "The localeForTranslations %s must be present in the list for relatedLocalesForFormatting.",
          sl.localeForTranslations().toLanguageTag());

      final ULocale rootLocaleForFormatting =
          LocalesHierarchyUtils.getHighestAncestorLocale(sl.localeForTranslations());
      sl.relatedLocalesForFormatting().stream()
          .forEach(
              relatedLocale -> {
                Preconditions.checkState(
                    ALL_AVAILABLE_LOCALES.contains(relatedLocale),
                    "The given relatedLocaleForFormatting %s must be canonical and available in CLDR.",
                    relatedLocale.toLanguageTag());
                Preconditions.checkState(
                    LocalesHierarchyUtils.isSameLocale(relatedLocale, rootLocaleForFormatting)
                        || LocalesHierarchyUtils.isDescendantLocale(
                            relatedLocale, rootLocaleForFormatting),
                    "The given relatedLocaleForFormatting %s is not the same as, or a descendant of the localeForTranslations %s.",
                    relatedLocale.toLanguageTag(),
                    rootLocaleForFormatting.toLanguageTag());
              });
      return sl;
    }