我想使用类的方法对我的Deque<Card>
集合的内容进行排序。Card
getRealValue()
public class Card implements Comparable<Card> {
private final int value;
private final CardType cardType;
public Card(int value, CardType cardType) {
this.value = value;
this.cardType = cardType;
}
public int getRealValue() {
int realValue = this.value == 1 ? 52 : 0;
return realValue + this.value * 4 + this.cardType.ordinal();
}
public int compareTo(Card o) {
return this.getRealValue() - o.getRealValue();
}
}
这是我的 CardType 枚举
public enum CardType {
CLUB("♣"),
SPADE("♠"),
HEART("♥"),
DIAMOND("♦");
public final String icon;
private CardType(String icon) {
this.icon = icon;
}
}
我想根据我的 Deque 排序realValue()