TypeConverter { public static Map<InterMineObject, List<InterMineObject>> getConvertedObjectMap(List<ApiTemplate> conversionTemplates, Class<? extends InterMineObject> typeA, Class<? extends InterMineObject> typeB, Object bagOrIds, ObjectStore os) throws InterMineException { PathQuery pq = getConversionMapQuery(conversionTemplates, typeA, typeB, bagOrIds); Map<String, InterMineBag> savedBags = new HashMap<String, InterMineBag>(); if (bagOrIds instanceof InterMineBag) { InterMineBag bag = (InterMineBag) bagOrIds; savedBags.put(bag.getName(), bag); } if (pq == null) { return null; } Query q; try { q = MainHelper.makeQuery(pq, savedBags, null, null, null); } catch (ObjectStoreException e) { throw new InterMineException(e); } Results r; Map<InterMineObject, List<InterMineObject>> retval = new HashMap<InterMineObject, List<InterMineObject>>(); r = os.execute(q); Iterator<?> iter = r.iterator(); while (iter.hasNext()) { List row = (List) iter.next(); InterMineObject orig = (InterMineObject) row.get(0); InterMineObject derived = (InterMineObject) row.get(1); List<InterMineObject> ders = retval.get(orig); if (ders == null) { ders = new ArrayList<InterMineObject>(); retval.put(orig, ders); } ders.add(derived); } return retval; } private  TypeConverter(); static Map<InterMineObject, List<InterMineObject>> getConvertedObjectMap(List<ApiTemplate> conversionTemplates,
            Class<? extends InterMineObject> typeA,
            Class<? extends InterMineObject> typeB,
            Object bagOrIds, ObjectStore os); static PathQuery getConversionMapQuery(List<ApiTemplate> conversionTemplates,
                                                Class<? extends InterMineObject> typeA,
                                                Class<? extends InterMineObject> typeB,
                                                Object bagOrIds); static PathQuery getConversionQuery(List<ApiTemplate> conversionTemplates,
            Class<? extends InterMineObject> typeA,
            Class<? extends InterMineObject> typeB,
            Object bagOrIds); static Map<Class, ApiTemplate> getConversionTemplates(
            List<ApiTemplate> conversionTemplates, Class typeA);  }
@Test public void testGetConvertedObjectMap() throws Exception { Results r = getEmployeesAndAddresses(); Assert.assertEquals("Results: " + r, 2, r.size()); List<String> classKeys = new ArrayList<String>(); classKeys.add("name"); InterMineBag imb = new InterMineBag("Fred", "Employee", "Test bag", new Date(), BagState.CURRENT, os, null, uosw, classKeys); imb.addIdToBag(((Employee) ((List) r.get(0)).get(0)).getId(), "Employee"); imb.addIdToBag(((Employee) ((List) r.get(1)).get(0)).getId(), "Employee"); Map expected = new HashMap(); expected.put(((List) r.get(0)).get(0), Collections.singletonList(((List) r.get(0)).get(1))); expected.put(((List) r.get(1)).get(0), Collections.singletonList(((List) r.get(1)).get(1))); Map<InterMineObject, List<InterMineObject>> got = TypeConverter.getConvertedObjectMap(conversionTemplates, Employee.class, Address.class, imb, os); Assert.assertEquals(expected, got); }