if (!(ca.getImages() instanceof HashSet)) ca.setImages(new HashSet()); ca.getImages().add(img);
cla.setImage(img);
    public Set findCGCIHierarchies(final Set arg0) {        // CONTRACT        if (null == arg0 || arg0.size() == 0) {            return new HashSet();        }        List result = containerDao.findCGCIHierarchies(arg0);        Set imagesAll = new HashSet(result);        if (null == imagesAll || imagesAll.size() == 0) {            if (log.isDebugEnabled()) {                log.debug("findCGCIHierarchies() -- no results found:\n"                        + arg0.toString());            }            return new HashSet();        }        // LOGIC        Set hierarchies = new HashSet();        Iterator i = imagesAll.iterator();        while (i.hasNext()) {            Image img = (Image) i.next();            Set classifications = img.getClassifications();            Set categories = new HashSet();            for (Iterator c = classifications.iterator(); c.hasNext();) {                Classification cla = (Classification) c.next();                if (null!=cla.getCategory()){                     // TODO where else could be null with outer join                    categories.add(cla.getCategory());                }            }            if (categories == null || categories.size() < 1) {                hierarchies.add(img);            } else {                Iterator c = categories.iterator();                while (c.hasNext()) {                    Category tmp = (Category) c.next();                    Category2 ca = new Category2(tmp); //TODO Hack                     if (!(ca.getImages() instanceof HashSet))                        ca.setImages(new HashSet());                    ca.getImages().add(img);                    CategoryGroup cg = ca.getCategoryGroup();                    if (cg == null) {                        hierarchies.add(ca);                    } else {                        if (!(cg.getCategories() instanceof HashSet))                            cg.setCategories(new HashSet());                        cg.getCategories().add(ca);                        hierarchies.add(cg);                    }                }            }        }        return (Set) clean(hierarchies);    }