static Rule() { foreach (NameType s in Enum.GetValues(typeof(NameType))) { IDictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > > rts = new Dictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > >(); foreach (RuleType rt in Enum.GetValues(typeof(RuleType))) { IDictionary <string, IDictionary <string, IList <Rule> > > rs = new Dictionary <string, IDictionary <string, IList <Rule> > >(); Languages ls = Languages.GetInstance(s); foreach (string l in ls.GetLanguages()) { try { rs[l] = ParseRules(CreateScanner(s, rt, l), CreateResourceName(s, rt, l)); } catch (InvalidOperationException e) { throw new InvalidOperationException("Problem processing " + CreateResourceName(s, rt, l), e); } } if (!rt.Equals(RuleType.RULES)) { rs["common"] = ParseRules(CreateScanner(s, rt, "common"), CreateResourceName(s, rt, "common")); } rts[rt] = Collections.UnmodifiableMap(rs); } RULES[s] = Collections.UnmodifiableMap(rts); } }
static Lang() { foreach (NameType s in Enum.GetValues(typeof(NameType))) { langs[s] = LoadFromResource(LANGUAGE_RULES_RN, Languages.GetInstance(s)); } }
private static IDictionary <NameType, Lang> LoadLangs() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { IDictionary <NameType, Lang> langs = new Dictionary <NameType, Lang>(); foreach (NameType s in Enum.GetValues(typeof(NameType))) { langs[s] = LoadFromResource(LANGUAGE_RULES_RN, Languages.GetInstance(s)); } return(langs); }
private static IDictionary <NameType, IDictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > > > LoadRules() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { var rules = new Dictionary <NameType, IDictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > > >(); foreach (NameType s in Enum.GetValues(typeof(NameType))) { IDictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > > rts = new Dictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > >(); foreach (RuleType rt in Enum.GetValues(typeof(RuleType))) { IDictionary <string, IDictionary <string, IList <Rule> > > rs = new Dictionary <string, IDictionary <string, IList <Rule> > >(); Languages ls = Languages.GetInstance(s); foreach (string l in ls.GetLanguages()) { try { rs[l] = ParseRules(CreateScanner(s, rt, l), CreateResourceName(s, rt, l)); } catch (Exception e) when(e.IsIllegalStateException()) { throw new InvalidOperationException("Problem processing " + CreateResourceName(s, rt, l), e); } } if (!rt.Equals(RuleType.RULES)) { rs["common"] = ParseRules(CreateScanner(s, rt, "common"), CreateResourceName(s, rt, "common")); } rts[rt] = rs.AsReadOnly(); } rules[s] = rts.AsReadOnly(); } return(rules); }
[Test]//@Test(expected = IllegalArgumentException.class) public void TestInvalidLanguageIllegalArgumentException() { Assert.Throws <ArgumentException>(() => Languages.GetInstance("thereIsNoSuchLanguage")); }
[Test]//@Test(expected = IllegalStateException.class) public void TestInvalidLangIllegalStateException() { Assert.Throws <InvalidOperationException>(() => Lang.LoadFromResource("thisIsAMadeUpResourceName", Languages.GetInstance(NameType.GENERIC))); }