@Test public void testIterator() { Configuration configuration = new Configuration(); configuration.set("p.sqooptest1", "value"); configuration.set("p.sqooptest2", "value"); PrefixContext context = new PrefixContext(configuration, "p."); boolean seenSqooptest1 = false; boolean seenSqooptest2 = false; for(Map.Entry<String, String> entry : context) { if("sqooptest1".equals(entry.getKey()) && "value".equals(entry.getValue())) { seenSqooptest1 = true; } else if("sqooptest2".equals(entry.getKey()) && "value".equals(entry.getValue())) { seenSqooptest2 = true; } else { fail("Found unexpected property: " + entry.getKey() + " with value " + entry.getValue()); } } assertTrue(seenSqooptest1); assertTrue(seenSqooptest2); }
@Override public Iterator<Map.Entry<String, String>> iterator() { Map<String, String> intermediateMap = new HashMap<String, String>(); for(Map.Entry<String, String> entry : configuration) { String key = entry.getKey(); if(key.startsWith(prefix)) { intermediateMap.put(key.replaceFirst(prefix, ""), entry.getValue()); } } return intermediateMap.entrySet().iterator(); }
PrefixContext implements ImmutableContext { @Override public Iterator<Map.Entry<String, String>> iterator() { Map<String, String> intermediateMap = new HashMap<String, String>(); for(Map.Entry<String, String> entry : configuration) { String key = entry.getKey(); if(key.startsWith(prefix)) { intermediateMap.put(key.replaceFirst(prefix, ""), entry.getValue()); } } return intermediateMap.entrySet().iterator(); } }
PrefixContext implements ImmutableContext { @Override public Iterator<Map.Entry<String, String>> iterator() { Map<String, String> intermediateMap = new HashMap<String, String>(); for(Map.Entry<String, String> entry : configuration) { String key = entry.getKey(); if(key.startsWith(prefix)) { intermediateMap.put(key.replaceFirst(prefix, ""), entry.getValue()); } } return intermediateMap.entrySet().iterator(); } PrefixContext(Configuration configuration, String prefix); }
PrefixContext implements ImmutableContext { @Override public Iterator<Map.Entry<String, String>> iterator() { Map<String, String> intermediateMap = new HashMap<String, String>(); for(Map.Entry<String, String> entry : configuration) { String key = entry.getKey(); if(key.startsWith(prefix)) { intermediateMap.put(key.replaceFirst(prefix, ""), entry.getValue()); } } return intermediateMap.entrySet().iterator(); } PrefixContext(Configuration configuration, String prefix); @Override String getString(String key); @Override String getString(String key, String defaultValue); @Override long getLong(String key, long defaultValue); @Override int getInt(String key, int defaultValue); @Override boolean getBoolean(String key, boolean defaultValue); Configuration getConfiguration(); @Override Iterator<Map.Entry<String, String>> iterator(); }
PrefixContext implements ImmutableContext { @Override public Iterator<Map.Entry<String, String>> iterator() { Map<String, String> intermediateMap = new HashMap<String, String>(); for(Map.Entry<String, String> entry : configuration) { String key = entry.getKey(); if(key.startsWith(prefix)) { intermediateMap.put(key.replaceFirst(prefix, ""), entry.getValue()); } } return intermediateMap.entrySet().iterator(); } PrefixContext(Configuration configuration, String prefix); @Override String getString(String key); @Override String getString(String key, String defaultValue); @Override long getLong(String key, long defaultValue); @Override int getInt(String key, int defaultValue); @Override boolean getBoolean(String key, boolean defaultValue); Configuration getConfiguration(); @Override Iterator<Map.Entry<String, String>> iterator();  }