org.robolectric.res.PluralResourceLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of robolectric-resources Show documentation
Show all versions of robolectric-resources Show documentation
An alternative Android testing framework.
package org.robolectric.res;
import javax.xml.xpath.XPathExpressionException;
import java.util.ArrayList;
import java.util.List;
public class PluralResourceLoader extends XpathResourceXmlLoader {
private ResBundle pluralRulesResBundle;
public PluralResourceLoader(ResBundle pluralRulesResBundle) {
super("/resources/plurals");
this.pluralRulesResBundle = pluralRulesResBundle;
}
@Override protected void processNode(String name, XmlNode xmlNode, XmlContext xmlContext) throws XPathExpressionException {
PluralRules rules = new PluralRules();
for (XmlNode item : xmlNode.selectElements("item")) {
String value = item.getTextContent();
String quantity = item.getAttrValue("quantity");
rules.add(new Plural(quantity, value));
}
pluralRulesResBundle.put("plurals", name, rules, xmlContext);
}
static class PluralRules {
List plurals = new ArrayList();
Plural find(int quantity) {
for (Plural p : plurals) {
if (p.num == quantity) return p;
}
for (Plural p : plurals) {
if (p.num == -1) return p;
}
return null;
}
void add(Plural p) {
plurals.add(p);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy