@Override public Object resolve(String variable) { if(variable != null && variable.equals(VariableResolver.ALL_FIELDS)) { return new ConcatMap(variableMappings); } for (Map variableMapping : variableMappings) { Object o = variableMapping.get(variable); if (o != null) { return o; } } return null; }
/** * Note: this makes a copy of the values, so it is not fundamentally lazy. * @return */ @Override @SuppressWarnings("unchecked") public Collection<Object> values() { Collection<Object> ret = new ArrayList<>(size()); for (Map m : variableMappings) { ret.addAll(m.values()); } return ret; }
@Test public void testToString() throws Exception { Map<String, Object> v1 = new HashMap<>(); v1.put("k1", "v1"); Map<String, Object> v2 = new HashMap<>(); v2.put("k2", "v2"); v2.put("k3", null); Map<String, Object> union = new HashMap<String, Object>() {{ putAll(v1); put("k2", "v2"); }}; ConcatMap c = create(v1, v2); Assert.assertEquals(c.toString(), union.toString()); }
@Override public Object resolve(String variable) { if(variable.equals(VariableResolver.ALL_FIELDS)) { return new ConcatMap(ImmutableList.of(fieldsMap)); } return fieldsMap.get(variable); }
private ConcatMap create(Map... ms) { List<Map> l = new ArrayList<>(); for(Map m : ms) { l.add(m); } return new ConcatMap(l); }