java 耗油退件



import java.util.*;

public class FriendRecommend {
 Map<String, List<Recommend>> totalMap = new Hashtable<String, List<Recommend>>();

 public void getReconList(String UserId) {
  if (totalMap.containsKey(UserId)) {
   List<Recommend> recommends = totalMap.get(UserId);
   // 打印Recommend //输出 recommend 内容
  } else {

   List<String> friends = getFriendsListForUser(UserId);
   Map<String, Recommend> recommendMap = new HashMap<String, Recommend>();
   for (String friend : friends) {
    List<String> recomList = getPurchaseForUser(friend);
    for (String prod : recomList) {
     if (recommendMap.containsKey(prod)) {
      Recommend recommend = recommendMap.get(prod);
      recommend.setFrequency(recommend.getFrequency() + 1);
      recommendMap.put(prod, recommend);
     } else {
      recommendMap.put(prod, new Recommend(prod, 1));
     }
    }
   }
   Iterator<String> iter = recommendMap.keySet().iterator();
   List<Recommend> recommend = new ArrayList<FriendRecommend.Recommend>();
   String product = iter.next();
   Recommend recProd = recommendMap.get(product);
   recommend.add(recProd);
   Collections.sort(recommend, new sortByFrequency());
   totalMap.put(UserId, recommend);
   // 输出 recommend 内容

  }
 }

 class Recommend {
  public Recommend(String ProdId, int frequency) {
   this.productID = ProdId;
   this.frequency = frequency;
  }

  private int frequency;
  private String productID;

  public int getFrequency() {
   return frequency;
  }

  public void setFrequency(int frequency) {
   this.frequency = frequency;
  }

  public String getProductID() {
   return productID;
  }

  public void setProductID(String productID) {
   this.productID = productID;
  }

 }

 private static final class sortByFrequency implements Comparator<Recommend> {

  public int compare(Recommend o1, Recommend o2) {
   // TODO Auto-generated method stub
   return o2.getFrequency() - o1.getFrequency();
  }

 }

 public static List<String> getPurchaseForUser(String CustomerId) {
  return new ArrayList<String>();

 }

 public static List<String> getFriendsListForUser(String CustomerId) {
  return new ArrayList<String>();
 }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值