@SuppressWarnings("rawtypes") @Override protected Object extractField(Object target) { List<String> fieldNames = getFieldNames(); for (int i = 0; i < fieldNames.size(); i++) { String field = fieldNames.get(i); if (target instanceof Map) { Map map = (Map) target; if (map.containsKey(field)) { target = map.get(field); } else { return NOT_FOUND; } } else { return NOT_FOUND; } } return target; } }
@Test public void testMapWritableFieldExtractorNested() throws Exception { ConstantFieldExtractor cfe = new MapFieldExtractor(); Map<String, Object> m = new LinkedHashMap<String, Object>(); Map<String, String> nested = new LinkedHashMap<String, String>(); nested.put("bar", "found"); m.put("foo", nested); assertEquals("found", extract(cfe, "foo.bar", m)); }
@SuppressWarnings("rawtypes") @Override protected Object extractField(Object target) { List<String> fieldNames = getFieldNames(); for (int i = 0; i < fieldNames.size(); i++) { String field = fieldNames.get(i); if (target instanceof Map) { Map map = (Map) target; if (map.containsKey(field)) { target = map.get(field); } else { return NOT_FOUND; } } else { return NOT_FOUND; } } return target; } }
@Test public void testMapFieldExtractorTopLevel() throws Exception { ConstantFieldExtractor cfe = new MapFieldExtractor(); Map<String, String> m = new LinkedHashMap<String, String>(); m.put("key", "value"); assertEquals("value", extract(cfe, "key", m)); }
@SuppressWarnings("rawtypes") @Override protected Object extractField(Object target) { List<String> fieldNames = getFieldNames(); for (int i = 0; i < fieldNames.size(); i++) { String field = fieldNames.get(i); if (target instanceof Map) { Map map = (Map) target; if (map.containsKey(field)) { target = map.get(field); } else { return NOT_FOUND; } } else { return NOT_FOUND; } } return target; } }
@Test public void testMapFieldExtractorNestedNotFound() throws Exception { ConstantFieldExtractor cfe = new MapFieldExtractor(); Map<String, String> m = new LinkedHashMap<String, String>(); assertEquals(FieldExtractor.NOT_FOUND, extract(cfe, "key", m)); }
@SuppressWarnings("rawtypes") @Override protected Object extractField(Object target) { List<String> fieldNames = getFieldNames(); for (int i = 0; i < fieldNames.size(); i++) { String field = fieldNames.get(i); if (target instanceof Map) { Map map = (Map) target; if (map.containsKey(field)) { target = map.get(field); } else { return NOT_FOUND; } } else { return NOT_FOUND; } } return target; } }
@SuppressWarnings("rawtypes") @Override protected Object extractField(Object target) { List<String> fieldNames = getFieldNames(); for (int i = 0; i < fieldNames.size(); i++) { String field = fieldNames.get(i); if (target instanceof Map) { Map map = (Map) target; if (map.containsKey(field)) { target = map.get(field); } else { return NOT_FOUND; } } else { return NOT_FOUND; } } return target; } }