ERXArrayUtilities.sortedArraySortedWithKey(possibleEntities, "length");
ERXArrayUtilities.sortArrayWithKey(possibleEntities, "length");
    protected Object entityForName(String name) {        Object result = null;        if(name != null) {            String lowerCaseName = name.toLowerCase();            if (entityNames == null) {                entityNames = (NSArray)((NSArray)ERXUtilities.entitiesForModelGroup(EOModelGroup.defaultGroup()).valueForKey("name")).valueForKey("toLowerCase");            }            NSMutableArray possibleEntities = new NSMutableArray();            for (Enumeration e = entityNames.objectEnumerator(); e.hasMoreElements();) {                String lowercaseEntityName = (String)e.nextElement();                if (lowerCaseName.indexOf(lowercaseEntityName) != -1)                    possibleEntities.addObject(lowercaseEntityName);            }            if (possibleEntities.count() == 1) {                result = ERXUtilities.caseInsensitiveEntityNamed((String)possibleEntities.lastObject());            } else if (possibleEntities.count() > 1) {                ERXArrayUtilities.sortedArraySortedWithKey(possibleEntities, "length");                if (((String)possibleEntities.objectAtIndex(0)).length() == ((String)possibleEntities.objectAtIndex(1)).length())                    log.warn("Found multiple entities of the same length for configuration: " + name                             + " possible entities: " + possibleEntities);                result = ERXUtilities.caseInsensitiveEntityNamed((String)possibleEntities.lastObject());            }            if (log.isDebugEnabled())                log.debug("Found possible entities: " + possibleEntities + " for configuration: " + name                          + " result: " + result);        }        return result;    }