package com.imooc; |
import java.util.Comparator; |
public class PukeComparator implements Comparator <Puke>{ |
|
|
public String[] values = { "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "J" , "Q" , "K" , "A" }; |
|
public int stringToInt(String[] str,String value){ |
int i = 0 ; |
while (!str[i].equals(value)){ |
i ++; |
} |
return i+ 2 ; |
} |
|
@Override |
public int compare(Puke o1, Puke o2) { |
|
Integer index1 = stringToInt(values,o1.value); |
Integer index2 = stringToInt(values,o2.value); |
int no = index1 - index2; |
if (no == 0 ) { |
return o1.huase.compareTo(o2.huase); |
} else if (no > 0 ){ |
return 1 ; |
//return index1.compareTo(index2); |
} else { |
return - 1 ; |
} |
|
|
|
|
} |
|
|
|
} |
初级程序员
by: 云代码会员 发表于:2016-10-15 07:47:58 顶(0) | 踩(1) 回复
頂
回复评论