From 203710a8f5439a345294f277698ee952ab966ceb Mon Sep 17 00:00:00 2001 From: Mark Davis Date: Mon, 2 Jul 2012 22:23:52 +0000 Subject: [PATCH] ICU-9407 added @internals X-SVN-Rev: 32014 --- .../core/src/com/ibm/icu/text/DateFormat.java | 2 +- .../com/ibm/icu/text/DateIntervalFormat.java | 23 ++++++++------ .../icu/text/DateTimePatternGenerator.java | 31 +++++++++++++++++-- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java index 5724ff9528c..cd1289a3346 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java @@ -94,7 +94,7 @@ import com.ibm.icu.util.ULocale.Category; * {@link #YEAR_ABBR_MONTH} for something like "Sept 2012". If you don't want to use one of the predefined skeletons, * you can supply your own. The skeletons are like the patterns in SimpleDateFormat, except they: *
    - *
  1. only keep the field pattern letter and all other parts in a pattern, such as space, punctuation, and + *
  2. only keep the field pattern letter and ignore all other parts in a pattern, such as space, punctuation, and * string literals. *
  3. are independent of the order of fields. *
  4. ignore certain differences in the field's pattern letter length: diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java index 8acefc5c1f1..7a9127cdf9d 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java @@ -1,5 +1,5 @@ /* -* Copyright (C) 2008-2011, International Business Machines +* Copyright (C) 2008-2012, International Business Machines * Corporation and others. All Rights Reserved. */ @@ -318,7 +318,7 @@ public class DateIntervalFormat extends UFormat { private DateIntervalFormat() { } - /* + /** * Construct a DateIntervalFormat from DateFormat, * a DateIntervalInfo, and skeleton. * DateFormat provides the timezone, calendar, @@ -330,23 +330,26 @@ public class DateIntervalFormat extends UFormat { * @param locale the locale of this date interval formatter. * @param dtitvinf the DateIntervalInfo object to be adopted. * @param skeleton the skeleton of the date formatter + * @internal + * @deprecated This API is ICU internal only. */ - private DateIntervalFormat(ULocale locale, DateIntervalInfo dtItvInfo, - String skeleton) + public DateIntervalFormat(String skeleton, DateIntervalInfo dtItvInfo, + DateTimePatternGenerator generator, + SimpleDateFormat simpleDateFormat) { + SimpleDateFormat dateFormat = simpleDateFormat; + fDateFormat = dateFormat; // freeze date interval info dtItvInfo.freeze(); fSkeleton = skeleton; fInfo = dtItvInfo; - DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale); - final String bestPattern = generator.getBestPattern(skeleton); - fDateFormat = new SimpleDateFormat(bestPattern, locale); fFromCalendar = (Calendar) fDateFormat.getCalendar().clone(); fToCalendar = (Calendar) fDateFormat.getCalendar().clone(); initializePattern(); } + /** * Construct a DateIntervalFormat from skeleton and the default FORMAT locale. @@ -419,7 +422,8 @@ public class DateIntervalFormat extends UFormat { getInstance(String skeleton, ULocale locale) { DateIntervalInfo dtitvinf = new DateIntervalInfo(locale); - return new DateIntervalFormat(locale, dtitvinf, skeleton); + DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale); + return new DateIntervalFormat(skeleton, dtitvinf, generator, new SimpleDateFormat(generator.getBestPattern(skeleton), locale)); } @@ -512,7 +516,8 @@ public class DateIntervalFormat extends UFormat { // clone. If it is frozen, clone returns itself, otherwise, clone // returns a copy. dtitvinf = (DateIntervalInfo)dtitvinf.clone(); - return new DateIntervalFormat(locale, dtitvinf, skeleton); + DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale); + return new DateIntervalFormat(skeleton, dtitvinf, generator, new SimpleDateFormat(generator.getBestPattern(skeleton), locale)); } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java index 94778bddf0f..4a05f4a299d 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java @@ -86,6 +86,8 @@ import com.ibm.icu.util.UResourceBundle; * @stable ICU 3.6 */ public class DateTimePatternGenerator implements Freezable, Cloneable { + private static final boolean DEBUG = false; + // debugging flags //static boolean SHOW_DISTANCE = false; // TODO add hack to fix months for CJK, as per bug ticket 1099 @@ -286,6 +288,22 @@ public class DateTimePatternGenerator implements Freezable " + patWithSkelFlag); + } skeleton2pattern.put(matcher, patWithSkelFlag); basePattern_pattern.put(basePattern, patWithSkelFlag); return this; @@ -557,6 +580,7 @@ public class DateTimePatternGenerator implements Freezable skeleton2pattern = new TreeMap(); // items are in priority order private TreeMap basePattern_pattern = new TreeMap(); // items are in priority order -- 2.40.0