@Test public void parseAndAdd() { int size = AdHoc.adHocProps.size(); AdHoc.parseAndAdd(null); assertEquals(size, AdHoc.adHocProps.size()); AdHoc.parseAndAdd(""); assertEquals(size, AdHoc.adHocProps.size()); AdHoc.parseAndAdd("compiler"); assertEquals(size, AdHoc.adHocProps.size()); AdHoc.parseAndAdd("compiler.src"); assertEquals(size, AdHoc.adHocProps.size()); AdHoc.parseAndAdd("compiler.src.dir"); assertEquals(size, AdHoc.adHocProps.size()); AdHoc.parseAndAdd("compiler.src="); Map<Context, PropFile> defaultScopes = AdHoc.adHocProps.get(Scope.Default); Context compilerContext = Context.named("compiler"); assertTrue(defaultScopes.containsKey(compilerContext)); PropFile compilerPropFile = defaultScopes.get(compilerContext); PropFile.Prop compilerSrcProp = compilerPropFile.get("src"); assertNotSame(PropFile.Prop.Empty, compilerSrcProp); assertEquals("", compilerSrcProp.value()); AdHoc.adHocProps.clear(); AdHoc.parseAndAdd("compiler.src=src"); defaultScopes = AdHoc.adHocProps.get(Scope.Default); assertTrue(defaultScopes.containsKey(compilerContext)); compilerPropFile = defaultScopes.get(compilerContext); compilerSrcProp = compilerPropFile.get("src"); assertNotSame(PropFile.Prop.Empty, compilerSrcProp); assertEquals("src", compilerSrcProp.value()); AdHoc.parseAndAdd("compiler.src.dir=src"); defaultScopes = AdHoc.adHocProps.get(Scope.Default); assertTrue(defaultScopes.containsKey(compilerContext)); compilerPropFile = defaultScopes.get(compilerContext); PropFile.Prop compilerSrcDirProp = compilerPropFile.get("src.dir"); assertNotSame(PropFile.Prop.Empty, compilerSrcDirProp); assertEquals("src", compilerSrcDirProp.value()); compilerSrcProp = compilerPropFile.get("src"); assertNotSame(PropFile.Prop.Empty, compilerSrcProp); assertEquals("src", compilerSrcProp.value()); AdHoc.parseAndAdd("compiler#test.src=test-src"); assertTrue(defaultScopes.containsKey(compilerContext)); compilerPropFile = defaultScopes.get(compilerContext); compilerSrcDirProp = compilerPropFile.get("src.dir"); assertNotSame(PropFile.Prop.Empty, compilerSrcDirProp); assertEquals("src", compilerSrcDirProp.value()); compilerSrcProp = compilerPropFile.get("src"); assertNotSame(PropFile.Prop.Empty, compilerSrcProp); assertEquals("src", compilerSrcProp.value()); Map<Context, PropFile> testScopes = AdHoc.adHocProps.get(Scope.named("test")); assertTrue(testScopes.containsKey(compilerContext)); compilerPropFile = testScopes.get(compilerContext); compilerSrcProp = compilerPropFile.get("src"); assertNotSame(PropFile.Prop.Empty, compilerSrcProp); assertEquals("test-src", compilerSrcProp.value()); AdHoc.parseAndAdd("compiler#test.src.dir=test-src"); assertTrue(defaultScopes.containsKey(compilerContext)); compilerPropFile = defaultScopes.get(compilerContext); compilerSrcDirProp = compilerPropFile.get("src.dir"); assertNotSame(PropFile.Prop.Empty, compilerSrcDirProp); assertEquals("src", compilerSrcDirProp.value()); compilerSrcProp = compilerPropFile.get("src"); assertNotSame(PropFile.Prop.Empty, compilerSrcProp); assertEquals("src", compilerSrcProp.value()); testScopes = AdHoc.adHocProps.get(Scope.named("test")); assertTrue(testScopes.containsKey(compilerContext)); compilerPropFile = testScopes.get(compilerContext); compilerSrcProp = compilerPropFile.get("src"); assertNotSame(PropFile.Prop.Empty, compilerSrcProp); assertEquals("test-src", compilerSrcProp.value()); compilerSrcProp = compilerPropFile.get("src.dir"); assertNotSame(PropFile.Prop.Empty, compilerSrcProp); assertEquals("test-src", compilerSrcProp.value()); }
static void parseAndAdd(String prop) { if (prop == null) { return; } try { String context, scope, propName, propValue; int index; if ((index = prop.indexOf("#")) != -1) { context = prop.substring(0, index); scope = prop.substring(index + 1, (index = prop.indexOf(".", index))); } else { context = prop.substring(0, (index = prop.indexOf("."))); scope = ""; } propName = prop.substring(index + 1, (index = prop.indexOf("=", index))); propValue = prop.substring(index + 1); Context propContext = Context.named(context); Scope propScope = Scope.named(scope); Map<Context, PropFile> contexts = adHocProps.get(propScope); if (contexts == null) { contexts = new ConcurrentHashMap<Context, PropFile>(12, 1.0f); adHocProps.put(propScope, contexts); } PropFile adHocPropFile = contexts.get(propContext); if (adHocPropFile == null) { adHocPropFile = new PropFile(propContext, propScope, PropFile.Loc.AdHoc); contexts.put(propContext, adHocPropFile); Props.addAdHoc(propScope, propContext, adHocPropFile); } if (adHocPropFile.contains(propName)) { PropFile.Prop adHocProp = adHocPropFile.get(propName); Output.print("^warn^ Found two ad-hoc property values for ^b^%s%s.%s^r^ [ ^b^%s^r^ and ^b^%s^r^ ] using first encountered, ^b^%s^r^", context, propScope.getAdHocSuffix(), propName, adHocProp.value(), propValue, adHocProp.value()); } else { adHocPropFile.add(propName, propValue); } } catch (Exception e) { Output.print("^error^ Could not parse ad-hoc property ^b^%s^r^.", prop); } }
AdHoc { static void parseAndAdd(String prop) { if (prop == null) { return; } try { String context, scope, propName, propValue; int index; if ((index = prop.indexOf("#")) != -1) { context = prop.substring(0, index); scope = prop.substring(index + 1, (index = prop.indexOf(".", index))); } else { context = prop.substring(0, (index = prop.indexOf("."))); scope = ""; } propName = prop.substring(index + 1, (index = prop.indexOf("=", index))); propValue = prop.substring(index + 1); Context propContext = Context.named(context); Scope propScope = Scope.named(scope); Map<Context, PropFile> contexts = adHocProps.get(propScope); if (contexts == null) { contexts = new ConcurrentHashMap<Context, PropFile>(12, 1.0f); adHocProps.put(propScope, contexts); } PropFile adHocPropFile = contexts.get(propContext); if (adHocPropFile == null) { adHocPropFile = new PropFile(propContext, propScope, PropFile.Loc.AdHoc); contexts.put(propContext, adHocPropFile); Props.addAdHoc(propScope, propContext, adHocPropFile); } if (adHocPropFile.contains(propName)) { PropFile.Prop adHocProp = adHocPropFile.get(propName); Output.print("^warn^ Found two ad-hoc property values for ^b^%s%s.%s^r^ [ ^b^%s^r^ and ^b^%s^r^ ] using first encountered, ^b^%s^r^", context, propScope.getAdHocSuffix(), propName, adHocProp.value(), propValue, adHocProp.value()); } else { adHocPropFile.add(propName, propValue); } } catch (Exception e) { Output.print("^error^ Could not parse ad-hoc property ^b^%s^r^.", prop); } } }
AdHoc { static void parseAndAdd(String prop) { if (prop == null) { return; } try { String context, scope, propName, propValue; int index; if ((index = prop.indexOf("#")) != -1) { context = prop.substring(0, index); scope = prop.substring(index + 1, (index = prop.indexOf(".", index))); } else { context = prop.substring(0, (index = prop.indexOf("."))); scope = ""; } propName = prop.substring(index + 1, (index = prop.indexOf("=", index))); propValue = prop.substring(index + 1); Context propContext = Context.named(context); Scope propScope = Scope.named(scope); Map<Context, PropFile> contexts = adHocProps.get(propScope); if (contexts == null) { contexts = new ConcurrentHashMap<Context, PropFile>(12, 1.0f); adHocProps.put(propScope, contexts); } PropFile adHocPropFile = contexts.get(propContext); if (adHocPropFile == null) { adHocPropFile = new PropFile(propContext, propScope, PropFile.Loc.AdHoc); contexts.put(propContext, adHocPropFile); Props.addAdHoc(propScope, propContext, adHocPropFile); } if (adHocPropFile.contains(propName)) { PropFile.Prop adHocProp = adHocPropFile.get(propName); Output.print("^warn^ Found two ad-hoc property values for ^b^%s%s.%s^r^ [ ^b^%s^r^ and ^b^%s^r^ ] using first encountered, ^b^%s^r^", context, propScope.getAdHocSuffix(), propName, adHocProp.value(), propValue, adHocProp.value()); } else { adHocPropFile.add(propName, propValue); } } catch (Exception e) { Output.print("^error^ Could not parse ad-hoc property ^b^%s^r^.", prop); } }  }
AdHoc { static void parseAndAdd(String prop) { if (prop == null) { return; } try { String context, scope, propName, propValue; int index; if ((index = prop.indexOf("#")) != -1) { context = prop.substring(0, index); scope = prop.substring(index + 1, (index = prop.indexOf(".", index))); } else { context = prop.substring(0, (index = prop.indexOf("."))); scope = ""; } propName = prop.substring(index + 1, (index = prop.indexOf("=", index))); propValue = prop.substring(index + 1); Context propContext = Context.named(context); Scope propScope = Scope.named(scope); Map<Context, PropFile> contexts = adHocProps.get(propScope); if (contexts == null) { contexts = new ConcurrentHashMap<Context, PropFile>(12, 1.0f); adHocProps.put(propScope, contexts); } PropFile adHocPropFile = contexts.get(propContext); if (adHocPropFile == null) { adHocPropFile = new PropFile(propContext, propScope, PropFile.Loc.AdHoc); contexts.put(propContext, adHocPropFile); Props.addAdHoc(propScope, propContext, adHocPropFile); } if (adHocPropFile.contains(propName)) { PropFile.Prop adHocProp = adHocPropFile.get(propName); Output.print("^warn^ Found two ad-hoc property values for ^b^%s%s.%s^r^ [ ^b^%s^r^ and ^b^%s^r^ ] using first encountered, ^b^%s^r^", context, propScope.getAdHocSuffix(), propName, adHocProp.value(), propValue, adHocProp.value()); } else { adHocPropFile.add(propName, propValue); } } catch (Exception e) { Output.print("^error^ Could not parse ad-hoc property ^b^%s^r^.", prop); } }  static void add(List<String> adHocProps); static Map<Scope, Map<Context, PropFile>> get(); }
AdHoc { static void parseAndAdd(String prop) { if (prop == null) { return; } try { String context, scope, propName, propValue; int index; if ((index = prop.indexOf("#")) != -1) { context = prop.substring(0, index); scope = prop.substring(index + 1, (index = prop.indexOf(".", index))); } else { context = prop.substring(0, (index = prop.indexOf("."))); scope = ""; } propName = prop.substring(index + 1, (index = prop.indexOf("=", index))); propValue = prop.substring(index + 1); Context propContext = Context.named(context); Scope propScope = Scope.named(scope); Map<Context, PropFile> contexts = adHocProps.get(propScope); if (contexts == null) { contexts = new ConcurrentHashMap<Context, PropFile>(12, 1.0f); adHocProps.put(propScope, contexts); } PropFile adHocPropFile = contexts.get(propContext); if (adHocPropFile == null) { adHocPropFile = new PropFile(propContext, propScope, PropFile.Loc.AdHoc); contexts.put(propContext, adHocPropFile); Props.addAdHoc(propScope, propContext, adHocPropFile); } if (adHocPropFile.contains(propName)) { PropFile.Prop adHocProp = adHocPropFile.get(propName); Output.print("^warn^ Found two ad-hoc property values for ^b^%s%s.%s^r^ [ ^b^%s^r^ and ^b^%s^r^ ] using first encountered, ^b^%s^r^", context, propScope.getAdHocSuffix(), propName, adHocProp.value(), propValue, adHocProp.value()); } else { adHocPropFile.add(propName, propValue); } } catch (Exception e) { Output.print("^error^ Could not parse ad-hoc property ^b^%s^r^.", prop); } }  static void add(List<String> adHocProps); static Map<Scope, Map<Context, PropFile>> get();  }