|
|
|
@ -1,119 +1,149 @@
|
|
|
|
|
package cn.edu.hust.session;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import scala.math.Ordered;
|
|
|
|
|
|
|
|
|
|
// CategorySortKey类实现了Ordered接口(用于定义比较规则)以及Serializable接口(用于支持对象的序列化操作)
|
|
|
|
|
// 该类主要用于定义分类排序相关的键,通过比较不同实例中的点击数、订单数和支付数来确定排序规则
|
|
|
|
|
public class CategorySortKey implements Ordered<CategorySortKey>, java.io.Serializable {
|
|
|
|
|
|
|
|
|
|
// 用于记录点击次数的成员变量
|
|
|
|
|
private Long clickCount;
|
|
|
|
|
// 用于记录订单次数的成员变量
|
|
|
|
|
private Long orderCount;
|
|
|
|
|
// 用于记录支付次数的成员变量
|
|
|
|
|
private Long payCount;
|
|
|
|
|
|
|
|
|
|
// 实现Ordered接口中的compare方法,用于定义两个CategorySortKey实例的比较逻辑
|
|
|
|
|
// 根据点击数、订单数、支付数依次比较来确定两个实例的大小关系
|
|
|
|
|
@Override
|
|
|
|
|
public int compare(CategorySortKey categorySortKey) {
|
|
|
|
|
if(clickCount-categorySortKey.getClickCount()!=0)
|
|
|
|
|
{
|
|
|
|
|
return (int) (clickCount-categorySortKey.getClickCount());
|
|
|
|
|
}else if(clickCount-categorySortKey.getClickCount()==0&&orderCount-categorySortKey.getOrderCount()!=0)
|
|
|
|
|
{
|
|
|
|
|
return (int) (orderCount-categorySortKey.getOrderCount());
|
|
|
|
|
// 首先比较点击数,如果点击数不同,则根据点击数的差值返回比较结果
|
|
|
|
|
if (clickCount - categorySortKey.getClickCount()!= 0) {
|
|
|
|
|
return (int) (clickCount - categorySortKey.getClickCount());
|
|
|
|
|
}
|
|
|
|
|
// 如果点击数相同,接着比较订单数,若订单数不同,则根据订单数的差值返回比较结果
|
|
|
|
|
else if (clickCount - categorySortKey.getClickCount() == 0 && orderCount - categorySortKey.getOrderCount()!= 0) {
|
|
|
|
|
return (int) (orderCount - categorySortKey.getOrderCount());
|
|
|
|
|
}
|
|
|
|
|
else if(clickCount-categorySortKey.getClickCount()==0&&orderCount-categorySortKey.getOrderCount()==0&&payCount-categorySortKey.getPayCount()!=0)
|
|
|
|
|
return (int) (payCount-categorySortKey.getPayCount());
|
|
|
|
|
// 如果点击数和订单数都相同,再比较支付数,若支付数不同,则根据支付数的差值返回比较结果
|
|
|
|
|
else if (clickCount - categorySortKey.getClickCount() == 0 && orderCount - categorySortKey.getOrderCount() == 0 && payCount - categorySortKey.getPayCount()!= 0)
|
|
|
|
|
return (int) (payCount - categorySortKey.getPayCount());
|
|
|
|
|
// 如果点击数、订单数和支付数都相同,则认为两个实例相等,返回0
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 实现Ordered接口中的$less方法,用于判断当前实例是否小于给定的CategorySortKey实例
|
|
|
|
|
@Override
|
|
|
|
|
public boolean $less(CategorySortKey categorySortKey) {
|
|
|
|
|
if(clickCount<categorySortKey.getClickCount())
|
|
|
|
|
{
|
|
|
|
|
// 首先比较点击数,如果当前实例的点击数小于给定实例的点击数,则返回true,表示当前实例小于给定实例
|
|
|
|
|
if (clickCount < categorySortKey.getClickCount()) {
|
|
|
|
|
return true;
|
|
|
|
|
}else if(clickCount==categorySortKey.getClickCount()&&orderCount<categorySortKey.getOrderCount())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
// 如果点击数相等,接着比较订单数,若当前实例的订单数小于给定实例的订单数,则返回true
|
|
|
|
|
else if (clickCount == categorySortKey.getClickCount() && orderCount < categorySortKey.getOrderCount()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if(clickCount==categorySortKey.getClickCount()&&orderCount==categorySortKey.getOrderCount()&&payCount<categorySortKey.getPayCount())
|
|
|
|
|
// 如果点击数和订单数都相等,再比较支付数,若当前实例的支付数小于给定实例的支付数,则返回true
|
|
|
|
|
else if (clickCount == categorySortKey.getClickCount() && orderCount == categorySortKey.getOrderCount() && payCount < categorySortKey.getPayCount())
|
|
|
|
|
return true;
|
|
|
|
|
// 如果以上比较都不满足小于的条件,则返回false,表示当前实例不小于给定实例
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 实现Ordered接口中的$greater方法,用于判断当前实例是否大于给定的CategorySortKey实例
|
|
|
|
|
@Override
|
|
|
|
|
public boolean $greater(CategorySortKey categorySortKey) {
|
|
|
|
|
if(clickCount>categorySortKey.getClickCount())
|
|
|
|
|
{
|
|
|
|
|
// 首先比较点击数,如果当前实例的点击数大于给定实例的点击数,则返回true,表示当前实例大于给定实例
|
|
|
|
|
if (clickCount > categorySortKey.getClickCount()) {
|
|
|
|
|
return true;
|
|
|
|
|
}else if(clickCount==categorySortKey.getClickCount()&&orderCount>categorySortKey.getOrderCount())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
// 如果点击数相等,接着比较订单数,若当前实例的订单数大于给定实例的订单数,则返回true
|
|
|
|
|
else if (clickCount == categorySortKey.getClickCount() && orderCount > categorySortKey.getOrderCount()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if(clickCount==categorySortKey.getClickCount()&&orderCount==categorySortKey.getOrderCount()&&payCount>categorySortKey.getPayCount())
|
|
|
|
|
// 如果点击数和订单数都相等,再比较支付数,若当前实例的支付数大于给定实例的支付数,则返回true
|
|
|
|
|
else if (clickCount == categorySortKey.getClickCount() && orderCount == categorySortKey.getOrderCount() && payCount > categorySortKey.getPayCount())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// 如果以上比较都不满足大于的条件,则返回false,表示当前实例不大于给定实例
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 实现Ordered接口中的$less$eq方法,用于判断当前实例是否小于等于给定的CategorySortKey实例
|
|
|
|
|
@Override
|
|
|
|
|
public boolean $less$eq(CategorySortKey categorySortKey) {
|
|
|
|
|
if($less(categorySortKey))
|
|
|
|
|
{
|
|
|
|
|
// 如果当前实例小于给定实例(通过$less方法判断),则返回true
|
|
|
|
|
if ($less(categorySortKey)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if(clickCount==categorySortKey.getClickCount()&&orderCount==categorySortKey.getOrderCount()&&payCount==categorySortKey.getPayCount())
|
|
|
|
|
// 如果点击数、订单数和支付数都与给定实例相等,则也返回true,表示小于等于
|
|
|
|
|
else if (clickCount == categorySortKey.getClickCount() && orderCount == categorySortKey.getOrderCount() && payCount == categorySortKey.getPayCount())
|
|
|
|
|
return true;
|
|
|
|
|
// 其他情况返回false
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 实现Ordered接口中的$greater$eq方法,用于判断当前实例是否大于等于给定的CategorySortKey实例
|
|
|
|
|
@Override
|
|
|
|
|
public boolean $greater$eq(CategorySortKey categorySortKey) {
|
|
|
|
|
if($greater(categorySortKey))
|
|
|
|
|
{
|
|
|
|
|
// 如果当前实例大于给定实例(通过$greater方法判断),则返回true
|
|
|
|
|
if ($greater(categorySortKey)) {
|
|
|
|
|
return true;
|
|
|
|
|
}else if(clickCount==categorySortKey.getClickCount()&&orderCount==categorySortKey.getOrderCount()&&payCount==categorySortKey.getPayCount())
|
|
|
|
|
}
|
|
|
|
|
// 如果点击数、订单数和支付数都与给定实例相等,则也返回true,表示大于等于
|
|
|
|
|
else if (clickCount == categorySortKey.getClickCount() && orderCount == categorySortKey.getOrderCount() && payCount == categorySortKey.getPayCount())
|
|
|
|
|
return true;
|
|
|
|
|
// 其他情况返回false
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 实现Ordered接口中的compareTo方法,与compare方法逻辑基本一致,用于定义比较规则
|
|
|
|
|
// 根据点击数、订单数、支付数依次比较来确定两个实例的大小关系
|
|
|
|
|
@Override
|
|
|
|
|
public int compareTo(CategorySortKey categorySortKey) {
|
|
|
|
|
if(clickCount-categorySortKey.getClickCount()!=0)
|
|
|
|
|
{
|
|
|
|
|
return (int) (clickCount-categorySortKey.getClickCount());
|
|
|
|
|
}else if(clickCount-categorySortKey.getClickCount()==0&&orderCount-categorySortKey.getOrderCount()!=0)
|
|
|
|
|
{
|
|
|
|
|
return (int) (orderCount-categorySortKey.getOrderCount());
|
|
|
|
|
}
|
|
|
|
|
else if(clickCount-categorySortKey.getClickCount()==0&&orderCount-categorySortKey.getOrderCount()==0&&payCount-categorySortKey.getPayCount()!=0)
|
|
|
|
|
return (int) (payCount-categorySortKey.getPayCount());
|
|
|
|
|
if (clickCount - categorySortKey.getClickCount()!= 0) {
|
|
|
|
|
return (int) (clickCount - categorySortKey.getClickCount());
|
|
|
|
|
} else if (clickCount - categorySortKey.getClickCount() == 0 && orderCount - categorySortKey.getOrderCount()!= 0) {
|
|
|
|
|
return (int) (orderCount - categorySortKey.getOrderCount());
|
|
|
|
|
} else if (clickCount - categorySortKey.getClickCount() == 0 && orderCount - categorySortKey.getOrderCount() == 0 && payCount - categorySortKey.getPayCount()!= 0)
|
|
|
|
|
return (int) (payCount - categorySortKey.getPayCount());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取点击次数的方法
|
|
|
|
|
public Long getClickCount() {
|
|
|
|
|
return clickCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置点击次数的方法
|
|
|
|
|
public void setClickCount(Long clickCount) {
|
|
|
|
|
this.clickCount = clickCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取订单次数的方法
|
|
|
|
|
public Long getOrderCount() {
|
|
|
|
|
return orderCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置订单次数的方法
|
|
|
|
|
public void setOrderCount(Long orderCount) {
|
|
|
|
|
this.orderCount = orderCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取支付次数的方法
|
|
|
|
|
public Long getPayCount() {
|
|
|
|
|
return payCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置支付次数的方法
|
|
|
|
|
public void setPayCount(Long payCount) {
|
|
|
|
|
this.payCount = payCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 同时设置点击次数、订单次数和支付次数的方法
|
|
|
|
|
public void set(Long clickCount, Long orderCount, Long payCount) {
|
|
|
|
|
this.clickCount = clickCount;
|
|
|
|
|
this.orderCount = orderCount;
|
|
|
|
|
this.payCount = payCount;
|
|
|
|
|
}//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|