@Test public void testWithOneAssociation() { List list = Lists.newArrayList("assoc1 | foo | bar", null, "assoc1 | not foo | not bar"); QueryResults queryResults = buildQueryResults(list); AssociationColumnRemapper.apply(queryResults); assertFalse("Found Association Column", queryResults.containsColumnName(ASSOC)); assertTrue("Did not find new assoc1 column", queryResults.containsColumnName("assoc1")); assertTrue("Did not find correct # of associations", queryResults.getResults("assoc1").size() == 3); }
public static void apply(QueryResults queryResults) { Map<String, List<Object>> resultsMap = queryResults.getResultsMap(); Map<String, List<Object>> associationsMap = new TreeMap<>(); if (resultsMap.containsKey("Associations")) { List associationResults = queryResults.getResults("Associations"); Set<String> linkNames = new HashSet<>(); for (Object a : associationResults) { if (a != null) { String s = (String) a; String[] parts = s.split(ILink.DELIMITER); linkNames.add(parts[0].trim()); } } for (String linkName : linkNames) { List<Object> list = new ArrayList<>(queryResults.rowCount()); for (int i = 0; i < queryResults.rowCount(); i++) { list.add(null); } associationsMap.put(linkName, list); } for (int i = 0; i < queryResults.rowCount(); i++) { String association = (String) associationResults.get(i); if (association != null) { String[] parts = association.split(ILink.DELIMITER); String linkName = parts[0]; List<Object> list = associationsMap.get(linkName); list.set(i, association); } } resultsMap.remove("Associations"); resultsMap.putAll(associationsMap); } }
AssociationColumnRemapper { public static void apply(QueryResults queryResults) { Map<String, List<Object>> resultsMap = queryResults.getResultsMap(); Map<String, List<Object>> associationsMap = new TreeMap<>(); if (resultsMap.containsKey("Associations")) { List associationResults = queryResults.getResults("Associations"); Set<String> linkNames = new HashSet<>(); for (Object a : associationResults) { if (a != null) { String s = (String) a; String[] parts = s.split(ILink.DELIMITER); linkNames.add(parts[0].trim()); } } for (String linkName : linkNames) { List<Object> list = new ArrayList<>(queryResults.rowCount()); for (int i = 0; i < queryResults.rowCount(); i++) { list.add(null); } associationsMap.put(linkName, list); } for (int i = 0; i < queryResults.rowCount(); i++) { String association = (String) associationResults.get(i); if (association != null) { String[] parts = association.split(ILink.DELIMITER); String linkName = parts[0]; List<Object> list = associationsMap.get(linkName); list.set(i, association); } } resultsMap.remove("Associations"); resultsMap.putAll(associationsMap); } } }
AssociationColumnRemapper { public static void apply(QueryResults queryResults) { Map<String, List<Object>> resultsMap = queryResults.getResultsMap(); Map<String, List<Object>> associationsMap = new TreeMap<>(); if (resultsMap.containsKey("Associations")) { List associationResults = queryResults.getResults("Associations"); Set<String> linkNames = new HashSet<>(); for (Object a : associationResults) { if (a != null) { String s = (String) a; String[] parts = s.split(ILink.DELIMITER); linkNames.add(parts[0].trim()); } } for (String linkName : linkNames) { List<Object> list = new ArrayList<>(queryResults.rowCount()); for (int i = 0; i < queryResults.rowCount(); i++) { list.add(null); } associationsMap.put(linkName, list); } for (int i = 0; i < queryResults.rowCount(); i++) { String association = (String) associationResults.get(i); if (association != null) { String[] parts = association.split(ILink.DELIMITER); String linkName = parts[0]; List<Object> list = associationsMap.get(linkName); list.set(i, association); } } resultsMap.remove("Associations"); resultsMap.putAll(associationsMap); } }  }
AssociationColumnRemapper { public static void apply(QueryResults queryResults) { Map<String, List<Object>> resultsMap = queryResults.getResultsMap(); Map<String, List<Object>> associationsMap = new TreeMap<>(); if (resultsMap.containsKey("Associations")) { List associationResults = queryResults.getResults("Associations"); Set<String> linkNames = new HashSet<>(); for (Object a : associationResults) { if (a != null) { String s = (String) a; String[] parts = s.split(ILink.DELIMITER); linkNames.add(parts[0].trim()); } } for (String linkName : linkNames) { List<Object> list = new ArrayList<>(queryResults.rowCount()); for (int i = 0; i < queryResults.rowCount(); i++) { list.add(null); } associationsMap.put(linkName, list); } for (int i = 0; i < queryResults.rowCount(); i++) { String association = (String) associationResults.get(i); if (association != null) { String[] parts = association.split(ILink.DELIMITER); String linkName = parts[0]; List<Object> list = associationsMap.get(linkName); list.set(i, association); } } resultsMap.remove("Associations"); resultsMap.putAll(associationsMap); } }  static void apply(QueryResults queryResults); }
AssociationColumnRemapper { public static void apply(QueryResults queryResults) { Map<String, List<Object>> resultsMap = queryResults.getResultsMap(); Map<String, List<Object>> associationsMap = new TreeMap<>(); if (resultsMap.containsKey("Associations")) { List associationResults = queryResults.getResults("Associations"); Set<String> linkNames = new HashSet<>(); for (Object a : associationResults) { if (a != null) { String s = (String) a; String[] parts = s.split(ILink.DELIMITER); linkNames.add(parts[0].trim()); } } for (String linkName : linkNames) { List<Object> list = new ArrayList<>(queryResults.rowCount()); for (int i = 0; i < queryResults.rowCount(); i++) { list.add(null); } associationsMap.put(linkName, list); } for (int i = 0; i < queryResults.rowCount(); i++) { String association = (String) associationResults.get(i); if (association != null) { String[] parts = association.split(ILink.DELIMITER); String linkName = parts[0]; List<Object> list = associationsMap.get(linkName); list.set(i, association); } } resultsMap.remove("Associations"); resultsMap.putAll(associationsMap); } }  static void apply(QueryResults queryResults);  }