`

对集合中的对象做排序

 
阅读更多
final Map<Long, Integer> cardIdScountMap = this.buildCardIdScountMap(cardIdSet);

			Collections.sort(cardList, new Comparator<Card>() {
				@Override
				public int compare(Card o1, Card o2) {
					// 先比较scount,再比较是否有名片,最后再比较createTime
					if (cardIdScountMap.get(o1.getCardId()) > cardIdScountMap.get(o2.getCardId())) {
						return 1;
					}
					else if (!StringUtils.isEmpty(o1.getPic()) && StringUtils.isEmpty(o2.getPic())) {
						return 1;
					}
					else if (StringUtils.isEmpty(o1.getPic()) && !StringUtils.isEmpty(o2.getPic())) {
						return -1;
					}
					else if (o1.getCreateTime().after(o2.getCreateTime())) {
						return 1;
					}
					else {
						return -1;
					}
				}
			});
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics