Top Description Inners Fields Constructors Methods
com.ibm.icu.text

public Class PersonNameFormatter

extends Object
Class Inheritance
Imports
java.util.Locale, com.ibm.icu.impl.personname.PersonNameFormatterImpl

A class for formatting names of people. Takes raw name data for a person and renders it into a string according to the caller's specifications, taking into account how people's names are rendered in the caller's locale. The Length, Usage, and Formality options can be used to get a wide variety of results. In English, they would produce results along these lines:
REFERRING ADDRESSING MONOGRAM
FORMAL INFORMAL FORMAL INFORMAL FORMAL INFORMAL
LONG James Earl Carter Jr. Jimmy Carter Mr. Carter Jimmy JEC JC
MEDIUM James E. Carter Jr. Jimmy Carter Mr. Carter Jimmy C J
SHORT J. E. Carter Jimmy Carter Mr. Carter Jimmy C J
ICU Status
Draft since ICU 73.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
PersonNameFormatter.Builder

A utility class that can be used to construct a PersonNameFormatter.

public static enum
PersonNameFormatter.DisplayOrder

An enum indicating the desired display order for a formatted name.

public static enum
PersonNameFormatter.Formality

Specifies the intended formality of the formatted name.

public static enum
PersonNameFormatter.Length

Specifies the desired length of the formatted name.

public static enum
PersonNameFormatter.Usage

Specifies the intended usage of the formatted name.

Field Summary

Modifier and TypeField and Description
private final PersonNameFormatterImpl

Constructor Summary

AccessConstructor and Description
private
public
PersonNameFormatter(Locale locale, String[] gnFirstPatterns, String[] snFirstPatterns, String[] gnFirstLocales, String[] snFirstLocales)

Deprecated This API is for unit testing only.

Method Summary

Modifier and TypeMethod and Description
public static PersonNameFormatter.Builder

Returns:

A new Builder.
builder
()

Returns a Builder object that can be used to construct a new PersonNameFormatter.

public String

Returns:

The name, formatted according to the locale and other parameters passed to the formatter's constructor.
formatToString
(PersonName
A PersonName object that supplies individual field values (optionally, with modifiers applied) to the formatter for formatting.
name
)

Formats a name.

public PersonNameFormatter.Builder

Returns:

A new Builder that can be used to create a new formatter based on this formatter.
toBuilder
()

Returns a Builder object whose fields match those used to construct this formatter, allowing a new formatter to be created based on this one.

public String
toString()

Overrides java.lang.Object.toString.

Deprecated This API is for debugging only.
Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

implback to summary
private final PersonNameFormatterImpl impl

Constructor Detail

PersonNameFormatterback to summary
private PersonNameFormatter(Locale locale, PersonNameFormatter.Length length, PersonNameFormatter.Usage usage, PersonNameFormatter.Formality formality, PersonNameFormatter.DisplayOrder displayOrder, boolean surnameAllCaps)
PersonNameFormatterback to summary
public PersonNameFormatter(Locale locale, String[] gnFirstPatterns, String[] snFirstPatterns, String[] gnFirstLocales, String[] snFirstLocales)

Deprecated

This API is for unit testing only.

Annotations
@Deprecated
ICU Status
Internal ICU component: For unit testing only!

Method Detail

builderback to summary
public static PersonNameFormatter.Builder builder()

Returns a Builder object that can be used to construct a new PersonNameFormatter.

Returns:PersonNameFormatter.Builder

A new Builder.

ICU Status
Draft since ICU 73.
formatToStringback to summary
public String formatToString(PersonName name)

Formats a name.

Parameters
name:PersonName

A PersonName object that supplies individual field values (optionally, with modifiers applied) to the formatter for formatting.

Returns:String

The name, formatted according to the locale and other parameters passed to the formatter's constructor.

ICU Status
Draft since ICU 73.
toBuilderback to summary
public PersonNameFormatter.Builder toBuilder()

Returns a Builder object whose fields match those used to construct this formatter, allowing a new formatter to be created based on this one.

Returns:PersonNameFormatter.Builder

A new Builder that can be used to create a new formatter based on this formatter.

ICU Status
Draft since ICU 73.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Deprecated

This API is for debugging only.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
@Deprecated
ICU Status
Internal ICU component: For debugging only!
com.ibm.icu.text back to summary

public Class PersonNameFormatter.Builder

extends Object
Class Inheritance

A utility class that can be used to construct a PersonNameFormatter. Use PersonNameFormatter.builder() to get a new instance.
ICU Status
Draft since ICU 73.

Field Summary

Modifier and TypeField and Description
private PersonNameFormatter.DisplayOrder
private PersonNameFormatter.Formality
private PersonNameFormatter.Length
private Locale
private boolean
private PersonNameFormatter.Usage

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public PersonNameFormatter

Returns:

A new PersonNameFormatter.
build
()

Returns a new PersonNameFormatter with the values that were passed to this builder.

public PersonNameFormatter.Builder

Returns:

This builder.
setDisplayOrder
(PersonNameFormatter.DisplayOrder
The desired display order for formatted names.
order
)

Specifies the desired display order for the formatted names.

public PersonNameFormatter.Builder

Returns:

This builder.
setFormality
(PersonNameFormatter.Formality
The new name length.
formality
)

Sets the name formality for the formatter to be constructed.

public PersonNameFormatter.Builder

Returns:

This builder.
setLength
(PersonNameFormatter.Length
The new name length.
length
)

Sets the name length for the formatter to be constructed.

public PersonNameFormatter.Builder

Returns:

This builder.
setLocale
(Locale
The new formatter locale. May not be null.
locale
)

Sets the locale for the formatter to be constructed.

public PersonNameFormatter.Builder

Returns:

This builder.
setSurnameAllCaps
(boolean
If true, the surname in the formatted result will be rendered in ALL CAPS.
allCaps
)

Requests that the surname in the formatted result be rendered in ALL CAPS.

public PersonNameFormatter.Builder

Returns:

This builder.
setUsage
(PersonNameFormatter.Usage
The new name length.
usage
)

Sets the name usage for the formatter to be constructed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

displayOrderback to summary
private PersonNameFormatter.DisplayOrder displayOrder
formalityback to summary
private PersonNameFormatter.Formality formality
lengthback to summary
private PersonNameFormatter.Length length
localeback to summary
private Locale locale
surnameAllCapsback to summary
private boolean surnameAllCaps
usageback to summary
private PersonNameFormatter.Usage usage

Constructor Detail

Builderback to summary
private Builder()

Method Detail

buildback to summary
public PersonNameFormatter build()

Returns a new PersonNameFormatter with the values that were passed to this builder. This method doesn't freeze or delete the builder; you can call build() more than once (presumably after calling the other methods to change the parameter) to create more than one PersonNameFormatter; you don't need a new Builder for each PersonNameFormatter.

Returns:PersonNameFormatter

A new PersonNameFormatter.

ICU Status
Draft since ICU 73.
setDisplayOrderback to summary
public PersonNameFormatter.Builder setDisplayOrder(PersonNameFormatter.DisplayOrder order)

Specifies the desired display order for the formatted names. This can be either SORTING, which requests that names be formatted in a manner suitable for inclusion in a sorted list (e.g., in English, "Smith, John"), or DEFAULT, which gives the standard field order suitable for most contexts (e.g., in English, "John Smith").

Parameters
order:PersonNameFormatter.DisplayOrder

The desired display order for formatted names.

Returns:PersonNameFormatter.Builder

This builder.

ICU Status
Draft since ICU 73.
setFormalityback to summary
public PersonNameFormatter.Builder setFormality(PersonNameFormatter.Formality formality)

Sets the name formality for the formatter to be constructed.

Parameters
formality:PersonNameFormatter.Formality

The new name length.

Returns:PersonNameFormatter.Builder

This builder.

ICU Status
Draft since ICU 73.
setLengthback to summary
public PersonNameFormatter.Builder setLength(PersonNameFormatter.Length length)

Sets the name length for the formatter to be constructed.

Parameters
length:PersonNameFormatter.Length

The new name length.

Returns:PersonNameFormatter.Builder

This builder.

ICU Status
Draft since ICU 73.
setLocaleback to summary
public PersonNameFormatter.Builder setLocale(Locale locale)

Sets the locale for the formatter to be constructed.

Parameters
locale:Locale

The new formatter locale. May not be null.

Returns:PersonNameFormatter.Builder

This builder.

ICU Status
Draft since ICU 73.
setSurnameAllCapsback to summary
public PersonNameFormatter.Builder setSurnameAllCaps(boolean allCaps)

Requests that the surname in the formatted result be rendered in ALL CAPS. This is often done with Japanese names to highlight which name is the surname.

Parameters
allCaps:boolean

If true, the surname in the formatted result will be rendered in ALL CAPS.

Returns:PersonNameFormatter.Builder

This builder.

ICU Status
Draft since ICU 73.
setUsageback to summary
public PersonNameFormatter.Builder setUsage(PersonNameFormatter.Usage usage)

Sets the name usage for the formatter to be constructed.

Parameters
usage:PersonNameFormatter.Usage

The new name length.

Returns:PersonNameFormatter.Builder

This builder.

ICU Status
Draft since ICU 73.
com.ibm.icu.text back to summary

public final Enum PersonNameFormatter.DisplayOrder

extends Enum<PersonNameFormatter.DisplayOrder>
Class Inheritance

An enum indicating the desired display order for a formatted name.
ICU Status
Draft since ICU 73.

Field Summary

Modifier and TypeField and Description
public static final PersonNameFormatter.DisplayOrder
DEFAULT

The default display order; used to indicate normal formatting.

public static final PersonNameFormatter.DisplayOrder
FORCE_GIVEN_FIRST

Forces the formatter to format the name in given-first order.

public static final PersonNameFormatter.DisplayOrder
FORCE_SURNAME_FIRST

Forces the formatter to format the name in surname-first order.

public static final PersonNameFormatter.DisplayOrder
SORTING

Used to indicate a display order suitable for use in a sorted list: For English, this would put the surnames first, with a comma between them and the rest of the name: "Smith, John".

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static PersonNameFormatter.DisplayOrder
public static PersonNameFormatter.DisplayOrder[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DEFAULTback to summary
public static final PersonNameFormatter.DisplayOrder DEFAULT

The default display order; used to indicate normal formatting.

ICU Status
Draft since ICU 73.
FORCE_GIVEN_FIRSTback to summary
public static final PersonNameFormatter.DisplayOrder FORCE_GIVEN_FIRST

Forces the formatter to format the name in given-first order. If the name itself specifies a display order, this overrides it.

ICU Status
Draft since ICU 74.
FORCE_SURNAME_FIRSTback to summary
public static final PersonNameFormatter.DisplayOrder FORCE_SURNAME_FIRST

Forces the formatter to format the name in surname-first order. If the name itself specifies a display order, this overrides it.

ICU Status
Draft since ICU 74.
SORTINGback to summary
public static final PersonNameFormatter.DisplayOrder SORTING

Used to indicate a display order suitable for use in a sorted list: For English, this would put the surnames first, with a comma between them and the rest of the name: "Smith, John".

ICU Status
Draft since ICU 73.

Constructor Detail

DisplayOrderback to summary
private DisplayOrder()

Method Detail

valueOfback to summary
public static PersonNameFormatter.DisplayOrder valueOf(String name)
valuesback to summary
public static PersonNameFormatter.DisplayOrder[] values()
com.ibm.icu.text back to summary

public final Enum PersonNameFormatter.Formality

extends Enum<PersonNameFormatter.Formality>
Class Inheritance

Specifies the intended formality of the formatted name.
ICU Status
Draft since ICU 73.

Field Summary

Modifier and TypeField and Description
public static final PersonNameFormatter.Formality
DEFAULT

The default formality for the locale.

public static final PersonNameFormatter.Formality
FORMAL

The more formal version of the name.

public static final PersonNameFormatter.Formality
INFORMAL

The more informal version of the name.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static PersonNameFormatter.Formality
public static PersonNameFormatter.Formality[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DEFAULTback to summary
public static final PersonNameFormatter.Formality DEFAULT

The default formality for the locale. For most locales, this is the same as FORMAL, but for English, this is the same as INFORMAL.

ICU Status
Draft since ICU 74.
FORMALback to summary
public static final PersonNameFormatter.Formality FORMAL

The more formal version of the name.

ICU Status
Draft since ICU 73.
INFORMALback to summary
public static final PersonNameFormatter.Formality INFORMAL

The more informal version of the name. In English, this might omit fields or use the "informal" variant of the given name.

ICU Status
Draft since ICU 73.

Constructor Detail

Formalityback to summary
private Formality()

Method Detail

valueOfback to summary
public static PersonNameFormatter.Formality valueOf(String name)
valuesback to summary
public static PersonNameFormatter.Formality[] values()
com.ibm.icu.text back to summary

public final Enum PersonNameFormatter.Length

extends Enum<PersonNameFormatter.Length>
Class Inheritance

Specifies the desired length of the formatted name.
ICU Status
Draft since ICU 73.

Field Summary

Modifier and TypeField and Description
public static final PersonNameFormatter.Length
DEFAULT

The default name length for the locale.

public static final PersonNameFormatter.Length
LONG

The longest name length.

public static final PersonNameFormatter.Length
MEDIUM

The most typical name length.

public static final PersonNameFormatter.Length
SHORT

A shortened name.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static PersonNameFormatter.Length
public static PersonNameFormatter.Length[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DEFAULTback to summary
public static final PersonNameFormatter.Length DEFAULT

The default name length for the locale. For most locales, this is the same as MEDIUM.

ICU Status
Draft since ICU 74.
LONGback to summary
public static final PersonNameFormatter.Length LONG

The longest name length. Generally uses most of the fields in the name object.

ICU Status
Draft since ICU 73.
MEDIUMback to summary
public static final PersonNameFormatter.Length MEDIUM

The most typical name length. Generally includes the given name and surname, but generally not most of the other fields.

ICU Status
Draft since ICU 73.
SHORTback to summary
public static final PersonNameFormatter.Length SHORT

A shortened name. Skips most fields and may abbreviate some name fields to just their initials. When Formality is INFORMAL, may only include one field.

ICU Status
Draft since ICU 73.

Constructor Detail

Lengthback to summary
private Length()

Method Detail

valueOfback to summary
public static PersonNameFormatter.Length valueOf(String name)
valuesback to summary
public static PersonNameFormatter.Length[] values()
com.ibm.icu.text back to summary

public final Enum PersonNameFormatter.Usage

extends Enum<PersonNameFormatter.Usage>
Class Inheritance

Specifies the intended usage of the formatted name.
ICU Status
Draft since ICU 73.

Field Summary

Modifier and TypeField and Description
public static final PersonNameFormatter.Usage
ADDRESSING

Used for when the name is going to be used to address the user directly: "Turn left here, John."

public static final PersonNameFormatter.Usage
MONOGRAM

Used to generate monograms, short 1 to 3-character versions of the name suitable for use in things like chat avatars.

public static final PersonNameFormatter.Usage
REFERRING

Used in general cases, when the name is used to refer to somebody else.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static PersonNameFormatter.Usage
public static PersonNameFormatter.Usage[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ADDRESSINGback to summary
public static final PersonNameFormatter.Usage ADDRESSING

Used for when the name is going to be used to address the user directly: "Turn left here, John."

ICU Status
Draft since ICU 73.
MONOGRAMback to summary
public static final PersonNameFormatter.Usage MONOGRAM

Used to generate monograms, short 1 to 3-character versions of the name suitable for use in things like chat avatars. In English, this is usually the person's initials, but this isn't true in all languages. When the caller specifies Usage.MONOGRAM, the Length parameter can be used to get different lengths of monograms: Length.SHORT is generally a single letter; Length.LONG may be as many as three or four.

ICU Status
Draft since ICU 73.
REFERRINGback to summary
public static final PersonNameFormatter.Usage REFERRING

Used in general cases, when the name is used to refer to somebody else.

ICU Status
Draft since ICU 73.

Constructor Detail

Usageback to summary
private Usage()

Method Detail

valueOfback to summary
public static PersonNameFormatter.Usage valueOf(String name)
valuesback to summary
public static PersonNameFormatter.Usage[] values()