Package com.ibm.icu.impl.personname
Class PersonNameFormatterImpl
- java.lang.Object
-
- com.ibm.icu.impl.personname.PersonNameFormatterImpl
-
public class PersonNameFormatterImpl extends java.lang.Object
Actual implementation class for PersonNameFormatter.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
capitalizeSurname
private PersonNameFormatter.DisplayOrder
displayOrder
private java.lang.String
foreignSpaceReplacement
private PersonNameFormatter.Formality
formality
private java.util.Set<java.lang.String>
gnFirstLocales
private PersonNamePattern[]
gnFirstPatterns
private java.lang.String
initialPattern
private java.lang.String
initialSequencePattern
private PersonNameFormatter.Length
length
private java.util.Locale
locale
private java.lang.String
nativeSpaceReplacement
(package private) static java.util.Set<java.lang.String>
NON_DEFAULT_SCRIPTS
private java.util.Set<java.lang.String>
snFirstLocales
private PersonNamePattern[]
snFirstPatterns
private PersonNameFormatter.Usage
usage
-
Constructor Summary
Constructors Constructor Description PersonNameFormatterImpl(java.util.Locale locale, PersonNameFormatter.Length length, PersonNameFormatter.Usage usage, PersonNameFormatter.Formality formality, PersonNameFormatter.DisplayOrder displayOrder, boolean surnameAllCaps)
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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String[]
asStringArray(ICUResourceBundle resource)
Returns the value of the resource, as a string array.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).java.lang.String
formatToString(PersonName name)
private PersonNamePattern
getBestPattern(PersonNamePattern[] patterns, PersonName name)
PersonNameFormatter.DisplayOrder
getDisplayOrder()
PersonNameFormatter.Formality
getFormality()
java.lang.String
getInitialPattern()
java.lang.String
getInitialSequencePattern()
PersonNameFormatter.Length
getLength()
java.util.Locale
getLocale()
private java.util.Locale
getNameLocale(PersonName name)
Internal function to figure out the name's locale when the name doesn't specify it.private java.lang.String
getNameScript(PersonName name)
Internal function to figure out the name's script by examining its characters.boolean
getSurnameAllCaps()
PersonNameFormatter.Usage
getUsage()
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.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.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.private java.util.Locale
newLocaleWithScript(java.util.Locale oldLocale, java.lang.String scriptCode, java.lang.String regionCode)
boolean
shouldCapitalizeSurname()
java.lang.String
toString()
-
-
-
Field Detail
-
locale
private final java.util.Locale locale
-
gnFirstPatterns
private final PersonNamePattern[] gnFirstPatterns
-
snFirstPatterns
private final PersonNamePattern[] snFirstPatterns
-
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
-
length
private final PersonNameFormatter.Length length
-
usage
private final PersonNameFormatter.Usage usage
-
formality
private final PersonNameFormatter.Formality formality
-
displayOrder
private final PersonNameFormatter.DisplayOrder displayOrder
-
NON_DEFAULT_SCRIPTS
static final java.util.Set<java.lang.String> NON_DEFAULT_SCRIPTS
-
-
Constructor Detail
-
PersonNameFormatterImpl
public PersonNameFormatterImpl(java.util.Locale locale, PersonNameFormatter.Length length, PersonNameFormatter.Usage usage, PersonNameFormatter.Formality formality, PersonNameFormatter.DisplayOrder displayOrder, boolean surnameAllCaps)
-
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 classjava.lang.Object
-
formatToString
public java.lang.String formatToString(PersonName name)
-
getLocale
public java.util.Locale getLocale()
-
getLength
public PersonNameFormatter.Length getLength()
-
getUsage
public PersonNameFormatter.Usage getUsage()
-
getFormality
public PersonNameFormatter.Formality getFormality()
-
getDisplayOrder
public PersonNameFormatter.DisplayOrder getDisplayOrder()
-
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.
-
getBestPattern
private PersonNamePattern getBestPattern(PersonNamePattern[] patterns, PersonName name)
-
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.
-
-