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 java.util.ArrayList;
import java.util.List;
public class PluralResourceLoader extends XpathResourceXmlLoader {
private ResBunch resBunch;
public PluralResourceLoader(ResBunch resBunch) {
super("/resources/plurals");
this.resBunch = resBunch;
}
@Override protected void processNode(String name, XmlNode xmlNode, XmlContext xmlContext) {
List rules = new ArrayList<>();
for (XmlNode item : xmlNode.selectElements("item")) {
String value = item.getTextContent();
String quantity = item.getAttrValue("quantity");
rules.add(new Plural(quantity, value));
}
resBunch.put("plurals", name, new PluralRules(rules, ResType.CHAR_SEQUENCE, xmlContext));
}
public static class PluralRules extends TypedResource> {
public PluralRules(List data, ResType resType, XmlContext xmlContext) {
super(data, resType, xmlContext);
}
public Plural find(int quantity) {
for (Plural p : getData()) {
if (p.num == quantity) return p;
}
for (Plural p : getData()) {
if (p.num == -1) return p;
}
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy