/** * Takes the result of a tagCount call and an array of categories and * distributes the entries in the tagCount hash evenly across the * categories based on the count value for each tag. * * Typically, this is used to display a 'tag cloud' in your UI. * * @param tagHash the tag dictionary returned from a tagCount call * @param categoryList An array containing the categories to split the tags * @return a dictionary mapping each tag name to its corresponding category */ public <U> NSDictionary<String, U> cloud(NSDictionary<String, Integer> tagHash, NSArray<U> categoryList) { int min = 0; int max = 0; for (Integer count : tagHash.allValues()) { if (count.intValue() > max) { max = count.intValue(); } if (count.intValue() < min) { min = count.intValue(); } } NSMutableDictionary<String, U> cloud = new NSMutableDictionary<>(); int divisor = ((max - min) / categoryList.count()) + 1; for (Map.Entry<String, Integer> entry : tagHash.entrySet()) { U obj = categoryList.objectAtIndex((entry.getValue().intValue() - min) / divisor); cloud.setObjectForKey(obj, entry.getKey()); } return cloud; }
public int updateValuesInRowsDescribedByQualifier(NSDictionary<String, Object> updatedRow, EOQualifier qualifier, EOEntity entity) { try { int count = 0; Iterator<NSMutableDictionary<String, Object>> i = iterator(); while (i.hasNext()) { NSMutableDictionary<String, Object> rawRow = i.next(); NSMutableDictionary<String, Object> row = rowFromStoredValues(rawRow, entity); if (qualifier == null || qualifier.evaluateWithObject(row)) { for (Map.Entry<String, Object> entry : updatedRow.entrySet()) { EOAttribute attribute = entity.attributeNamed(entry.getKey()); rawRow.setObjectForKey(entry.getValue(), attribute.columnName()); } count++; } } return count; } catch (EOGeneralAdaptorException e) { e.printStackTrace(); throw e; } catch (Throwable e) { e.printStackTrace(); throw new EOGeneralAdaptorException("Failed to update '" + entity.name() + "' row " + updatedRow + " with qualifier " + qualifier + ": " + e.getMessage()); } }
@Override public void insertRow(NSDictionary<String, Object> row, EOEntity entity) { NSMutableDictionary<String, Object> newRow = new NSMutableDictionary<>(); EOEntity target = entity; /* XXX: This assumes that EOF isn't going to try to insert into two different tables at once */ for (Entry<String, Object> entry : row.entrySet()) { EOAttribute attrib = entity.anyAttributeNamed(entry.getKey()); if (attrib.isFlattened()) { EOAttribute _attrib = entity._attributeForPath(attrib.definition()); target = _attrib.entity(); newRow.setObjectForKey(entry.getValue(), _attrib.name()); } else { newRow.setObjectForKey(entry.getValue(), attrib.name()); } } _stores.objectForKey(target).insertRow(newRow, target); }