if (group != null && !usedGroups.containsKey(new Integer(group.getID()))) { groupID = new Integer(group.getID()); groupData = (CategoryGroupData) groupsMap.get(groupID); if (groupData == null) { groupData = createCategoryGroupData(group); groupsMap.put(groupID, groupData); }  catData = createCategoryData(category, categoriesMap); catData.setCategoryGroup(groupData); groupData.getCategories().add(catData); results.add(groupData);
if (group != null) { if (!usedGroups.containsKey(new Integer(group.getID()))) { groupID = new Integer(group.getID()); groupData = (CategoryGroupData) groupsMap.get(groupID); if (groupData == null) { groupData = createCategoryGroupData(group); groupsMap.put(groupID, groupData); }  catData = createCategoryData(category, categoriesMap); catData.setCategoryGroup(groupData); groupData.getCategories().add(catData); results.add(groupData); }
    public static List fillICGHierarchyAvailable(List categories, int imgID,                                             int userID)    {        ArrayList results = new ArrayList(), finalResults = new ArrayList();        Iterator i = categories.iterator(), j;        Category category;        CategoryGroup group;        CategoryGroupData groupData = null;        CategoryData catData;        Classification classif;        Integer groupID;        HashMap groupsMap = new HashMap(), categoriesMap = new HashMap();        HashMap usedGroups = new HashMap();        boolean in;        while (i.hasNext()) {            in = false;            category = (Category) i.next();            group = category.getCategoryGroup();            j = category.getClassificationList().iterator();            while (j.hasNext()) {                classif = (Classification) j.next();                if (classif.isValid().equals(Boolean.TRUE) &&                         classif.getModuleExecution().getExperimenter().getID()                         == userID && classif.getImage().getID() == imgID) {                    in = true;                    if (group != null)                         usedGroups.put(new Integer(group.getID()), group);                }            }            if (!in) {  //the image has been classified in the category.               if (group != null &&                        !usedGroups.containsKey(new Integer(group.getID()))) {                   groupID = new Integer(group.getID());                   groupData = (CategoryGroupData) groupsMap.get(groupID);                   if (groupData == null) {                       groupData = createCategoryGroupData(group);                       groupsMap.put(groupID, groupData);                   }                   //Create the category                   catData = createCategoryData(category, categoriesMap);                   catData.setCategoryGroup(groupData);                   groupData.getCategories().add(catData);                   results.add(groupData);               } else { //orphan category, shouldn't happen                   catData = createCategoryData(category, categoriesMap);                   results.add(catData);               }            }         }        //Copy all elements of results into finalResults        finalResults.addAll(results);        i = results.iterator();        Object userObject;        while (i.hasNext()) {            userObject = i.next();            if (userObject instanceof CategoryGroupData) {                groupData = (CategoryGroupData) userObject;                if (usedGroups.containsKey(new Integer(groupData.getID())))                    finalResults.remove(groupData);            }        }        return finalResults;    }