ICU-13320 ICU4J DateFormatSymbols, add getNarrowEras/setNarrowEras ()

This commit is contained in:
Peter Edberg 2019-02-04 15:54:54 -08:00 committed by pedberg-icu
parent 7791a58a83
commit 7a0a5c7ba9
2 changed files with 47 additions and 11 deletions
icu4j/main
classes/core/src/com/ibm/icu/text
tests/core/src/com/ibm/icu/dev/test/format

View file

@ -720,7 +720,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
Map<CapitalizationContextUsage,boolean[]> capitalization = null;
/**
* Returns era strings. For example: "AD" and "BC".
* Returns abbreviated era strings. For example: "AD" and "BC".
* @return the era strings.
* @stable ICU 2.0
*/
@ -729,7 +729,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
}
/**
* Sets era strings. For example: "AD" and "BC".
* Sets abbreviated era strings. For example: "AD" and "BC".
* @param newEras the new era strings.
* @stable ICU 2.0
*/
@ -738,7 +738,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
}
/**
* {@icu} Returns era name strings. For example: "Anno Domini" and "Before Christ".
* {@icu} Returns full era name strings. For example: "Anno Domini" and "Before Christ".
* @return the era strings.
* @stable ICU 3.4
*/
@ -747,7 +747,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
}
/**
* {@icu} Sets era name strings. For example: "Anno Domini" and "Before Christ".
* {@icu} Sets full era name strings. For example: "Anno Domini" and "Before Christ".
* @param newEraNames the new era strings.
* @stable ICU 3.8
*/
@ -755,6 +755,26 @@ public class DateFormatSymbols implements Serializable, Cloneable {
eraNames = duplicate(newEraNames);
}
/**
* {@icu} Returns narrow era name strings. For example: "A" and "B".
* @return the narrow era strings.
* @draft ICU 64
* @provisional This API might change or be removed in a future release.
*/
public String[] getNarrowEras() {
return duplicate(narrowEras);
}
/**
* {@icu} Sets narrow era name strings. For example: "A" and "B".
* @param newNarrowEras the new narrow era strings.
* @draft ICU 64
* @provisional This API might change or be removed in a future release.
*/
public void setNarrowEras(String[] newNarrowEras) {
narrowEras = duplicate(newNarrowEras);
}
/**
* Returns month strings. For example: "January", "February", etc.
* @return the month strings.
@ -1458,6 +1478,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
DateFormatSymbols that = (DateFormatSymbols) obj;
return (Utility.arrayEquals(eras, that.eras)
&& Utility.arrayEquals(eraNames, that.eraNames)
&& Utility.arrayEquals(narrowEras, that.narrowEras)
&& Utility.arrayEquals(months, that.months)
&& Utility.arrayEquals(shortMonths, that.shortMonths)
&& Utility.arrayEquals(narrowMonths, that.narrowMonths)

View file

@ -142,18 +142,33 @@ public class IntlTestDateFormatSymbols extends TestFmwk
// just do some VERY basic tests to make sure that get/set work
long count;
final String[] eras = en.getEras();
fr.setEras(eras);
final String[] eras1 = fr.getEras();
count = eras.length;
if( count != eras1.length) {
final String[] erasEn = en.getEras();
final String[] eraNamesEn = en.getEraNames();
final String[] erasNarrowEn = en.getNarrowEras();
fr.setEras(erasEn);
fr.setNarrowEras(erasNarrowEn);
final String[] erasFr = fr.getEras();
final String[] erasNarrowFr = fr.getNarrowEras();
count = erasEn.length;
if( count != erasFr.length || count != erasNarrowFr.length) {
errln("ERROR: setEras() failed (different size array)");
}
else {
else { // like the C++ tests
for(int i = 0; i < count; i++) {
if(! eras[i].equals(eras1[i])) {
if(! erasEn[i].equals(erasFr[i])) {
errln("ERROR: setEras() failed (different string values)");
}
if(! erasNarrowEn[i].equals(erasNarrowFr[i])) {
errln("ERROR: setNarrowEras() failed (different string values)");
}
if( eraNamesEn[i].length() <= erasEn[i].length() ) {
// At least for English we know a wide eraName should be longer than an abbrev era
errln("ERROR: english eraNames[i] not longer than eras[i]");
}
if( erasNarrowEn[i].length() >= erasEn[i].length() ) {
// At least for English we know a narrowEra should be shorter than an abbrev era
errln("ERROR: english erasNarrow[i] not shorter than eras[i]");
}
}
}