GenericItemSimilarity implements ItemSimilarity { @Override public long[] allSimilarItemIDs(long itemID) { FastIDSet similarItemIDs = similarItemIDsIndex.get(itemID); return similarItemIDs != null ? similarItemIDs.toArray() : NO_IDS; } GenericItemSimilarity(Iterable<ItemItemSimilarity> similarities);  GenericItemSimilarity(Iterable<ItemItemSimilarity> similarities, int maxToKeep);  GenericItemSimilarity(ItemSimilarity otherSimilarity, DataModel dataModel);  GenericItemSimilarity(ItemSimilarity otherSimilarity,
                               DataModel dataModel,
                               int maxToKeep); @Override double itemSimilarity(long itemID1, long itemID2); @Override double[] itemSimilarities(long itemID1, long[] itemID2s); @Override long[] allSimilarItemIDs(long itemID); @Override void refresh(Collection<Refreshable> alreadyRefreshed);  }
@Test public void testAllSimilaritiesWithoutIndex() throws TasteException { List<GenericItemSimilarity.ItemItemSimilarity> itemItemSimilarities = Arrays.asList(new GenericItemSimilarity.ItemItemSimilarity(1L, 2L, 0.2), new GenericItemSimilarity.ItemItemSimilarity(1L, 3L, 0.2), new GenericItemSimilarity.ItemItemSimilarity(2L, 1L, 0.2), new GenericItemSimilarity.ItemItemSimilarity(3L, 5L, 0.2), new GenericItemSimilarity.ItemItemSimilarity(3L, 4L, 0.2)); ItemSimilarity similarity = new GenericItemSimilarity(itemItemSimilarities); assertTrue(containsExactly(similarity.allSimilarItemIDs(1L), 2L, 3L)); assertTrue(containsExactly(similarity.allSimilarItemIDs(2L), 1L)); assertTrue(containsExactly(similarity.allSimilarItemIDs(3L), 1L, 5L, 4L)); assertTrue(containsExactly(similarity.allSimilarItemIDs(4L), 3L)); assertTrue(containsExactly(similarity.allSimilarItemIDs(5L), 3L)); }
@Test public void testAllSimilaritiesWithIndex() throws TasteException { List<GenericItemSimilarity.ItemItemSimilarity> itemItemSimilarities = Arrays.asList(new GenericItemSimilarity.ItemItemSimilarity(1L, 2L, 0.2), new GenericItemSimilarity.ItemItemSimilarity(1L, 3L, 0.2), new GenericItemSimilarity.ItemItemSimilarity(2L, 1L, 0.2), new GenericItemSimilarity.ItemItemSimilarity(3L, 5L, 0.2), new GenericItemSimilarity.ItemItemSimilarity(3L, 4L, 0.2)); ItemSimilarity similarity = new GenericItemSimilarity(itemItemSimilarities); assertTrue(containsExactly(similarity.allSimilarItemIDs(1L), 2L, 3L)); assertTrue(containsExactly(similarity.allSimilarItemIDs(2L), 1L)); assertTrue(containsExactly(similarity.allSimilarItemIDs(3L), 1L, 5L, 4L)); assertTrue(containsExactly(similarity.allSimilarItemIDs(4L), 3L)); assertTrue(containsExactly(similarity.allSimilarItemIDs(5L), 3L)); }