MemoryDiffStorage implements DiffStorage { @Override public void updateItemPref(long itemID, float prefDelta) { if (stdDevWeighted) { throw new UnsupportedOperationException("Can't update only when stdDevWeighted is set"); } try { buildAverageDiffsLock.readLock().lock(); for (Map.Entry<Long,FastByIDMap<RunningAverage>> entry : averageDiffs.entrySet()) { boolean matchesItemID1 = itemID == entry.getKey(); for (Map.Entry<Long,RunningAverage> entry2 : entry.getValue().entrySet()) { RunningAverage average = entry2.getValue(); if (matchesItemID1) { average.changeDatum(-prefDelta); } else if (itemID == entry2.getKey()) { average.changeDatum(prefDelta); } } } RunningAverage itemAverage = averageItemPref.get(itemID); if (itemAverage != null) { itemAverage.changeDatum(prefDelta); } } finally { buildAverageDiffsLock.readLock().unlock(); } } MemoryDiffStorage(DataModel dataModel,
                           Weighting stdDevWeighted,
                           long maxEntries); @Override RunningAverage getDiff(long itemID1, long itemID2); @Override RunningAverage[] getDiffs(long userID, long itemID, PreferenceArray prefs); @Override RunningAverage getAverageItemPref(long itemID); @Override void addItemPref(long userID, long itemIDA, float prefValue); @Override void updateItemPref(long itemID, float prefDelta); @Override void removeItemPref(long userID, long itemIDA, float prefValue); @Override FastIDSet getRecommendableItemIDs(long userID); @Override void refresh(Collection<Refreshable> alreadyRefreshed); @Override String toString();  }
@Test (expected=UnsupportedOperationException.class) public void testUpdateWeighted() throws Exception { DataModel model = getDataModelVaried(); MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.WEIGHTED, Long.MAX_VALUE); storage.updateItemPref(2, 0.8f); }