1+ package btp .oneP ;
2+
3+ import java .text .ParseException ;
4+ import java .text .SimpleDateFormat ;
5+ import java .util .ArrayList ;
6+ import java .util .Arrays ;
7+ import java .util .Collections ;
8+ import java .util .Comparator ;
9+ import java .util .Date ;
10+ import java .util .List ;
11+
12+ public class AgentTest {
13+ private static Comparator <Agentnew > comparatorForAgent = new Comparator <Agentnew >(){
14+ @ Override
15+ public int compare (Agentnew o1 , Agentnew o2 ) {
16+ if (!o1 .isWastage ()&&o2 .isWastage ()){
17+ return -1 ;
18+ }else if (o1 .isWastage ()&&!o2 .isWastage ()){
19+ return 1 ;
20+ }else {
21+ if (o1 .getLastVideoTime ().before (o2 .getLastVideoTime ())){
22+ return -1 ;
23+ }else if (o1 .getLastVideoTime ().after (o2 .getLastVideoTime ())){
24+ return 1 ;
25+ }else {
26+ if (o1 .getAllocateCount ()<o2 .getAllocateCount ()){
27+ return -1 ;
28+ }else if (o1 .getAllocateCount ()>o2 .getAllocateCount ()){
29+ return 1 ;
30+ }else {
31+ return 0 ;
32+ }
33+ }
34+ }
35+ }
36+ };
37+
38+ public static void main (String [] args ) throws ParseException {
39+ SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" );
40+ // TODO Auto-generated method stub
41+ List <Agentnew > userListTemp = new ArrayList <Agentnew >();
42+ userListTemp .add (new Agentnew (sdf .parse ("2001-3-20 05:05:09" ),true ,2 ));
43+ userListTemp .add (new Agentnew (sdf .parse ("2002-3-20 05:05:09" ),true ,2 ));
44+ userListTemp .add (new Agentnew (sdf .parse ("2001-3-20 06:05:09" ),true ,3 ));
45+ userListTemp .add (new Agentnew (sdf .parse ("2001-3-20 05:05:09" ),true ,4 ));
46+ userListTemp .add (new Agentnew (sdf .parse ("2001-3-20 05:05:09" ),false ,2 ));
47+ userListTemp .add (new Agentnew (sdf .parse ("2001-3-20 05:05:09" ),true ,2 ));
48+ userListTemp .add (new Agentnew (sdf .parse ("2001-3-20 05:05:09" ),false ,4 ));
49+ userListTemp .add (new Agentnew (sdf .parse ("2001-3-20 05:05:09" ),true ,2 ));
50+ userListTemp .add (new Agentnew (sdf .parse ("2001-3-20 05:05:09" ),false ,5 ));
51+ userListTemp .add (new Agentnew (sdf .parse ("2001-3-20 05:05:09" ),false ,0 ));
52+ userListTemp .add (new Agentnew (sdf .parse ("2001-3-20 05:05:09" ),true ,2 ));
53+ userListTemp .add (new Agentnew (sdf .parse ("2001-3-20 05:05:09" ),true ,6 ));
54+
55+ Collections .sort (userListTemp ,comparatorForAgent );
56+
57+ for (Agentnew a :userListTemp ){
58+ System .out .println (a );
59+ }
60+
61+ }
62+
63+ }
64+
65+ class Agentnew {
66+ //上次接视频时间
67+ private Date lastVideoTime = new Date ();
68+ //上次分配是否未接
69+ private boolean wastage ;
70+ //分配次数
71+ private int allocateCount ;
72+
73+
74+ public Agentnew (Date lastVideoTime , boolean wastage , int allocateCount ) {
75+ super ();
76+ this .lastVideoTime = lastVideoTime ;
77+ this .wastage = wastage ;
78+ this .allocateCount = allocateCount ;
79+ }
80+ public Date getLastVideoTime () {
81+ return lastVideoTime ;
82+ }
83+ public void setLastVideoTime (Date lastVideoTime ) {
84+ this .lastVideoTime = lastVideoTime ;
85+ }
86+ public boolean isWastage () {
87+ return wastage ;
88+ }
89+ public void setWastage (boolean wastage ) {
90+ this .wastage = wastage ;
91+ }
92+ public int getAllocateCount () {
93+ return allocateCount ;
94+ }
95+ public void setAllocateCount (int allocateCount ) {
96+ this .allocateCount = allocateCount ;
97+ }
98+ @ Override
99+ public String toString () {
100+ return "Agentnew [ wastage=" + wastage +",lastVideoTime=" + new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" ).format (lastVideoTime ) + ", allocateCount=" + allocateCount +"]" ;
101+ }
102+
103+ }
0 commit comments