public GenericDataModel(FastByIDMap<PreferenceArray> userData, FastByIDMap<FastByIDMap<Long>> timestamps) {
Preconditions.checkArgument(userData != null, "userData is null");
this.preferenceFromUsers = userData;
FastByIDMap<Collection<Preference>> prefsForItems = new FastByIDMap<Collection<Preference>>();
FastIDSet itemIDSet = new FastIDSet();
int currentCount = 0;
float maxPrefValue = Float.NEGATIVE_INFINITY;
float minPrefValue = Float.POSITIVE_INFINITY;
for (Map.Entry<Long, PreferenceArray> entry : preferenceFromUsers.entrySet()) {
PreferenceArray prefs = entry.getValue();
prefs.sortByItem();
for (Preference preference : prefs) {
long itemID = preference.getItemID();
itemIDSet.add(itemID);
List<Preference> prefsForItem = (List<Preference>) prefsForItems.get(itemID);
if (prefsForItem == null) {
prefsForItem = new ArrayList<Preference>(2);
prefsForItems.put(itemID, prefsForItem);
}
prefsForItem.add(preference);
float value = preference.getValue();
if (value > maxPrefValue) {
maxPrefValue = value;
}
if (value < minPrefValue) {
minPrefValue = value;
}
}
if (++currentCount % 10000 == 0) {
log.info("Processed {} users", currentCount);
}
}
log.info("Processed {} users", currentCount);
setMinPreference(minPrefValue);
setMaxPreference(maxPrefValue);
this.itemIDs = itemIDSet.toArray();
itemIDSet = null; // Might help GC -- this is big
Arrays.sort(itemIDs);
this.preferenceForItems = toDataMap(prefsForItems, false);