Package com.ibm.icu.text
Class ListFormatter
- java.lang.Object
-
- com.ibm.icu.text.ListFormatter
-
public final class ListFormatter extends java.lang.Object
Immutable class for formatting a list, using data from CLDR (or supplied separately). The class is not subclassable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ListFormatter.Cache
private static class
ListFormatter.ContextualHandler
static class
ListFormatter.Field
Field selectors for format fields defined by ListFormatter.static class
ListFormatter.FormattedList
An immutable class containing the result of a list formatting operation.(package private) static class
ListFormatter.FormattedListBuilder
private static interface
ListFormatter.PatternHandler
static class
ListFormatter.SpanField
Class for span fields in FormattedList.private static class
ListFormatter.StaticHandler
static class
ListFormatter.Type
Type of meaning expressed by the list.static class
ListFormatter.Width
Verbosity level of the list patterns.
-
Field Summary
Fields Modifier and Type Field Description (package private) static ListFormatter.Cache
cache
private static java.util.regex.Pattern
changeToE
private static java.util.regex.Pattern
changeToU
private static java.util.regex.Pattern
changeToVavDash
private static java.lang.String
compiledE
private static java.lang.String
compiledO
private static java.lang.String
compiledU
private static java.lang.String
compiledVav
private static java.lang.String
compiledVavDash
private static java.lang.String
compiledY
private ULocale
locale
private java.lang.String
middle
private ListFormatter.PatternHandler
patternHandler
private java.lang.String
start
-
Constructor Summary
Constructors Modifier Constructor Description ListFormatter(java.lang.String two, java.lang.String start, java.lang.String middle, java.lang.String end)
Deprecated.This API is ICU internal only.private
ListFormatter(java.lang.String two, java.lang.String start, java.lang.String middle, java.lang.String end, ULocale locale)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static java.lang.String
compilePattern(java.lang.String pattern, java.lang.StringBuilder sb)
private ListFormatter.PatternHandler
createPatternHandler(java.lang.String two, java.lang.String end)
java.lang.String
format(java.lang.Object... items)
Format a list of objects.java.lang.String
format(java.util.Collection<?> items)
Format a collection of objects.(package private) ListFormatter.FormattedListBuilder
formatImpl(java.util.Collection<?> items, boolean needsFields)
ListFormatter.FormattedList
formatToValue(java.lang.Object... items)
Format a list of objects to a FormattedList.ListFormatter.FormattedList
formatToValue(java.util.Collection<?> items)
Format a collection of objects to a FormattedList.static ListFormatter
getInstance()
Create a list formatter that is appropriate for the default FORMAT locale.static ListFormatter
getInstance(ULocale locale)
Create a list formatter that is appropriate for a locale.static ListFormatter
getInstance(ULocale locale, ListFormatter.Type type, ListFormatter.Width width)
Create a list formatter that is appropriate for a locale.static ListFormatter
getInstance(java.util.Locale locale)
Create a list formatter that is appropriate for a locale.static ListFormatter
getInstance(java.util.Locale locale, ListFormatter.Type type, ListFormatter.Width width)
Create a list formatter that is appropriate for a locale.ULocale
getLocale()
Deprecated.This API is ICU internal only.java.lang.String
getPatternForNumItems(int count)
Returns the pattern to use for a particular item count.(package private) static java.lang.String
typeWidthToStyleString(ListFormatter.Type type, ListFormatter.Width width)
-
-
-
Field Detail
-
start
private final java.lang.String start
-
middle
private final java.lang.String middle
-
locale
private final ULocale locale
-
patternHandler
private final ListFormatter.PatternHandler patternHandler
-
compiledY
private static final java.lang.String compiledY
-
compiledE
private static final java.lang.String compiledE
-
compiledO
private static final java.lang.String compiledO
-
compiledU
private static final java.lang.String compiledU
-
changeToE
private static final java.util.regex.Pattern changeToE
-
changeToU
private static final java.util.regex.Pattern changeToU
-
compiledVav
private static final java.lang.String compiledVav
-
compiledVavDash
private static final java.lang.String compiledVavDash
-
changeToVavDash
private static final java.util.regex.Pattern changeToVavDash
-
cache
static ListFormatter.Cache cache
-
-
Constructor Detail
-
ListFormatter
@Deprecated public ListFormatter(java.lang.String two, java.lang.String start, java.lang.String middle, java.lang.String end)
Deprecated.This API is ICU internal only.Internal: Create a ListFormatter from component strings, with definitions as in LDML.- Parameters:
two
- string for two items, containing {0} for the first, and {1} for the second.start
- string for the start of a list items, containing {0} for the first, and {1} for the rest.middle
- string for the start of a list items, containing {0} for the first part of the list, and {1} for the rest of the list.end
- string for the end of a list items, containing {0} for the first part of the list, and {1} for the last item.
-
ListFormatter
private ListFormatter(java.lang.String two, java.lang.String start, java.lang.String middle, java.lang.String end, ULocale locale)
-
-
Method Detail
-
compilePattern
private static java.lang.String compilePattern(java.lang.String pattern, java.lang.StringBuilder sb)
-
getInstance
public static ListFormatter getInstance(ULocale locale, ListFormatter.Type type, ListFormatter.Width width)
Create a list formatter that is appropriate for a locale.- Parameters:
locale
- the locale in question.- Returns:
- ListFormatter
-
getInstance
public static ListFormatter getInstance(java.util.Locale locale, ListFormatter.Type type, ListFormatter.Width width)
Create a list formatter that is appropriate for a locale.- Parameters:
locale
- the locale in question.- Returns:
- ListFormatter
-
getInstance
public static ListFormatter getInstance(ULocale locale)
Create a list formatter that is appropriate for a locale.- Parameters:
locale
- the locale in question.- Returns:
- ListFormatter
-
getInstance
public static ListFormatter getInstance(java.util.Locale locale)
Create a list formatter that is appropriate for a locale.- Parameters:
locale
- the locale in question.- Returns:
- ListFormatter
-
getInstance
public static ListFormatter getInstance()
Create a list formatter that is appropriate for the default FORMAT locale.- Returns:
- ListFormatter
-
format
public java.lang.String format(java.lang.Object... items)
Format a list of objects.- Parameters:
items
- items to format. The toString() method is called on each.- Returns:
- items formatted into a string
-
format
public java.lang.String format(java.util.Collection<?> items)
Format a collection of objects. The toString() method is called on each.- Parameters:
items
- items to format. The toString() method is called on each.- Returns:
- items formatted into a string
-
formatToValue
public ListFormatter.FormattedList formatToValue(java.lang.Object... items)
Format a list of objects to a FormattedList. You can access the offsets of each element from the FormattedList.- Parameters:
items
- items to format. The toString() method is called on each.- Returns:
- items formatted into a FormattedList
-
formatToValue
public ListFormatter.FormattedList formatToValue(java.util.Collection<?> items)
Format a collection of objects to a FormattedList. You can access the offsets of each element from the FormattedList.- Parameters:
items
- items to format. The toString() method is called on each.- Returns:
- items formatted into a FormattedList
-
formatImpl
ListFormatter.FormattedListBuilder formatImpl(java.util.Collection<?> items, boolean needsFields)
-
createPatternHandler
private ListFormatter.PatternHandler createPatternHandler(java.lang.String two, java.lang.String end)
-
getPatternForNumItems
public java.lang.String getPatternForNumItems(int count)
Returns the pattern to use for a particular item count.- Parameters:
count
- the item count.- Returns:
- the pattern with {0}, {1}, {2}, etc. For English, getPatternForNumItems(3) == "{0}, {1}, and {2}"
- Throws:
java.lang.IllegalArgumentException
- when count is 0 or negative.
-
getLocale
@Deprecated public ULocale getLocale()
Deprecated.This API is ICU internal only.Returns the locale of this object.
-
typeWidthToStyleString
static java.lang.String typeWidthToStyleString(ListFormatter.Type type, ListFormatter.Width width)
-
-