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

public Class DateTimePatternGenerator

extends Object
implements Freezable<DateTimePatternGenerator>, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, com.ibm.icu.util.Freezable
Imports
java.util.ArrayList, .Arrays, .BitSet, .Collection, .Collections, .EnumSet, .HashMap, .HashSet, .Iterator, .LinkedHashMap, .LinkedHashSet, .List, .Locale, .Map, .MissingResourceException, .Set, .TreeMap, .TreeSet, com.ibm.icu.impl.ICUCache, .ICUData, .ICUResourceBundle, .PatternTokenizer, .SimpleCache, .SimpleFormatterImpl, .UResource, com.ibm.icu.util.Calendar, .Freezable, .ICUCloneNotSupportedException, .Region, .ULocale, .ULocale.Category, .UResourceBundle

This class provides flexible generation of date format patterns, like "yy-MM-dd". The user can build up the generator by adding successive patterns. Once that is done, a query can be made using a "skeleton", which is a pattern which just includes the desired fields and lengths. The generator will return the "best fit" pattern corresponding to that skeleton.

The main method people will use is getBestPattern(String skeleton), since normally this class is pre-built with data from a particular locale. However, generators can be built directly from other data as well.

ICU Status
Stable since ICU 3.6.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
private class
private static class
private static class
public static enum
DateTimePatternGenerator.DisplayWidth

Field display name width constants for getFieldDisplayName

private static class
private static enum
public static class
DateTimePatternGenerator.FormatParser

Deprecated This API is ICU internal only.
This class provides mechanisms for parsing a SimpleDateFormat pattern or generating a new pattern, while handling the quoting.
public static class
DateTimePatternGenerator.PatternInfo

PatternInfo supplies output parameters for addPattern(...).

private static class
private static class
private static class
DateTimePatternGenerator.SkeletonFields

A compact storage mechanism for skeleton field strings.

public static class
DateTimePatternGenerator.VariableField

Deprecated This API is ICU internal only.
Utility class for FormatParser.

Field Summary

Modifier and TypeField and Description
private transient DateTimePatternGenerator.DistanceInfo
private String[]
private static final DateTimePatternGenerator.DisplayWidth
APPENDITEM_WIDTH

The field name width for use in appendItems

private static final int
private String[]
private TreeMap<String, DateTimePatternGenerator.PatternWithSkeletonFlag>
private static final String[]
private static final Set<String>
private static final String[]
private static final String[]
private static final DateTimePatternGenerator.DisplayWidth[]
private Set<String>
private transient DateTimePatternGenerator.DateTimeMatcher
private static final int
private String[]
public static final int
public static final int
public static final int
public static final int
private static final boolean
private String
private char
private static final int
private static ICUCache<String, DateTimePatternGenerator>
public static final int
private static final int
private static final String[]
private String[][]
private transient DateTimePatternGenerator.FormatParser
fp

Deprecated as a consequence of DateTimePatternGenerator.FormatParser being deprecated.
private static final int
public static final int
private volatile boolean
public static final int
private static final String[]
pack-priv static final Map<String, String[]>
private static final int
public static final int
MATCH_ALL_FIELDS_LENGTH

Option mask for forcing the width of all date and time fields.

public static final int
MATCH_HOUR_FIELD_LENGTH

Option mask for forcing the width of hour field.

public static final int
MATCH_MINUTE_FIELD_LENGTH

Option mask for forcing the width of minute field.

public static final int
public static final int
MATCH_SECOND_FIELD_LENGTH

Option mask for forcing the width of second field.

public static final int
private static final int
public static final int
private static final int
private static final int
private static final int
public static final int
public static final int
private static final int
private static final int
private static final int
private TreeMap<DateTimePatternGenerator.DateTimeMatcher, DateTimePatternGenerator.PatternWithSkeletonFlag>
private static final int
public static final int
TYPE_LIMIT

One more than the highest normal field number.

private static final int[][]
public static final int
public static final int
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
protected
DateTimePatternGenerator()

Only for use by subclasses

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
public DateTimePatternGenerator
addPattern(String
Pattern to add.
pattern
,
boolean
When existing values are to be overridden use true, otherwise use false.
override
,
DateTimePatternGenerator.PatternInfo
Returned information.
returnInfo
)

Adds a pattern to the generator.

public DateTimePatternGenerator
addPatternWithSkeleton(String pattern, String skeletonToUse, boolean override, DateTimePatternGenerator.PatternInfo returnInfo)

Deprecated This API is ICU internal only.
addPatternWithSkeleton: If skeletonToUse is specified, then an availableFormats entry is being added.
private String
private void
public Object

Returns:

A copy of this DateTimePatternGenerator object.
clone
()

Overrides java.lang.Object.clone.

Returns a copy of this DateTimePatternGenerator object.
public DateTimePatternGenerator
cloneAsThawed()

Implements com.ibm.icu.util.Freezable.cloneAsThawed.

Provides for the clone operation.
private void
private void
public DateTimePatternGenerator
freeze()

Implements com.ibm.icu.util.Freezable.freeze.

Freezes the object.
private void
private String[]
private String
getAppendFormat(int foundMask)

public static int
getAppendFormatNumber(UResource.Key key)

Deprecated This API is ICU internal only.
public static int
getAppendFormatNumber(String string)

Deprecated This API is ICU internal only.
public String

Returns:

append pattern for field
getAppendItemFormat
(int
The index to retrieve the append item formats.
field
)

Getter corresponding to setAppendItemFormats.

public String

Returns:

name for field
getAppendItemName
(int
The index to get the append item name.
field
)

Getter corresponding to setAppendItemName.

private String
getAppendName(int foundMask)

public String

Returns:

skeleton, such as "MMMdd"
getBaseSkeleton
(String
Input pattern, such as "dd/MMM"
pattern
)

Utility to return a unique base skeleton from a given pattern.

public Set<String>
getBaseSkeletons(Set<String> result)

Return a list of all the base skeletons (in canonical form) from this class

private String
getBestAppending(DateTimePatternGenerator.DateTimeMatcher source, int missingFields, DateTimePatternGenerator.DistanceInfo distInfo, DateTimePatternGenerator.DateTimeMatcher skipMatcher, EnumSet<DateTimePatternGenerator.DTPGflags> flags, int options)

We only get called here if we failed to find an exact skeleton.

public String

Returns:

Best pattern matching the input skeleton.
getBestPattern
(String
The skeleton is a pattern containing only the variable fields. For example, "MMMdd" and "mmhh" are skeletons.
skeleton
)

Return the best pattern matching the input skeleton.

public String

Returns:

Best pattern matching the input skeleton (and options).
getBestPattern
(String
The skeleton is a pattern containing only the variable fields. For example, "MMMdd" and "mmhh" are skeletons.
skeleton
,
int
MATCH_xxx options for forcing the length of specified fields in the returned pattern to match those in the skeleton (when this would not happen otherwise). For default behavior, use MATCH_NO_OPTIONS.
options
)

Return the best pattern matching the input skeleton.

private String
getBestPattern(String skeleton, DateTimePatternGenerator.DateTimeMatcher skipMatcher, int options)

private DateTimePatternGenerator.PatternWithMatcher
private String
private static char
getCanonicalChar(int field, char reference)

Gets the canonical character associated with the specified field (ERA, YEAR, etc).

private static int
getCanonicalIndex(String s, boolean
TODO
strict
)

Get the canonical index, or return -1 if illegal.

public String

Returns:

skeleton, such as "MMMEd"
getCanonicalSkeletonAllowingDuplicates
(String
Input pattern, such as "ccc, d LLL"
pattern
)

Deprecated This API is ICU internal only.
Same as getSkeleton, but allows duplicates and returns a string using canonical pattern chars
private static int
public String

Returns:

pattern
getDateTimeFormat
()

Getter corresponding to setDateTimeFormat.

public String

Returns:

the current dateTimeFormat for the specified style.
getDateTimeFormat
(int
one of DateFormat.FULL..DateFormat.SHORT. An exception will be thrown if out of range.
style
)

Getter corresponding to setDateTimeFormat.

public String

Returns:

string corresponding to the decimal point
getDecimal
()

Getter corresponding to setDecimal.

public DateFormat.HourCycle
getDefaultHourCycle()

Return the default hour cycle.

public char
getDefaultHourFormatChar()

Deprecated This API is ICU internal only.
public static DateTimePatternGenerator
getEmptyInstance()

Create empty generator, to be constructed with addPattern(...) etc.

public String

Returns:

The display name for the field
getFieldDisplayName
(int
The field type, such as ERA.
field
,
DateTimePatternGenerator.DisplayWidth
The desired DisplayWidth, such as DisplayWidth.ABBREVIATED.
width
)

The general interface to get a display name for a particular date/time field, in one of several possible display widths.

public String

Returns:

field value
getFields
(String
The pattern that is passed.
pattern
)

Deprecated This API is ICU internal only.
internal routine
private static String
public static DateTimePatternGenerator

Returns:

A frozen DateTimePatternGenerator.
getFrozenInstance
(ULocale
The locale to pass.
uLocale
)

Deprecated This API is ICU internal only.
Construct a frozen instance of DateTimePatternGenerator for a given locale.
public static DateTimePatternGenerator
getInstance()

Construct a flexible generator according to data for the default FORMAT locale.

public static DateTimePatternGenerator
getInstance(ULocale
The locale to pass.
uLocale
)

Construct a flexible generator according to data for a given locale.

public static DateTimePatternGenerator
getInstance(Locale
The java.util.Locale to pass.
locale
)

Construct a flexible generator according to data for a given locale.

public static DateTimePatternGenerator
getInstanceNoStdPat(ULocale
The locale to pass.
uLocale
)

Deprecated This API is ICU internal only.
Construct a non-frozen instance of DateTimePatternGenerator for a given locale that skips using the standard date and time patterns.
private static String
public Collection<String>

Returns:

the collection with added elements.
getRedundants
(Collection<String>
stores the redundant patterns that are removed. To get these in internal order, supply a LinkedHashSet. If null, a collection is allocated.
output
)

Deprecated This API is ICU internal only.
Redundant patterns are those which if removed, make no difference in the resulting getBestPattern values.
private TreeSet<String>
public String

Returns:

skeleton, such as "MMMdd"
getSkeleton
(String
Input pattern, such as "dd/MMM"
pattern
)

Utility to return a unique skeleton from a given pattern.

public String

Returns:

skeleton, such as "MMMdd"
getSkeletonAllowingDuplicates
(String
Input pattern, such as "dd/MMM"
pattern
)

Deprecated This API is ICU internal only.
Same as getSkeleton, but allows duplicates
public Map<String, String>

Returns:

the input Map containing the values.
getSkeletons
(Map<String, String>
an output Map in which to place the mapping from skeleton to pattern. If you want to see the internal order being used, supply a LinkedHashMap. If the input value is null, then a LinkedHashMap is allocated.

Issue

an alternate API would be to just return a list of the skeletons, and then have a separate routine to get from skeleton to pattern.

result
)

Return a list of all the skeletons (in canonical form) from this class, and the patterns that they map to.

private int
getTopBitNumber(int foundMask)

private void
hackTimes(DateTimePatternGenerator.PatternInfo returnInfo, String shortTimePattern)

private void
initData(ULocale uLocale, boolean skipStdPatterns)

private boolean

Returns:

true if the corresponding slot of CLDR_AVAIL_FORMAT_KEY[] has been added to DateTimePatternGenerator.
isAvailableFormatSet
(String
of the availableFormatMask in CLDR
key
)

This function checks the corresponding slot of CLDR_AVAIL_FORMAT_KEY[] has been added to DateTimePatternGenerator.

public boolean
isFrozen()

Implements com.ibm.icu.util.Freezable.isFrozen.

Determines whether the object has been frozen or not.
public static boolean

Returns:

true or not
isSingleField
(String
The skeleton to determine if it contains a single field.
skeleton
)

Deprecated This API is ICU internal only.
Determines whether a skeleton contains a single field
private String
public String

Returns:

pattern adjusted to match the skeleton fields widths and subtypes.
replaceFieldTypes
(String
input pattern
pattern
,
String
For the pattern to match to.
skeleton
)

Adjusts the field types (width and subtype) of a pattern to match what is in a skeleton.

public String

Returns:

pattern adjusted to match the skeleton fields widths and subtypes.
replaceFieldTypes
(String
input pattern
pattern
,
String
For the pattern to match to.
skeleton
,
int
MATCH_xxx options for forcing the length of specified fields in the returned pattern to match those in the skeleton (when this would not happen otherwise). For default behavior, use MATCH_NO_OPTIONS.
options
)

Adjusts the field types (width and subtype) of a pattern to match what is in a skeleton.

public void
setAppendItemFormat(int
such as ERA
field
,
String
pattern, such as "{0}, {1}"
value
)

An AppendItem format is a pattern used to append a field if there is no good match.

public void
setAppendItemName(int
Index of the append item names.
field
,
String
The value to set the item to.
value
)

Sets the names of fields, eg "era" in English for ERA.

private void
setAvailableFormat(String
of the availableFormats in CLDR
key
)

Add key to HashSet cldrAvailableFormatKeys.

public void
setDateTimeFormat(String
message format pattern, where {1} will be replaced by the date pattern and {0} will be replaced by the time pattern.
dateTimeFormat
)

The date time format is a message format pattern used to compose date and time patterns.

public void
setDateTimeFormat(int
one of DateFormat.FULL..DateFormat.SHORT. An exception will be thrown if out of range.
style
,
String
the new dateTimeFormat to set for the specified style
dateTimeFormat
)

dateTimeFormats are message patterns used to compose combinations of date and time patterns.

private void
public void
setDecimal(String
The decimal to set to.
decimal
)

The decimal value is used in formatting fractions of seconds.

private void
public void
setDefaultHourFormatChar(char defaultHourFormatChar)

Deprecated This API is ICU internal only.
private void
setFieldDisplayName(int
The field type, such as ERA.
field
,
DateTimePatternGenerator.DisplayWidth
The desired DisplayWidth, such as DisplayWidth.ABBREVIATED.
width
,
String
The display name to set
value
)

Deprecated This API is ICU internal only.
The private interface to set a display name for a particular date/time field, in one of several possible display widths.
private static String
showMask(int mask)

public boolean
skeletonsAreSimilar(String id, String skeleton)

Deprecated This API is ICU internal only.
Used by CLDR tooling; not in ICU4C.
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait