⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 questioncomparator.java

📁 一个在线学习系统的服务端SERVLET程序
💻 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 + -