InterpolationVariableCollector { public Map<InterpolationVariable, Integer> getMap() { final HashMap<InterpolationVariable, Integer> result = new HashMap<InterpolationVariable, Integer>(); int index = 0; for (Integer integer : byColumn.keySet()) { result.put(byColumn.get(integer), index); index++; } return result; } InterpolationVariableCollector(final Map<InterpolationVariable, Integer> map,
                                          final String defaultType);  InterpolationVariableCollector(final Map<InterpolationVariable, Integer> map); boolean isThereANeedToSetDefaultType(final InterpolationVariable newVar,
                                                final InterpolationVariable oldVar); Map<InterpolationVariable, Integer> getMap();  }
@Test public void merge() { final HashMap<InterpolationVariable, Integer> map = new HashMap<>(); map.put(new InterpolationVariable("var", DataType.TYPE_DATE, "Person", "birthday"), 1); map.put(new InterpolationVariable("var", DataType.TYPE_DATE, "Person", "dateOfDeath"), 2); final Map<InterpolationVariable, Integer> result = new InterpolationVariableCollector(map).getMap(); assertEquals(1, result.size()); final InterpolationVariable var = result.keySet().iterator().next(); assertEquals("var", var.getVarName()); assertEquals(DEFAULT_TYPE, var.getDataType()); }
@Test public void orderTopDown() { final HashMap<InterpolationVariable, Integer> map = new HashMap<>(); map.put(new InterpolationVariable("var", DataType.TYPE_DATE, "Person", "birthday"), 0); map.put(new InterpolationVariable("var", DataType.TYPE_DATE, "Person", "dateOfDeath"), 1); map.put(new InterpolationVariable("p", DataType.TYPE_DATE, "Person", "dateOfDeath"), 2); final Map<InterpolationVariable, Integer> result = new InterpolationVariableCollector(map).getMap(); assertEquals(2, result.size()); final Iterator<Integer> iterator = result.values().iterator(); assertEquals(1, (int) iterator.next()); assertEquals(0, (int) iterator.next()); }
@Test public void orderBottomUp() { final HashMap<InterpolationVariable, Integer> map = new HashMap<>(); map.put(new InterpolationVariable("var", DataType.TYPE_DATE, "Person", "birthday"), 2); map.put(new InterpolationVariable("var", DataType.TYPE_DATE, "Person", "dateOfDeath"), 1); map.put(new InterpolationVariable("p", DataType.TYPE_DATE, "Person", "dateOfDeath"), 0); final Map<InterpolationVariable, Integer> result = new InterpolationVariableCollector(map).getMap(); assertEquals(2, result.size()); final Iterator<Integer> iterator = result.values().iterator(); assertEquals(0, (int) iterator.next()); assertEquals(1, (int) iterator.next()); }