public static NSDictionary arrayGroupedByKeyPath(NSArray eos, String keyPath, boolean includeNulls, String extraKeyPathForValues) { NSMutableDictionary result=new NSMutableDictionary(); for (Enumeration e=eos.objectEnumerator(); e.hasMoreElements();) { Object eo = e.nextElement(); Object key = NSKeyValueCodingAdditions.Utility.valueForKeyPath(eo,keyPath); boolean isNullKey = key==null || key instanceof NSKeyValueCoding.Null; if (!isNullKey || includeNulls) { if (isNullKey) key=NULL_GROUPING_KEY; NSMutableArray existingGroup=(NSMutableArray)result.objectForKey(key); if (existingGroup==null) { existingGroup=new NSMutableArray(); result.setObjectForKey(existingGroup,key); } if (extraKeyPathForValues!=null) { Object value=NSKeyValueCodingAdditions.Utility.valueForKeyPath(eo,extraKeyPathForValues); if (value!=null) existingGroup.addObject(value); } else existingGroup.addObject(eo); } } return result;
public static NSDictionary arrayGroupedByKeyPath(NSArray objects, String keyPath) { return arrayGroupedByKeyPath(objects,keyPath,true,null);
    public static NSDictionary arrayGroupedByKeyPath(NSArray eos,                                                     String keyPath,                                                     boolean includeNulls,                                                     String extraKeyPathForValues) {        NSMutableDictionary result=new NSMutableDictionary();        for (Enumeration e=eos.objectEnumerator(); e.hasMoreElements();) {            Object eo = e.nextElement();            Object key = NSKeyValueCodingAdditions.Utility.valueForKeyPath(eo,keyPath);            boolean isNullKey = key==null || key instanceof NSKeyValueCoding.Null;            if (!isNullKey || includeNulls) {                if (isNullKey) key=NULL_GROUPING_KEY;                NSMutableArray existingGroup=(NSMutableArray)result.objectForKey(key);                if (existingGroup==null) {                    existingGroup=new NSMutableArray();                    result.setObjectForKey(existingGroup,key);                }                if (extraKeyPathForValues!=null) {                    Object value=NSKeyValueCodingAdditions.Utility.valueForKeyPath(eo,extraKeyPathForValues);                    if (value!=null) existingGroup.addObject(value);                } else                    existingGroup.addObject(eo);            }        }        return result;    }