AdsOptimizationImpl implements AdsOptimization { @Override public AdsOptimization deDup() { if (_candidateAds.size() == 0) { return this; } Set<Long> campaignSet = new HashSet<Long>(); for (Iterator<AdsStatsInfo> iterator = _candidateAds.iterator(); iterator.hasNext();) { Long cid = iterator.next().getCampaignId(); if (campaignSet.contains(cid)) { iterator.remove(); } else { campaignSet.add(cid); } } return this; } AdsOptimizationImpl(List<AdsStatsInfo> candidateAds); @Override List<AdsStatsInfo> filterCandidateAds(Inventory inventory, float minRelevanceScore, float minReservePrice); @Override AdsOptimization filterAds(Inventory inventory, float minRelevanceScore, float minReservePrice); @Override AdsOptimization selectTopK(int k); @Override AdsOptimization adsPricingAndAllocation(Inventory inventory, float mainlineReservePrice); @Override String toString(); @Override AdsOptimization deDup(); @Override boolean equals(Object o); @Override int hashCode(); @Override List<AdsStatsInfo> showResult();  }
@Test public void deDupShouldReturnAValidOutput() { System.out.println("deDupShouldReturnAValidOutput"); AdsOptimization result = ads.deDup(); List<AdsStatsInfo> adsStatsInfoList = new ArrayList<AdsStatsInfo>(); AdsStatsInfo adsStatsInfo = new AdsStatsInfo((long)66, (long)1231, 0.5f, 0.8f, 0.9f, 5.0f, true); adsStatsInfoList.add(adsStatsInfo); adsStatsInfo = new AdsStatsInfo((long)67, (long)1234, 0.67f, 0.7f, 0.8f, 6.5f, true); adsStatsInfoList.add(adsStatsInfo); AdsOptimizationImpl expected = new AdsOptimizationImpl(adsStatsInfoList); assertEquals(expected, result); }