📄 questioncomparator.java
字号:
package eols.logic.test;
import java.util.Comparator;
import eols.bean.test.Question;
public class QuestionComparator implements Comparator {
/** The sorting order of the hardNos */
private boolean asc = false;
/** Constructors */
public QuestionComparator() {
this(false);
}
public QuestionComparator(boolean asc) {
this.asc = asc;
}
/** Set the sorting order of the questions */
public void setAsc(boolean asc) {
this.asc = asc;
}
/** Do not need to compare the equality with other comparators */
public boolean equals(Object obj){
return false;
}
/**
* Comparator the question, based on the <code>hardNo</code> of each question
*
* @param o1 The first question to compare
* @param o2 The second question to compare
* @return Whether the hardNo of the first question is larger than the second one
*/
public int compare(Object o1, Object o2){
if (o1 == null)
return -1;
if (o2 == null)
return 1;
Question q1 = (Question)o1;
Question q2 = (Question)o2;
if (!asc) {
return q1.getHardNo() > q2.getHardNo() ? 1 :
q1.getHardNo() == q2.getHardNo() ? 0 : -1;
} else {
return q1.getHardNo() > q2.getHardNo() ? -1 :
q1.getHardNo() == q2.getHardNo() ? 0 : 1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -