Class PersonNameFormatterImpl


  • public class PersonNameFormatterImpl
    extends java.lang.Object
    Actual implementation class for PersonNameFormatter.
    • Field Detail

      • locale

        private final java.util.Locale locale
      • gnFirstLocales

        private final java.util.Set<java.lang.String> gnFirstLocales
      • snFirstLocales

        private final java.util.Set<java.lang.String> snFirstLocales
      • initialPattern

        private final java.lang.String initialPattern
      • initialSequencePattern

        private final java.lang.String initialSequencePattern
      • capitalizeSurname

        private final boolean capitalizeSurname
      • foreignSpaceReplacement

        private final java.lang.String foreignSpaceReplacement
      • nativeSpaceReplacement

        private final java.lang.String nativeSpaceReplacement
      • NON_DEFAULT_SCRIPTS

        static final java.util.Set<java.lang.String> NON_DEFAULT_SCRIPTS
    • Constructor Detail

      • PersonNameFormatterImpl

        public PersonNameFormatterImpl​(java.util.Locale locale,
                                       java.lang.String[] gnFirstPatterns,
                                       java.lang.String[] snFirstPatterns,
                                       java.lang.String[] gnFirstLocales,
                                       java.lang.String[] snFirstLocales)
        THIS IS A DUMMY CONSTRUCTOR JUST FOR THE USE OF THE UNIT TESTS TO CHECK SOME OF THE INTERNAL IMPLEMENTATION!
    • Method Detail

      • toString

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

        public java.lang.String formatToString​(PersonName name)
      • getLocale

        public java.util.Locale getLocale()
      • getSurnameAllCaps

        public boolean getSurnameAllCaps()
      • getInitialPattern

        public java.lang.String getInitialPattern()
      • getInitialSequencePattern

        public java.lang.String getInitialSequencePattern()
      • shouldCapitalizeSurname

        public boolean shouldCapitalizeSurname()
      • asStringArray

        private java.lang.String[] asStringArray​(ICUResourceBundle resource)
        Returns the value of the resource, as a string array.
        Parameters:
        resource - An ICUResourceBundle of type STRING or ARRAY. If ARRAY, this function just returns it as a string array. If STRING, it returns a one-element array containing that string.
        Returns:
        The resource's value, as an array of Strings.
      • nameIsGnFirst

        private boolean nameIsGnFirst​(PersonName name)
        Returns the field order to use when formatting this name, taking into account the name's preferredOrder field, as well as the name and formatter's respective locales.
        Parameters:
        name - The name to be formatted.
        Returns:
        If true, use given-first order to format the name; if false, use surname-first order.
      • getNameScript

        private java.lang.String getNameScript​(PersonName name)
        Internal function to figure out the name's script by examining its characters.
        Parameters:
        name - The name for which we need the script
        Returns:
        The four-letter script code for the name.
      • newLocaleWithScript

        private java.util.Locale newLocaleWithScript​(java.util.Locale oldLocale,
                                                     java.lang.String scriptCode,
                                                     java.lang.String regionCode)
      • getNameLocale

        private java.util.Locale getNameLocale​(PersonName name)
        Internal function to figure out the name's locale when the name doesn't specify it. (Note that this code assumes that if the locale is specified, it includes a language code.)
        Parameters:
        name - The name for which we need the locale
        Returns:
        The name's (real or guessed) locale.
      • nameScriptMatchesLocale

        private boolean nameScriptMatchesLocale​(java.lang.String nameScriptID,
                                                java.util.Locale formatterLocale)
        Returns true if the characters in the name match one of the scripts for the specified locale.
      • formattingLocaleExists

        private boolean formattingLocaleExists​(java.util.Locale formattingLocale)
        Returns true if there's actual name formatting data for the specified locale (i.e., when we fetch the resource data, we don't fall back to root).
      • localesMatch

        private boolean localesMatch​(java.util.Locale nameLocale,
                                     java.util.Locale formatterLocale)
        Returns true if the two locales should be considered equivalent for space-replacement purposes.