MemoryDiffStorage implements DiffStorage { @Override public RunningAverage getDiff(long itemID1, long itemID2) { boolean inverted = false; if (itemID1 > itemID2) { inverted = true; long temp = itemID1; itemID1 = itemID2; itemID2 = temp; } FastByIDMap<RunningAverage> level2Map; try { buildAverageDiffsLock.readLock().lock(); level2Map = averageDiffs.get(itemID1); } finally { buildAverageDiffsLock.readLock().unlock(); } RunningAverage average = null; if (level2Map != null) { average = level2Map.get(itemID2); } if (inverted) { return average == null ? null : average.inverse(); } else { return average; } } 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 public void testGetDiff() throws Exception { DataModel model = getDataModel(); MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.UNWEIGHTED, Long.MAX_VALUE); RunningAverage average = storage.getDiff(1, 2); assertEquals(0.23333333333333334, average.getAverage(), EPSILON); assertEquals(3, average.getCount()); }