use of android.icu.util.MeasureUnit in project j2objc by google.
the class MeasureUnitTest method TestGreek.
@Test
public void TestGreek() {
String[] locales = { "el_GR", "el" };
final MeasureUnit[] units = new MeasureUnit[] { MeasureUnit.SECOND, MeasureUnit.MINUTE, MeasureUnit.HOUR, MeasureUnit.DAY, MeasureUnit.WEEK, MeasureUnit.MONTH, MeasureUnit.YEAR };
FormatWidth[] styles = new FormatWidth[] { FormatWidth.WIDE, FormatWidth.SHORT };
int[] numbers = new int[] { 1, 7 };
String[] expected = { // "el_GR" 1 wide
"1 δευτερόλεπτο", "1 λεπτό", "1 ώρα", "1 ημέρα", "1 εβδομάδα", "1 μήνας", "1 έτος", // "el_GR" 1 short
"1 δευτ.", "1 λεπ.", "1 ώρα", "1 ημέρα", "1 εβδ.", "1 μήν.", // year (one)
"1 έτ.", // "el_GR" 7 wide
"7 δευτερόλεπτα", "7 λεπτά", "7 ώρες", "7 ημέρες", "7 εβδομάδες", "7 μήνες", "7 έτη", // "el_GR" 7 short
"7 δευτ.", "7 λεπ.", // hour (other)
"7 ώρ.", "7 ημέρες", "7 εβδ.", "7 μήν.", // year (other)
"7 έτ.", // "el" 1 wide
"1 δευτερόλεπτο", "1 λεπτό", "1 ώρα", "1 ημέρα", "1 εβδομάδα", "1 μήνας", "1 έτος", // "el" 1 short
"1 δευτ.", "1 λεπ.", "1 ώρα", "1 ημέρα", "1 εβδ.", "1 μήν.", // year (one)
"1 έτ.", // "el" 7 wide
"7 δευτερόλεπτα", "7 λεπτά", "7 ώρες", "7 ημέρες", "7 εβδομάδες", "7 μήνες", "7 έτη", // "el" 7 short
"7 δευτ.", "7 λεπ.", // hour (other)
"7 ώρ.", "7 ημέρες", "7 εβδ.", "7 μήν.", // year (other
"7 έτ." };
int counter = 0;
String formatted;
for (int locIndex = 0; locIndex < locales.length; ++locIndex) {
for (int numIndex = 0; numIndex < numbers.length; ++numIndex) {
for (int styleIndex = 0; styleIndex < styles.length; ++styleIndex) {
for (int unitIndex = 0; unitIndex < units.length; ++unitIndex) {
Measure m = new Measure(numbers[numIndex], units[unitIndex]);
MeasureFormat fmt = MeasureFormat.getInstance(new ULocale(locales[locIndex]), styles[styleIndex]);
formatted = fmt.format(m);
assertEquals("locale: " + locales[locIndex] + ", style: " + styles[styleIndex] + ", units: " + units[unitIndex] + ", value: " + numbers[numIndex], expected[counter], formatted);
++counter;
}
}
}
}
}
use of android.icu.util.MeasureUnit in project j2objc by google.
the class MeasureUnitTest method testDisplayNames.
@Test
public void testDisplayNames() {
Object[][] data = new Object[][] { // Unit, locale, width, expected result
{ MeasureUnit.YEAR, "en", FormatWidth.WIDE, "years" }, { MeasureUnit.YEAR, "ja", FormatWidth.WIDE, "年" }, { MeasureUnit.YEAR, "es", FormatWidth.WIDE, "años" }, { MeasureUnit.YEAR, "pt", FormatWidth.WIDE, "anos" }, { MeasureUnit.YEAR, "pt-PT", FormatWidth.WIDE, "anos" }, { MeasureUnit.AMPERE, "en", FormatWidth.WIDE, "amperes" }, { MeasureUnit.AMPERE, "ja", FormatWidth.WIDE, "アンペア" }, { MeasureUnit.AMPERE, "es", FormatWidth.WIDE, "amperios" }, { MeasureUnit.AMPERE, "pt", FormatWidth.WIDE, "amperes" }, { MeasureUnit.AMPERE, "pt-PT", FormatWidth.WIDE, "amperes" }, { MeasureUnit.METER_PER_SECOND_SQUARED, "pt", FormatWidth.WIDE, "metros por segundo ao quadrado" }, { MeasureUnit.METER_PER_SECOND_SQUARED, "pt-PT", FormatWidth.WIDE, "metros por segundo quadrado" }, { MeasureUnit.SQUARE_KILOMETER, "pt", FormatWidth.NARROW, "km²" }, { MeasureUnit.SQUARE_KILOMETER, "pt", FormatWidth.SHORT, "km²" }, { MeasureUnit.SQUARE_KILOMETER, "pt", FormatWidth.WIDE, "quilômetros quadrados" }, { MeasureUnit.SECOND, "pt-PT", FormatWidth.NARROW, "s" }, { MeasureUnit.SECOND, "pt-PT", FormatWidth.SHORT, "s" }, { MeasureUnit.SECOND, "pt-PT", FormatWidth.WIDE, "segundos" }, { MeasureUnit.SECOND, "pt", FormatWidth.NARROW, "seg" }, { MeasureUnit.SECOND, "pt", FormatWidth.SHORT, "segs" }, { MeasureUnit.SECOND, "pt", FormatWidth.WIDE, "segundos" } };
for (Object[] test : data) {
MeasureUnit unit = (MeasureUnit) test[0];
ULocale locale = ULocale.forLanguageTag((String) test[1]);
FormatWidth formatWidth = (FormatWidth) test[2];
String expected = (String) test[3];
MeasureFormat mf = MeasureFormat.getInstance(locale, formatWidth);
String actual = mf.getUnitDisplayName(unit);
assertEquals(String.format("Unit Display Name for %s, %s, %s", unit, locale, formatWidth), expected, actual);
}
}
use of android.icu.util.MeasureUnit in project j2objc by google.
the class MeasureUnitTest method updateJAVAVersions.
// DO NOT DELETE THIS FUNCTION! It may appear as dead code, but we use this to generate code
// for MeasureFormat during the release process.
static void updateJAVAVersions(String thisVersion) {
System.out.println();
Map<String, MeasureUnit> seen = new HashMap<String, MeasureUnit>();
TreeMap<String, List<MeasureUnit>> allUnits = getAllUnits();
for (Map.Entry<String, List<MeasureUnit>> entry : allUnits.entrySet()) {
String type = entry.getKey();
if (type.equals("currency")) {
continue;
}
for (MeasureUnit unit : entry.getValue()) {
String javaName = toJAVAName(unit);
checkForDup(seen, javaName, unit);
if (!JAVA_VERSION_MAP.containsKey(javaName)) {
System.out.printf(" {\"%s\", \"%s\"},\n", javaName, thisVersion);
}
}
}
}
use of android.icu.util.MeasureUnit in project j2objc by google.
the class MeasureUnitTest method generateCXXBackwardCompatibilityTest.
// DO NOT DELETE THIS FUNCTION! It may appear as dead code, but we use this to generate code
// for MeasureFormat during the release process.
static void generateCXXBackwardCompatibilityTest(String version) {
System.out.println();
Map<String, MeasureUnit> seen = new HashMap<String, MeasureUnit>();
System.out.printf("void MeasureFormatTest::TestCompatible%s() {\n", version.replace(".", "_"));
System.out.println(" UErrorCode status = U_ZERO_ERROR;");
System.out.println(" LocalPointer<MeasureUnit> measureUnit;");
TreeMap<String, List<MeasureUnit>> allUnits = getAllUnits();
for (Map.Entry<String, List<MeasureUnit>> entry : allUnits.entrySet()) {
if (isTypeHidden(entry.getKey())) {
continue;
}
for (MeasureUnit unit : entry.getValue()) {
String camelCase = toCamelCase(unit);
checkForDup(seen, camelCase, unit);
System.out.printf(" measureUnit.adoptInstead(MeasureUnit::create%s(status));\n", camelCase);
}
}
System.out.println(" assertSuccess(\"\", status);");
System.out.println("}");
}
use of android.icu.util.MeasureUnit in project j2objc by google.
the class MeasureUnitTest method generateConstants.
// DO NOT DELETE THIS FUNCTION! It may appear as dead code, but we use this to generate code
// for MeasureFormat during the release process.
static void generateConstants(String thisVersion) {
System.out.println();
Map<String, MeasureUnit> seen = new HashMap<String, MeasureUnit>();
TreeMap<String, List<MeasureUnit>> allUnits = getAllUnits();
for (Map.Entry<String, List<MeasureUnit>> entry : allUnits.entrySet()) {
String type = entry.getKey();
if (isTypeHidden(type)) {
continue;
}
for (MeasureUnit unit : entry.getValue()) {
String name = toJAVAName(unit);
String code = unit.getSubtype();
checkForDup(seen, name, unit);
System.out.println(" /**");
System.out.println(" * Constant for unit of " + type + ": " + code);
// Special case JAVA had old constants for time from before.
if ("duration".equals(type) && TIME_CODES.contains(code)) {
System.out.println(" * @stable ICU 4.0");
} else if (isDraft(name)) {
System.out.println(" * @draft ICU " + getVersion(name, thisVersion));
System.out.println(" * @provisional This API might change or be removed in a future release.");
} else {
System.out.println(" * @stable ICU " + getVersion(name, thisVersion));
}
System.out.println(" */");
if ("duration".equals(type) && TIME_CODES.contains(code)) {
System.out.println(" public static final TimeUnit " + name + " = (TimeUnit) MeasureUnit.internalGetInstance(\"" + type + "\", \"" + code + "\");");
} else {
System.out.println(" public static final MeasureUnit " + name + " = MeasureUnit.internalGetInstance(\"" + type + "\", \"" + code + "\");");
}
System.out.println();
}
}
System.out.println(" private static HashMap<Pair<MeasureUnit, MeasureUnit>, MeasureUnit>unitPerUnitToSingleUnit =");
System.out.println(" new HashMap<Pair<MeasureUnit, MeasureUnit>, MeasureUnit>();");
System.out.println();
System.out.println(" static {");
for (Map.Entry<MeasureUnit, Pair<MeasureUnit, MeasureUnit>> unitPerUnitEntry : getUnitsToPerParts().entrySet()) {
Pair<MeasureUnit, MeasureUnit> unitPerUnit = unitPerUnitEntry.getValue();
System.out.println(" unitPerUnitToSingleUnit.put(Pair.<MeasureUnit, MeasureUnit>of(MeasureUnit." + toJAVAName(unitPerUnit.first) + ", MeasureUnit." + toJAVAName(unitPerUnit.second) + "), MeasureUnit." + toJAVAName(unitPerUnitEntry.getKey()) + ");");
}
System.out.println(" }");
}
Aggregations