没有为我的case类定义隐式排序

时间:2016-12-18 22:43:57

标签: scala

我有一个案例类如下:

case class AGG_RECON_4( var VOL_PROBE_DL_VOL:Int, var VOL_PROBE_FREE_VOL:Int, var VOL_PROBE_TOT_VOL:Int, VOL_NW_UL_VOL:Int,VOL_NW_DL_VOL:Int, VOL_NW_FREE_VOL:Int, VOL_NW_TOT_VOL:Int, VOL_CHG_UL_VOL:Int,
                    VOL_CHG_DL_VOL:Int, VOL_CHG_FREE_VOL:Int, VOL_CHG_TOT_VOL:Int, VOL_DXE_Session_End_Time:String, VOL_NW_Session_End_Time:String,
                    VOL_CHG_Session_End_Time:String, VOL_Session_Closed_Time:String, VOL_DXE_Is_Completed:Boolean, VOL_NW_Is_Completed:Boolean, VOL_CHG_Is_Completed:Boolean, VOL_Is_Closed:Boolean, VOL_Session_Category:String) extends Serializable

case class AGG_RECON_3( CHG_ROAM_TYPE:String, CHG_APN:String,
                    CHG_APN_Category:String, CHG_Charging_Characteristics:String, CHG_Rate_Plan:String, CHG_Rating_Group:String, var CHG_CDR_Count:Int, var VOL_PROBE_UL_VOL:Int) extends Serializable

case class AGG_RECON_2(NW_First_Report_Time:String, NW_Last_Report_Time:String, NW_Session_Start_Time:String, NW_IMSI:String, NW_MSISDN:String, NW_RAT_Type:String, NW_ROAM_TYPE:String, NW_APN:String, NW_APN_Category:String, NW_Charging_Characteristics:String, var NW_CDR_Count:Int,
                   CHG_First_Report_Time:String, CHG_Last_Report_Time:String, CHG_Session_Start_Time:String, CHG_IMSI:String, CHG_MSISDN:String) extends Serializable


case class AGG_RECON(SUBSCRIBER_ID:String, ChargingID:String ,NodeID:String, START_TIME:String, DXE_First_Report_Time:String, DXE_Last_Report_Time:String, DXE_Session_Start_Time:String, DXE_Bearer_Creation_Time:String, DXE_IMSI:String, DXE_MSISDN:String, DXE_RAT_Type:String,
                 DXE_Subscriber_Type:String, DXE_VPMN:String, DXE_ROAM_TYPE:String, DXE_APN:String, DXE_APN_Category:String, DXE_Charging_Characteristics:String,var DXE_CDR_Count:Int,agg_recon_2:AGG_RECON_2,agg_recon_3:AGG_RECON_3,agg_recon_4:AGG_RECON_4) extends Ordered[AGG_RECON] with Serializable
{

def compare(that: AGG_RECON): Int = {

var formatter: DateTimeFormatter = null
var d1: DateTime= //..
var d2: DateTime =//..



return d1.compareTo(d2)

}

}

然后我去了我的案例类实例;但是,当我尝试对它进行排序时:

val elements=//Array[AGG_RECONN]
val sorted_cdrs=elements().sorted[AGG_RECON]

我得到:没有为AGG_RECON定义隐式排序。

1 个答案:

答案 0 :(得分:0)

请勿在{{1​​}}中实施Ordered。相反,请定义AGG_RECON implicit,如下所示:

Ordering[AGG_RECON]

(旁注:是否真的有必要使用UPPER_CASE名称?它确实与惯例冲突。)