@Test public void getPlurals_WithTestPluralRules() { String[] expectedQuantityStrings = {"零个", "一个", "两个", "少许", "多数", "其他"}; for (int i = 0; i < expectedQuantityStrings.length; i++) { String string = parsedStringPack.getQuantityString(PLURALS_ID, (long) i, TEST_PLURAL_RULES); assertEquals(expectedQuantityStrings[i], string); } }
@Nullable public String getQuantityString(int id, Object quantity, @NonNull PluralRules pluralRules) { String[] plural = plurals.get(id); if (plural == null) { plural = loadPlural(id); } if (plural == null) { return null; } final int index = quantityIndex(pluralRules.quantityForNumber(quantity)); String result = plural[index]; if (result != null) { return result; } return plural[0]; }
ParsedStringPack { @Nullable public String getQuantityString(int id, Object quantity, @NonNull PluralRules pluralRules) { String[] plural = plurals.get(id); if (plural == null) { plural = loadPlural(id); } if (plural == null) { return null; } final int index = quantityIndex(pluralRules.quantityForNumber(quantity)); String result = plural[index]; if (result != null) { return result; } return plural[0]; } }
ParsedStringPack { @Nullable public String getQuantityString(int id, Object quantity, @NonNull PluralRules pluralRules) { String[] plural = plurals.get(id); if (plural == null) { plural = loadPlural(id); } if (plural == null) { return null; } final int index = quantityIndex(pluralRules.quantityForNumber(quantity)); String result = plural[index]; if (result != null) { return result; } return plural[0]; } ParsedStringPack(@NonNull InputStream inputStream, @NonNull List<String> parentLocales); }
ParsedStringPack { @Nullable public String getQuantityString(int id, Object quantity, @NonNull PluralRules pluralRules) { String[] plural = plurals.get(id); if (plural == null) { plural = loadPlural(id); } if (plural == null) { return null; } final int index = quantityIndex(pluralRules.quantityForNumber(quantity)); String result = plural[index]; if (result != null) { return result; } return plural[0]; } ParsedStringPack(@NonNull InputStream inputStream, @NonNull List<String> parentLocales); boolean isEmpty(); @Nullable String getString(int id); @Nullable String getQuantityString(int id, Object quantity, @NonNull PluralRules pluralRules); }
ParsedStringPack { @Nullable public String getQuantityString(int id, Object quantity, @NonNull PluralRules pluralRules) { String[] plural = plurals.get(id); if (plural == null) { plural = loadPlural(id); } if (plural == null) { return null; } final int index = quantityIndex(pluralRules.quantityForNumber(quantity)); String result = plural[index]; if (result != null) { return result; } return plural[0]; } ParsedStringPack(@NonNull InputStream inputStream, @NonNull List<String> parentLocales); boolean isEmpty(); @Nullable String getString(int id); @Nullable String getQuantityString(int id, Object quantity, @NonNull PluralRules pluralRules);  }