@Test public void complexIndex() { LanguageIndex index = new LanguageIndex.Builder() .add(lp("en it")).add(lp("it en")) .add(lp("en pl")) .add(lp("en es-ES")).add(lp("en es-419")).add(lp("es en")) .add(lp("en pt-PT")).add(lp("en pt-BR")).add(lp("pt en")) .add(lp("en zh-TW")).add(lp("en zh-CN")).add(lp("zh en")) .addRule(p("es * NULL"), l("es-ES")) .addRule(p("es * +"), l("es-419")) .addRule(p("pt * NULL"), l("pt-PT")) .addRule(p("zh Hans *"), l("zh-CN")) .addRule(p("zh Hant *"), l("zh-TW")) .addRule(p("zh * SG"), l("zh-CN")) .addRule(p("zh * HK"), l("zh-TW")) .addRule(p("zh * MO"), l("zh-TW")) .addRule(p("zh * *"), l("zh-CN")) .build(); assertEquals(lp("en it"), index.map(lp("en it"))); assertEquals(lp("en it"), index.map(lp("en it-IT"))); assertEquals(lp("it en"), index.map(lp("it en"))); assertEquals(lp("it en"), index.map(lp("it-IT en-US"))); assertEquals(lp("en pl"), index.map(lp("en pl"))); assertEquals(lp("en pl"), index.map(lp("en pl-PL"))); assertNull(index.map(lp("pl en"))); assertEquals(lp("en es-ES"), index.map(lp("en es"))); assertEquals(lp("en es-ES"), index.map(lp("en es-x-mo-SDL"))); assertEquals(lp("en es-ES"), index.map(lp("en es-ES"))); assertEquals(lp("en es-419"), index.map(lp("en es-MX"))); assertEquals(lp("en es-419"), index.map(lp("en es-CO"))); assertEquals(lp("en es-419"), index.map(lp("en es-XX"))); assertEquals(lp("en pt-PT"), index.map(lp("en pt"))); assertEquals(lp("en pt-PT"), index.map(lp("en pt-PT"))); assertEquals(lp("en pt-BR"), index.map(lp("en pt-BR"))); assertEquals(lp("en zh-CN"), index.map(lp("en zh-Hans"))); assertEquals(lp("en zh-TW"), index.map(lp("en zh-Hans-TW"))); assertEquals(lp("en zh-CN"), index.map(lp("en zh-Hans-CN"))); assertEquals(lp("en zh-TW"), index.map(lp("en zh-Hant"))); assertEquals(lp("en zh-TW"), index.map(lp("en zh-Hant-TW"))); assertEquals(lp("en zh-CN"), index.map(lp("en zh-Hant-CN"))); assertEquals(lp("en zh-CN"), index.map(lp("en zh-SG"))); assertEquals(lp("en zh-TW"), index.map(lp("en zh-HK"))); assertEquals(lp("en zh-TW"), index.map(lp("en zh-MO"))); assertEquals(lp("en zh-CN"), index.map(lp("en zh"))); assertEquals(lp("en zh-CN"), index.map(lp("en zh-Unkn"))); }
public LanguageDirection map(LanguageDirection pair) { return mappingCache.computeIfAbsent(pair, this::search); }
LanguageIndex { public LanguageDirection map(LanguageDirection pair) { return mappingCache.computeIfAbsent(pair, this::search); } }
LanguageIndex { public LanguageDirection map(LanguageDirection pair) { return mappingCache.computeIfAbsent(pair, this::search); } private  LanguageIndex(Map<SimpleLanguageDirection, List<LanguageDirection>> index, Map<String, List<LanguageRule>> rules, Map<LanguageDirection, LanguageBridge> pivots); }
LanguageIndex { public LanguageDirection map(LanguageDirection pair) { return mappingCache.computeIfAbsent(pair, this::search); } private  LanguageIndex(Map<SimpleLanguageDirection, List<LanguageDirection>> index, Map<String, List<LanguageRule>> rules, Map<LanguageDirection, LanguageBridge> pivots); Set<LanguageDirection> getLanguages(); int size(); LanguageDirection asSingleLanguagePair(); boolean hasPivotLanguage(LanguageDirection direction); LanguageBridge getLanguageBridge(LanguageDirection direction); LanguageDirection map(LanguageDirection pair); LanguageDirection mapIgnoringDirection(LanguageDirection pair); @Override String toString(); }
LanguageIndex { public LanguageDirection map(LanguageDirection pair) { return mappingCache.computeIfAbsent(pair, this::search); } private  LanguageIndex(Map<SimpleLanguageDirection, List<LanguageDirection>> index, Map<String, List<LanguageRule>> rules, Map<LanguageDirection, LanguageBridge> pivots); Set<LanguageDirection> getLanguages(); int size(); LanguageDirection asSingleLanguagePair(); boolean hasPivotLanguage(LanguageDirection direction); LanguageBridge getLanguageBridge(LanguageDirection direction); LanguageDirection map(LanguageDirection pair); LanguageDirection mapIgnoringDirection(LanguageDirection pair); @Override String toString();  }