MemoryDiffStorage implements DiffStorage { @Override public FastIDSet getRecommendableItemIDs(long userID) throws TasteException { FastIDSet result; try { buildAverageDiffsLock.readLock().lock(); result = allRecommendableItemIDs.clone(); } finally { buildAverageDiffsLock.readLock().unlock(); } Iterator<Long> it = result.iterator(); while (it.hasNext()) { if (dataModel.getPreferenceValue(userID, it.next()) != null) { it.remove(); } } return result; } 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 testRecommendableIDsVariedWeighted() throws Exception { DataModel model = getDataModelVaried(); MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.WEIGHTED, Long.MAX_VALUE); FastIDSet recommendableItemIDs = storage.getRecommendableItemIDs(1); assertEquals(3, recommendableItemIDs.size()); assertTrue(recommendableItemIDs.contains(1)); recommendableItemIDs = storage.getRecommendableItemIDs(2); assertEquals(2, recommendableItemIDs.size()); assertTrue(recommendableItemIDs.contains(2)); assertTrue(recommendableItemIDs.contains(3)); recommendableItemIDs = storage.getRecommendableItemIDs(3); assertEquals(1, recommendableItemIDs.size()); assertTrue(recommendableItemIDs.contains(3)); recommendableItemIDs = storage.getRecommendableItemIDs(4); assertEquals(0, recommendableItemIDs.size()); recommendableItemIDs = storage.getRecommendableItemIDs(5); assertEquals(0, recommendableItemIDs.size()); }
@Test public void testRecommendableIDsPockedUnweighted() throws Exception { DataModel model = getDataModelPocked(); MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.UNWEIGHTED, Long.MAX_VALUE); FastIDSet recommendableItemIDs = storage.getRecommendableItemIDs(1); assertEquals(0, recommendableItemIDs.size()); recommendableItemIDs = storage.getRecommendableItemIDs(2); assertEquals(1, recommendableItemIDs.size()); recommendableItemIDs = storage.getRecommendableItemIDs(3); assertEquals(0, recommendableItemIDs.size()); recommendableItemIDs = storage.getRecommendableItemIDs(4); assertEquals(0, recommendableItemIDs.size()); }
@Test (expected=NoSuchUserException.class) public void testUnRecommendableID() throws Exception { DataModel model = getDataModel(); MemoryDiffStorage storage = new MemoryDiffStorage(model, Weighting.WEIGHTED, Long.MAX_VALUE); storage.getRecommendableItemIDs(0); }