「Talk is cheap. Show me the code」
代码语言:javascript复制 String key = user.getUserId() user.getEmail();
List<String> likes = likeMapper.queryLikenames();
Map<String,Integer> map = new HashMap();
for (String like : likes) {
if (like != null && cluster.hget(key,like) != null) {
Integer likeDegree = Integer.parseInt(cluster.hget(key,like));
map.put(like,likeDegree);
}
}
// 遍历map找出前三爱好
String[] like= new String[];
int[] value = new int[];
for (String likeKey : map.keySet()) {
int likeValue = map.get(likeKey);
for (int i = ; i < value.length; i ) {
if (likeValue > value[i]) {
// 替换
for (int j = value.length-; j > i; j--) {
value[j] = value[j-];
like[j] = like[j-];
}
value[i] = likeValue;
like[i]= likeKey;
break;
}
}
}
String bestLike = like[];
String middleLike = like[];
String lastLike = like[];
int total = value[] value[] value[];
if (total == ) {
total = ;
}