?? caseinformationcomparator.java
字號:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package eti.bi.alphaminer.vo;
import java.util.Comparator;
/**
* CaseInformationComparator is a class used to set CaseInformation stored
* in a CaseInfoList based on different criteria.
*/
public class CaseInformationComparator implements Comparator {
/**
* Different kind of sorting criteria
*/
public static final int SCORE = 0;
public static final int CASE_ID = 1;
public static final int INDUSTRY = 2;
public static final int PROBLEM_TYPE = 3;
public static final int BUSINESS_OBJECTIVE = 4;
public static final int DATAMINING_GOAL = 5;
public static final int COMPANY_NAME = 6;
/**
* Sorting criteria currently used
*/
private int m_SortBy;
/**
* Current sorting order
*/
private boolean m_Ascending;
/**
* Constructs a CaseInformationComparator
*/
public CaseInformationComparator() {
super();
setSortBy(SCORE);
setAscending(false);
}
/**
* Gets the sorting criteria used.
* @return the sorting criteria used.
*/
public int getSortBy() {
return m_SortBy;
}
/**
* Sets the sorting criteria used.
* @param a_SortBy the sorting criteria to be set.
*/
public void setSortBy(int a_SortBy) {
m_SortBy = a_SortBy;
}
/**
* Gets the sorting order used.
* @return true if the current sorting order is ascending; false otherwise.
*/
public boolean getAscending() {
return m_Ascending;
}
/**
* Sets the sorting order.
* @param a_IsAscending set the sorting order used.
*/
public void setAscending(boolean a_IsAscending) {
m_Ascending = a_IsAscending;
}
/**
* @see java.util.Comparator#compare(Object, Object)
*/
public int compare(Object a_Obj1, Object a_Obj2) {
CaseInformation info1 = (CaseInformation) a_Obj1;
CaseInformation info2 = (CaseInformation) a_Obj2;
int sortBy = getSortBy();
if (sortBy == SCORE)
return compareNumber(info1.getScore(), info2.getScore());
else if (sortBy == CASE_ID)
return compareString(info1.getCaseID(), info2.getCaseID());
else if (sortBy == INDUSTRY)
return compareString(info1.getIndustry(), info2.getIndustry());
else if (sortBy == PROBLEM_TYPE)
return compareString(
info1.getProblemType(),
info2.getProblemType());
else if (sortBy == BUSINESS_OBJECTIVE)
return compareString(
info1.getBusinessObjective(),
info2.getBusinessObjective());
else if (sortBy == DATAMINING_GOAL)
return compareString(
info1.getDataMiningGoal(),
info2.getDataMiningGoal());
else if (sortBy == COMPANY_NAME)
return compareString(
info1.getCompanyName(),
info2.getCompanyName());
else
return 1;
}
/**
* Compares values of two numbers for sorting them in ascending or
* decending order.
* @param a_Num1 one of the two numbers to be compared.
* @param a_Num2 one of the two numbers to be copmared.
* @return if numbers are to be sort in ascending order,
* return 1 if a_Num1 is greater than a_Num2,
* return 0 if they are equal or return -1 if a_Num1 is smaller than a_Num2;
* otherwise, return 1 if a_Num1 is smaller than a_Num2,
* return 0 if they are equal or return -1 if a_Num1 is greater than a_Num2.
*/
private int compareNumber(double a_Num1, double a_Num2) {
if (getAscending()) {
if (a_Num1 > a_Num2)
return 1;
else if (a_Num1 == a_Num2)
return 0;
else
return -1;
} else {
if (a_Num1 < a_Num2)
return 1;
else if (a_Num1 == a_Num2)
return 0;
else
return -1;
}
}
/**
* Compares values of two strings for sorting them in ascending or
* decending order.
* @param a_String1 one of the two strings to be compared.
* @param a_String2 one of the two strings to be compared.
* @return if strings are to be sort in ascending order,
* return 1 if a_String1 is greater than a_String2,
* return 0 if they are equal or return -1 if a_String1 is smaller than a_String2;
* otherwise, return 1 if a_String1 is smaller than a_String2,
* return 0 if they are equal or return -1 if a_String1 is greater than a_String2.
*/
private int compareString(String a_String1, String a_String2) {
int result = a_String1.compareToIgnoreCase(a_String2);
if (getAscending()) {
if (result > 0)
return 1;
else if (result == 0)
return 0;
else
return -1;
} else {
if (result < 0)
return 1;
else if (result == 0)
return 0;
else
return -1;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -