itemsForSection.addObject(item);
sectionKey = keyForSection(section); if(sectionKey instanceof NSArray) { NSArray array = (NSArray)sectionKey; int index = 0; for (Enumeration keys = ((NSArray)sectionKey).objectEnumerator(); keys.hasMoreElements(); ) { Object currentKey = keys.nextElement(); Object currentSection = ((NSArray)section).objectAtIndex(index++); NSMutableArray currentItemsForSection=(NSMutableArray)_itemsPerSection.objectForKey(currentKey); if (currentItemsForSection==null) { _sections.addObject(currentSection); currentItemsForSection=new NSMutableArray(); _itemsPerSection.setObjectForKey(currentItemsForSection,currentKey); } currentItemsForSection.addObject(item); } } else { NSMutableArray currentItemsForSection=(NSMutableArray)_itemsPerSection.objectForKey(sectionKey); if (currentItemsForSection==null) { _sections.addObject(section); currentItemsForSection=new NSMutableArray(); _itemsPerSection.setObjectForKey(currentItemsForSection,sectionKey); } currentItemsForSection.addObject(item); }
    public NSArray sections() {        if (_sections==null) {            _sections= new NSMutableArray();            NSArray list=(NSArray)valueForBinding("list");            if (list!=null) {                for (Enumeration e=list.objectEnumerator(); e.hasMoreElements();) {                    Object item=e.nextElement();                    if(log.isDebugEnabled()) log.debug("item = "+item);                    setValueForBinding(item,"item");                    // Sections have to be copiable objects -- no EOs!!                    Object section=valueForBinding("sectionForItem");                    if(log.isDebugEnabled()) log.debug("section = "+section);                    if (section==null) section=NULL;                    Object sectionKey=copiableKeyForSection(section);                    if(log.isDebugEnabled()) log.debug("copiableKeyForSection = "+sectionKey);                    NSMutableArray itemsForSection=null;                    if (_sections.containsObject(section))                        itemsForSection=(NSMutableArray)_itemsPerSection.objectForKey(sectionKey);                    else {                        _sections.addObject(section);                        itemsForSection=new NSMutableArray();                        _itemsPerSection.setObjectForKey(itemsForSection,sectionKey);                    }                    itemsForSection.addObject(item);                }                String sortKey = (String)valueForBinding("sortKey");                //the key act on the array, so it must be in the form "@sortAsc.someKey"                if(sortKey != null) {                    _sections = (NSMutableArray)_sections.valueForKeyPath(sortKey);                }            }        }        return _sections;    }