-2

我有这堂课:

public class Turn {

public boolean turnMoved;
public int moveSelectionX;
public int moveSelectionY;
public int moveTargetX;
public int moveTargetY;

public boolean turnFired;
public int shotSelectionX;
public int shotSelectionY;
public int shotTargetX;
public int shotTargetY;

//Set this to true when doing a turn if we fired before moving
//Else if we do move/shot in the wrong order, we might select an empty cell
boolean firedFirst = false;
}

在我的程序的其他地方,我创建了这些对象的列表。列表完成后,我想按此顺序对列表进行排序,以便所有满足 1. 的对象都位于列表的前面,依此类推:

  1. turnMoved && turnFired == true
  2. 转身==真
  3. 转身 == 真
  4. turnMoved && turnFired == false

最简单的方法是什么?

4

1 回答 1

3

让你的班级实现Comparable<Turn>,写一个compareTo反映你的偏好的,并用Collections.sort它来对列表进行排序。

于 2013-04-05T15:38:06.300 回答