/// <summary> /// Gets an iterator of text to field for the specified style for the purpose of parsing. /// <para> /// The iterator must be returned in order from the longest text to the shortest. /// /// </para> /// </summary> /// <param name="style"> the style to get text for, null for all parsable text </param> /// <returns> the iterator of text to field pairs, in order from longest text to shortest text, /// null if the style is not parsable </returns> internal IEnumerator <Map_Entry <String, Long> > GetTextIterator(TextStyle style) { IList <Map_Entry <String, Long> > list = Parsable[style]; return(list != null?list.GetEnumerator() : null); }
/// <summary> /// Gets the text for the specified field value, locale and style /// for the purpose of printing. /// </summary> /// <param name="value"> the value to get text for, not null </param> /// <param name="style"> the style to get text for, not null </param> /// <returns> the text for the field value, null if no text found </returns> internal String GetText(long value, TextStyle style) { IDictionary <Long, String> map = ValueTextMap[style]; return(map != null ? map[value] : null); }
private Object CreateStore(TemporalField field, Locale locale) { IDictionary <TextStyle, IDictionary <Long, String> > styleMap = new Dictionary <TextStyle, IDictionary <Long, String> >(); if (field == ERA) { foreach (TextStyle textStyle in TextStyle.values()) { if (textStyle.Standalone) { // Stand-alone isn't applicable to era names. continue; } IDictionary <String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", DateTime.ERA, textStyle.toCalendarStyle(), locale); if (displayNames != null) { IDictionary <Long, String> map = new Dictionary <Long, String>(); foreach (Map_Entry <String, Integer> entry in displayNames) { map[(long)entry.Value] = entry.Key; } if (map.Count > 0) { styleMap[textStyle] = map; } } } return(new LocaleStore(styleMap)); } if (field == MONTH_OF_YEAR) { foreach (TextStyle textStyle in TextStyle.values()) { IDictionary <String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", DateTime.MONTH, textStyle.toCalendarStyle(), locale); IDictionary <Long, String> map = new Dictionary <Long, String>(); if (displayNames != null) { foreach (Map_Entry <String, Integer> entry in displayNames) { map[(long)(entry.Value + 1)] = entry.Key; } } else { // Narrow names may have duplicated names, such as "J" for January, Jun, July. // Get names one by one in that case. for (int month = 1; month <= 12; month++) { String name; name = CalendarDataUtility.retrieveJavaTimeFieldValueName("gregory", DateTime.MONTH, month, textStyle.toCalendarStyle(), locale); if (name == null) { break; } map[(long)(month + 1)] = name; } } if (map.Count > 0) { styleMap[textStyle] = map; } } return(new LocaleStore(styleMap)); } if (field == DAY_OF_WEEK) { foreach (TextStyle textStyle in TextStyle.values()) { IDictionary <String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", DateTime.DAY_OF_WEEK, textStyle.toCalendarStyle(), locale); IDictionary <Long, String> map = new Dictionary <Long, String>(); if (displayNames != null) { foreach (Map_Entry <String, Integer> entry in displayNames) { map[(long)ToWeekDay(entry.Value)] = entry.Key; } } else { // Narrow names may have duplicated names, such as "S" for Sunday and Saturday. // Get names one by one in that case. for (int wday = DayOfWeek.Sunday; wday <= DayOfWeek.Saturday; wday++) { String name; name = CalendarDataUtility.retrieveJavaTimeFieldValueName("gregory", DateTime.DAY_OF_WEEK, wday, textStyle.toCalendarStyle(), locale); if (name == null) { break; } map[(long)ToWeekDay(wday)] = name; } } if (map.Count > 0) { styleMap[textStyle] = map; } } return(new LocaleStore(styleMap)); } if (field == AMPM_OF_DAY) { foreach (TextStyle textStyle in TextStyle.values()) { if (textStyle.Standalone) { // Stand-alone isn't applicable to AM/PM. continue; } IDictionary <String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", DateTime.AM_PM, textStyle.toCalendarStyle(), locale); if (displayNames != null) { IDictionary <Long, String> map = new Dictionary <Long, String>(); foreach (Map_Entry <String, Integer> entry in displayNames) { map[(long)entry.Value] = entry.Key; } if (map.Count > 0) { styleMap[textStyle] = map; } } } return(new LocaleStore(styleMap)); } if (field == IsoFields.QUARTER_OF_YEAR) { // The order of keys must correspond to the TextStyle.values() order. //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String[] keys = { "QuarterNames", "standalone.QuarterNames", "QuarterAbbreviations", "standalone.QuarterAbbreviations", "QuarterNarrows", "standalone.QuarterNarrows"}; String[] keys = new String[] { "QuarterNames", "standalone.QuarterNames", "QuarterAbbreviations", "standalone.QuarterAbbreviations", "QuarterNarrows", "standalone.QuarterNarrows" }; for (int i = 0; i < keys.Length; i++) { String[] names = GetLocalizedResource(keys[i], locale); if (names != null) { IDictionary <Long, String> map = new Dictionary <Long, String>(); for (int q = 0; q < names.Length; q++) { map[(long)(q + 1)] = names[q]; } styleMap[TextStyle.values()[i]] = map; } } return(new LocaleStore(styleMap)); } return(""); // null marker for map }
/// <summary> /// Gets an iterator of text to field for the specified chrono, field, locale and style /// for the purpose of parsing. /// <para> /// The iterator must be returned in order from the longest text to the shortest. /// </para> /// <para> /// The null return value should be used if there is no applicable parsable text, or /// if the text would be a numeric representation of the value. /// Text can only be parsed if all the values for that field-style-locale combination are unique. /// /// </para> /// </summary> /// <param name="chrono"> the Chronology to get text for, not null </param> /// <param name="field"> the field to get text for, not null </param> /// <param name="style"> the style to get text for, null for all parsable text </param> /// <param name="locale"> the locale to get text for, not null </param> /// <returns> the iterator of text to field pairs, in order from longest text to shortest text, /// null if the field or style is not parsable </returns> public virtual IEnumerator <Map_Entry <String, Long> > GetTextIterator(Chronology chrono, TemporalField field, TextStyle style, Locale locale) { if (chrono == IsoChronology.INSTANCE || !(field is ChronoField)) { return(GetTextIterator(field, style, locale)); } int fieldIndex; switch ((ChronoField)field) { case ERA: fieldIndex = DateTime.ERA; break; case MONTH_OF_YEAR: fieldIndex = DateTime.MONTH; break; case DAY_OF_WEEK: fieldIndex = DateTime.DAY_OF_WEEK; break; case AMPM_OF_DAY: fieldIndex = DateTime.AM_PM; break; default: return(null); } int calendarStyle = (style == null) ? DateTime.ALL_STYLES : style.toCalendarStyle(); IDictionary <String, Integer> map = CalendarDataUtility.retrieveJavaTimeFieldValueNames(chrono.CalendarType, fieldIndex, calendarStyle, locale); if (map == null) { return(null); } IList <Map_Entry <String, Long> > list = new List <Map_Entry <String, Long> >(map.Count); switch (fieldIndex) { case DateTime.ERA: foreach (Map_Entry <String, Integer> entry in map) { int era = entry.Value; if (chrono == JapaneseChronology.INSTANCE) { if (era == 0) { era = -999; } else { era -= 2; } } list.Add(CreateEntry(entry.Key, (long)era)); } break; case DateTime.MONTH: foreach (Map_Entry <String, Integer> entry in map) { list.Add(CreateEntry(entry.Key, (long)(entry.Value + 1))); } break; case DateTime.DAY_OF_WEEK: foreach (Map_Entry <String, Integer> entry in map) { list.Add(CreateEntry(entry.Key, (long)ToWeekDay(entry.Value))); } break; default: foreach (Map_Entry <String, Integer> entry in map) { list.Add(CreateEntry(entry.Key, (long)entry.Value)); } break; } return(list.GetEnumerator()); }
/// <summary> /// Gets an iterator of text to field for the specified field, locale and style /// for the purpose of parsing. /// <para> /// The iterator must be returned in order from the longest text to the shortest. /// </para> /// <para> /// The null return value should be used if there is no applicable parsable text, or /// if the text would be a numeric representation of the value. /// Text can only be parsed if all the values for that field-style-locale combination are unique. /// /// </para> /// </summary> /// <param name="field"> the field to get text for, not null </param> /// <param name="style"> the style to get text for, null for all parsable text </param> /// <param name="locale"> the locale to get text for, not null </param> /// <returns> the iterator of text to field pairs, in order from longest text to shortest text, /// null if the field or style is not parsable </returns> public virtual IEnumerator <Map_Entry <String, Long> > GetTextIterator(TemporalField field, TextStyle style, Locale locale) { Object store = FindStore(field, locale); if (store is LocaleStore) { return(((LocaleStore)store).GetTextIterator(style)); } return(null); }
/// <summary> /// Gets the text for the specified chrono, field, locale and style /// for the purpose of formatting. /// <para> /// The text associated with the value is returned. /// The null return value should be used if there is no applicable text, or /// if the text would be a numeric representation of the value. /// /// </para> /// </summary> /// <param name="chrono"> the Chronology to get text for, not null </param> /// <param name="field"> the field to get text for, not null </param> /// <param name="value"> the field value to get text for, not null </param> /// <param name="style"> the style to get text for, not null </param> /// <param name="locale"> the locale to get text for, not null </param> /// <returns> the text for the field value, null if no text found </returns> public virtual String GetText(Chronology chrono, TemporalField field, long value, TextStyle style, Locale locale) { if (chrono == IsoChronology.INSTANCE || !(field is ChronoField)) { return(GetText(field, value, style, locale)); } int fieldIndex; int fieldValue; if (field == ERA) { fieldIndex = DateTime.ERA; if (chrono == JapaneseChronology.INSTANCE) { if (value == -999) { fieldValue = 0; } else { fieldValue = (int)value + 2; } } else { fieldValue = (int)value; } } else if (field == MONTH_OF_YEAR) { fieldIndex = DateTime.MONTH; fieldValue = (int)value - 1; } else if (field == DAY_OF_WEEK) { fieldIndex = DateTime.DAY_OF_WEEK; fieldValue = (int)value + 1; if (fieldValue > 7) { fieldValue = DayOfWeek.Sunday; } } else if (field == AMPM_OF_DAY) { fieldIndex = DateTime.AM_PM; fieldValue = (int)value; } else { return(null); } return(CalendarDataUtility.retrieveJavaTimeFieldValueName(chrono.CalendarType, fieldIndex, fieldValue, style.toCalendarStyle(), locale)); }