RecommenderUtils { public static void filterAlreadyActedOn(List<RecommendedItemVO<Integer, Integer>> recommendedItems, List<ItemVO<Integer, Integer>> itemsActedOn) { if (recommendedItems == null || recommendedItems.size() == 0 || itemsActedOn == null || itemsActedOn.size() == 0) { return; } Iterator<RecommendedItemVO<Integer, Integer>> recommendedItemsIterator = recommendedItems.iterator(); RecommendedItemVO<Integer, Integer> currentRecommendedItem; Set<ItemVO<Integer, Integer>> items = new HashSet<ItemVO<Integer, Integer>>(itemsActedOn); while (recommendedItemsIterator.hasNext()) { currentRecommendedItem = recommendedItemsIterator.next(); if (items.contains(currentRecommendedItem.getItem())) { recommendedItemsIterator.remove(); } } }  static List<RecommendedItemVO<Integer, Integer>> filterDuplicates(
            List<RecommendedItemVO<Integer, Integer>> recommendedItems, boolean useAveragePredictionValues); static void filterAlreadyActedOn(List<RecommendedItemVO<Integer, Integer>> recommendedItems,
                                            List<ItemVO<Integer, Integer>> itemsActedOn);  }
@Test public void testFilterAlreadyActedOn_Nothing_To_Filter_Null() { List<RecommendedItemVO<Integer, Integer>> recommendedItems = new ArrayList<RecommendedItemVO<Integer, Integer>>(); List<RecommendedItemVO<Integer, Integer>> expectedFilteredRecommendedItems; List<ItemVO<Integer, Integer>> actedOnItems = null; recommendedItems.add(rItem1_1); recommendedItems.add(rItem2_1); recommendedItems.add(rItem3_1); recommendedItems.add(rItem4_1); recommendedItems.add(rItem5_1); expectedFilteredRecommendedItems = recommendedItems; filterAlreadyActedOn(recommendedItems, actedOnItems); assertTrue(expectedFilteredRecommendedItems.containsAll(recommendedItems)); }
@Test public void testFilterAlreadyActedOn_Nothing_To_Filter_Empty() { List<RecommendedItemVO<Integer, Integer>> recommendedItems = new ArrayList<RecommendedItemVO<Integer, Integer>>(); List<RecommendedItemVO<Integer, Integer>> expectedFilteredRecommendedItems; List<ItemVO<Integer, Integer>> actedOnItems = new ArrayList<ItemVO<Integer, Integer>>(); recommendedItems.add(rItem1_1); recommendedItems.add(rItem2_1); recommendedItems.add(rItem3_1); recommendedItems.add(rItem4_1); recommendedItems.add(rItem5_1); expectedFilteredRecommendedItems = recommendedItems; filterAlreadyActedOn(recommendedItems, actedOnItems); assertTrue(expectedFilteredRecommendedItems.containsAll(recommendedItems)); }
@Test public void testFilterAlreadyActedOn() { List<RecommendedItemVO<Integer, Integer>> recommendedItems = new ArrayList<RecommendedItemVO<Integer, Integer>>(); List<RecommendedItemVO<Integer, Integer>> expectedFilteredRecommendedItems = new ArrayList<RecommendedItemVO<Integer, Integer>>(); List<ItemVO<Integer, Integer>> actedOnItems = new ArrayList<ItemVO<Integer, Integer>>(); recommendedItems.add(rItem1_1); recommendedItems.add(rItem2_1); recommendedItems.add(rItem3_1); recommendedItems.add(rItem4_1); recommendedItems.add(rItem5_1); actedOnItems.add(item1); actedOnItems.add(item3); expectedFilteredRecommendedItems.add(rItem2_1); expectedFilteredRecommendedItems.add(rItem4_1); expectedFilteredRecommendedItems.add(rItem5_1); filterAlreadyActedOn(recommendedItems, actedOnItems); assertTrue(expectedFilteredRecommendedItems.containsAll(recommendedItems)); }
@Test public void testFilterAlreadyActedOn_All() { List<RecommendedItemVO<Integer, Integer>> recommendedItems = new ArrayList<RecommendedItemVO<Integer, Integer>>(); List<RecommendedItemVO<Integer, Integer>> expectedFilteredRecommendedItems = new ArrayList<RecommendedItemVO<Integer, Integer>>(); List<ItemVO<Integer, Integer>> actedOnItems = new ArrayList<ItemVO<Integer, Integer>>(); recommendedItems.add(rItem1_1); recommendedItems.add(rItem2_1); recommendedItems.add(rItem3_1); recommendedItems.add(rItem4_1); recommendedItems.add(rItem5_1); actedOnItems.add(item1); actedOnItems.add(item2); actedOnItems.add(item3); actedOnItems.add(item4); actedOnItems.add(item5); filterAlreadyActedOn(recommendedItems, actedOnItems); assertTrue(expectedFilteredRecommendedItems.containsAll(recommendedItems)); }
@Test @Ignore public void testFilterAlreadyActedOnPerformance(){ List<RecommendedItemVO<Integer, Integer>> recItems = generateRecommendedItems1ToNNoDuplicates(1000); List<ItemVO<Integer, Integer>> items = generateItems1ToNNoDuplicates(500); Stopwatch sw = new Stopwatch(); sw.start(); for (int i = 0; i < 1000; i++) { RecommenderUtils.filterAlreadyActedOn(recItems,items); } System.out.println("time for 1000 filtering steps: " + sw.stop()); }