com.squarespace.cldrengine.plurals.PluralData Maven / Gradle / Ivy
The newest version!
package com.squarespace.cldrengine.plurals;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.squarespace.cldrengine.internal.PluralExternalData;
import lombok.experimental.UtilityClass;
@UtilityClass
class PluralData {
public static final Map CARDINALS;
public static final Map ORDINALS;
public static final List EXPRESSIONS;
static {
JsonObject cardinals = JsonParser.parseString(PluralExternalData.CARDINALRULES).getAsJsonObject();
CARDINALS = decodeRules(cardinals);
JsonObject ordinals = JsonParser.parseString(PluralExternalData.ORDINALRULES).getAsJsonObject();
ORDINALS = decodeRules(ordinals);
JsonArray expressions = JsonParser.parseString(PluralExternalData.EXPRESSIONS).getAsJsonArray();
EXPRESSIONS = decodeExpressions(expressions);
}
private static Map decodeRules(JsonObject set) {
Map res = new HashMap<>();
for (String id : set.keySet()) {
List rules = new ArrayList<>();
JsonArray a1 = set.get(id).getAsJsonArray();
for (int i = 0; i < a1.size(); i++) {
JsonArray a2 = a1.get(i).getAsJsonArray();
int index = a2.get(0).getAsInt();
int[][] indices = intArrayArray(a2.get(1).getAsJsonArray());
Rule rule = new Rule(index, indices);
rules.add(rule);
}
res.put(id, rules.toArray(new Rule[] {}));
}
return res;
}
private static List decodeExpressions(JsonArray arr1) {
List res = new ArrayList<>();
for (int i = 0; i < arr1.size(); i++) {
JsonArray raw = arr1.get(i).getAsJsonArray();
char operand = raw.get(0).getAsString().charAt(0);
int mod = raw.get(1).getAsInt();
int relop = raw.get(2).getAsInt();
// Decode rangelist
JsonArray arr2 = raw.get(3).getAsJsonArray();
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy