2009 奋斗成果

package addressbook.model;

import javax.servlet.http.HttpServletRequest;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.*;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
import java.text.*;

//import Record;


//public class Test1 extends HttpServlet {
public class Test1 {
private static List optimizeSqlList = new ArrayList();
static{
//optimizeSqlList.add("truncate table `UserEntityIP`");
//optimizeSqlList.add("insert into `UserEntityIP` ( `id` , `userName`, `email` , `createDate`, `familyName` , `givenName` , `addressLine1`, `city` , `zipCode` , `stateOrProvince`, `country` , `gender` , `phone` , `birthday`, `affiliateMarker`)select `id` , `userName`, `email` , `createdDate`, `familyName` , `givenName` , `addressLine1`, `city` , `zipCode` , `stateOrProvince`, `country` , `gender` , `phone` , `birthday`, `affiliateMarker` from UserEntity");
//optimizeSqlList.add("truncate table `UserEntity_tmp`");
//optimizeSqlList.add("insert into UserEntity_tmp(mtime,ip,id) select max(lastaccess) mtime, ip ,UserId from UserSessionLog group by UserId");
optimizeSqlList.add("update UserEntity inner join(select max(lastaccess) mtime, ip ,UserId from UserSessionLog where UserId<>'' group by UserId) b2 on UserEntity.id=b2.UserId set UserEntity.ip=b2.ip");
}
private static List sqlList = new ArrayList();
static{
sqlList.add("select familyName,givenName from UserEntity where trim(ifnull(familyName,'')) <>'' and trim(ifnull(givenName,'')) <>'' group by familyName,givenName having count(*)>=2");
sqlList.add("select email from UserEntity where trim(ifnull(email,'')) <>''group by email having count(*)>=2");
sqlList.add("select addressLine1 from UserEntity where trim(ifnull(addressLine1,'')) <>''group by addressLine1 having count(*)>=2");
sqlList.add("select birthday from UserEntity where trim(ifnull(birthday,'')) <>''group by birthday having count(*)>=2");
sqlList.add("select phone from UserEntity where trim(ifnull(phone,'')) <>''group by phone having count(*)>=2");
sqlList.add("select city from UserEntity where trim(ifnull(city,'')) <>''group by city having count(*)>=2");
sqlList.add("select gender from UserEntity where trim(ifnull(gender,'')) <>''group by gender having count(*)>=2");
sqlList.add("select country from UserEntity where trim(ifnull(country,'')) <>''group by country having count(*)>=2");
sqlList.add("select zipCode from UserEntity where trim(ifnull(zipCode,'')) <>''group by zipCode having count(*)>=2");
sqlList.add("select ip from UserEntity where trim(ifnull(ip,'')) <>''group by ip having count(*)>=2");
sqlList.add("select substring(userName,3) as userName1 from UserEntity where trim(ifnull( substring(userName,3),'')) <>'' group by userName1 having count(*)>=2");
}
//static List output() throws Exception {
public static void load()
{
try {
Connection conn=initConnect();
Statement statement = conn.createStatement();
optimizeDB(statement,optimizeSqlList);
} catch (SQLException e) {
System.out.println("Load failure, please check it.");
}

}

public static List output(int scores,String startDate,String endDate, int choice,ArrayList blist,String user,String fieldSel,String checkValue,String checkValue2) throws Exception{
String dateSql="";
String orderSql="";
String frontSql="";
String sql = "";
String userNameSql = "";
int nScore=scores;

startDate=TransDate(startDate);
endDate=TransDate(endDate);

frontSql="select a.userName,a.familyName,a.givenName,a.email,a.addressLine1,a.zipCode,a.city,a.country,a.gender,a.phone,a.birthday,a.ip,a.createdDate from UserEntity a where 1=1";
orderSql=" order by a.email,a.phone,a.familyName,a.givenName,a.addressLine1,a.birthday,a.ip";

/*if(choice==0)
{
if ((startDate==null) || (startDate.equals("")))
{
if ((endDate==null) || (endDate.equals("")))
dateSql=" where 1=1";
}
else if((endDate==null) || (endDate.equals("")))
{
dateSql=" where a.createdDate>='"+startDate+"'";
}
else
{
dateSql=" where a.createdDate>='"+startDate+"' and a.createdDate<='"+endDate+"'";
}
}else
{*/
//if ((startDate==null) || (startDate.equals("")))

if(!isBlank(startDate)&& isBlank(endDate))
{
dateSql=" and a.createdDate>='"+startDate+"'";
}
if(isBlank(startDate)&& !isBlank(endDate))
{
dateSql=" and a.createdDate<='"+endDate+"'";
}
if(!isBlank(startDate)&& !isBlank(endDate))
{
dateSql=" and a.createdDate>='"+startDate+"' and a.createdDate<='"+endDate+"'";
}

if(!isBlank(user))
{
if( isBlank(checkValue)&& isBlank(checkValue2))
userNameSql= " and a."+ fieldSel + " regexp '"+ user +"'";
if( !isBlank(checkValue)&& isBlank(checkValue2))
userNameSql= " and a."+ fieldSel + " = '"+ user +"'";
if( isBlank(checkValue)&& !isBlank(checkValue2))
userNameSql= " and a."+ fieldSel + " regexp binary '"+ user +"'";
if( !isBlank(checkValue)&&!isBlank(checkValue2))
userNameSql= " and binary a."+ fieldSel + " = '"+ user +"'";
}

Connection conn=initConnect();
Statement statement = conn.createStatement();
Long startTime =System.currentTimeMillis();

//if(choice==0)
// sql = "select a.userName,a.familyName,a.givenName,a.email,a.addressLine1,a.zipCode,a.city,a.country,a.gender,a.phone,a.birthday,a.ip,a.createdDate from UserEntity a" ;
//else
System.out.println("choic="+choice);
if(choice==1)
{
int listSize=blist.size();
String[] strGroupArray1=new String[4];
String[] strGroupArray2=new String[4];
String[] strOnArray=new String[4];

for(int i=0;i {
if(null == blist.get(i) || blist.get(i).equals("")) {
//if(isBlank(blist.get(i))){
continue;
}
else
{

if(blist.get(i).equals("UserName"))
{
strGroupArray1[i]="substring(userName,3) as userName";
strGroupArray2[i]="substring(userName,3)";
strOnArray[i]="substring(a.userName,3)";
}
else
{
strGroupArray1[i]=blist.get(i).toString();
strGroupArray2[i]=blist.get(i).toString();
strOnArray[i]="a."+blist.get(i).toString();
}
}
}

if(listSize==1)
{
int i;
// sql = "select a.* from UserEntityIP a inner join ( select "+ blist.get(0)+" from UserEntityIP"
// + " group by "+ blist.get(0)+" having count(*)>=2) b on a."+blist.get(0)+"=b."+blist.get(0);
sql = "select a.userName,a.familyName,a.givenName,a.email,a.addressLine1,a.zipCode,a.city,a.country,a.gender,a.phone,a.birthday,a.ip,a.createdDate from UserEntity a inner join ( select "+ strGroupArray1[0]+" from UserEntityIP"
+ " group by "+ strGroupArray2[0]+" having count(*)>=2) b on "+strOnArray[0]+"=b."+blist.get(0);

}
else if(listSize==2)
{
sql = "select a.userName,a.familyName,a.givenName,a.email,a.addressLine1,a.zipCode,a.city,a.country,a.gender,a.phone,a.birthday,a.ip,a.createdDate from UserEntity a inner join ( select "+ strGroupArray1[0]+","+strGroupArray1[1] +" from UserEntityIP"
+ " group by "+ strGroupArray2[0]+","+strGroupArray2[1]+" having count(*)>=2) b on "+strOnArray[0]+"=b."+blist.get(0)
+" and "+strOnArray[1]+"=b."+blist.get(1);
}
else if(listSize==3)
{
sql = "select a.userName,a.familyName,a.givenName,a.email,a.addressLine1,a.zipCode,a.city,a.country,a.gender,a.phone,a.birthday,a.ip,a.createdDate from UserEntity a inner join ( select "+ strGroupArray1[0]+","+ strGroupArray1[1] +","+ strGroupArray1[2] +" from UserEntityIP"
+ " group by "+ strGroupArray2[0]+","+strGroupArray2[1] +","+strGroupArray2[2] +" having count(*)>=2) b on "+strOnArray[0]+"=b."+blist.get(0)
+" and "+strOnArray[1]+"=b."+blist.get(1)+" and "+strOnArray[2]+"=b."+blist.get(2);
}
else if(listSize==4)
{
sql = "select a.userName,a.familyName,a.givenName,a.email,a.addressLine1,a.zipCode,a.city,a.country,a.gender,a.phone,a.birthday,a.ip,a.createdDate from UserEntity a inner join ( select "+ strGroupArray1[0]+","+strGroupArray1[1] +","+strGroupArray1[2] +","+strGroupArray1[3] + " from UserEntityIP"
+ " group by "+ strGroupArray2[0]+","+strGroupArray2[1] +","+strGroupArray2[2] + ","+strGroupArray2[3] + " having count(*)>=2) b on "+strOnArray[0]+"=b."+blist.get(0)
+" and "+strOnArray[1]+"=b."+blist.get(1)+" and "+strOnArray[2]+"=b."+blist.get(2)+" and "+strOnArray[3]+"=b."+blist.get(3);
}
sql=sql+userNameSql+dateSql+orderSql;
}
else
sql=frontSql+userNameSql+dateSql+orderSql;


//System.out.println(sql);
//if(choice==2)
//{
// sql= "select userName,familyName,givenName,email,addressLine1,zipCode,city,country,gender,phone,birthday,ip,createdDate from UserEntity where userName like '%"+user+"%'";
//}
//else
//{
//sql= sql+ dateSql;
//sql= sql+ orderSql;
//}
System.out.println(sql);
ResultSet rs= statement.executeQuery(sql);

List recordList = new ArrayList();
while(rs.next()){
String fullName = rs.getString("familyName") +rs.getString("givenName");
String UserName = rs.getString("userName");
String firstName = rs.getString("familyName");
String secondName = rs.getString("givenName");
String email = rs.getString("email");
String address1 = rs.getString("addressLine1");
String zipCode = rs.getString("zipCode");
String city = rs.getString("city");
String country = rs.getString("country");
String gender = rs.getString("gender");
String phone = rs.getString("phone");
String birthday = rs.getString("birthday");
String ipStr = rs.getString("ip");
String CreateDate = rs.getString("createdDate");
// final String encoding = System.getProperty("file.encoding");
// String link="duplicatedUser.do?act=1&firstName="+java.net.URLEncoder.encode(firstName, encoding)
// +"&secondName="+java.net.URLEncoder.encode(secondName, encoding)+"&birthday="+java.net.URLEncoder.encode(birthday, encoding)
// +"&ip="+java.net.URLEncoder.encode(ipStr, encoding)+"&email="+java.net.URLEncoder.encode(email, encoding)+"&phone="+java.net.URLEncoder.encode(phone, encoding)+"&address="+java.net.URLEncoder.encode(address1, encoding);
//final String encoding = System.getProperty("file.encoding");
String link="dup.do?act=1&firstName="+firstName
+"&secondName="+secondName+"&birthday="+birthday
+"&ip="+ipStr+"&email="+email+"&phone="+phone+"&address="+address1;
//link=java.net.URLEncoder.encode(link, encoding);
link=link.replace(" ", "%20");
//System.out.println(link);

Record record = new Record( firstName,secondName, email,
address1, zipCode, city,
country, gender, phone, birthday,ipStr,CreateDate,UserName,link);
recordList.add(record);
}

/*List distinctFullNameList = getAttList(statement, sqlList.get(0), "familyName", "givenName");
List distinctEmailList = getAttList(statement, sqlList.get(1), "email",null);
List distinctAddress1List = getAttList(statement, sqlList.get(2), "addressLine1",null);
List distinctBirthdayList = getAttList(statement, sqlList.get(3), "birthday", null);
List distinctPhoneList = getAttList(statement, sqlList.get(4), "phone", null);
List distinctCityList = getAttList(statement, sqlList.get(5), "city", null);
List distinctGenderList = getAttList(statement, sqlList.get(6), "gender", null);
List distinctCountryList = getAttList(statement, sqlList.get(7), "country", null);
List distinctZipcodeList = getAttList(statement, sqlList.get(8), "zipCode", null);
List distinctIPList = getAttList(statement, sqlList.get(9), "ip", null);
List distinctuserNameList = getAttList(statement, sqlList.get(10), "userName1", null);
*/
String fullsql="select userName,familyName,givenName,email,addressLine1,zipCode,city,country,gender,phone,birthday,ip,createdDate from UserEntity ";
ResultSet dtrs= statement.executeQuery(fullsql);

Map FullNameMap = new HashMap();
Map EmailMap = new HashMap();
Map AddressMap = new HashMap();
Map BirthdayMap = new HashMap();
Map PhoneMap = new HashMap();
Map CityMap = new HashMap();
Map GenderMap = new HashMap();
Map CountryMap = new HashMap();
Map ZipcodeMap = new HashMap();
Map IPMap = new HashMap();
Map UserNameMap = new HashMap();

while(dtrs.next()){
String FullName = dtrs.getString("familyName")+dtrs.getString("givenName");
if (!isBlank(FullName))
{
if (FullNameMap.get(FullName)==null) FullNameMap.put(FullName, 1);
else FullNameMap.put(FullName, ((Integer)FullNameMap.get(FullName)).intValue()+1);
}

String strEmail = dtrs.getString("email");
if (!isBlank(strEmail))
{
if (EmailMap.get(strEmail)==null) EmailMap.put(strEmail, 1);
else EmailMap.put(strEmail, ((Integer)EmailMap.get(strEmail)).intValue()+1);
}

String strAddress = dtrs.getString("addressLine1");
if (!isBlank(strAddress))
{
if (AddressMap.get(strAddress)==null) AddressMap.put(strAddress, 1);
else AddressMap.put(strAddress, ((Integer)AddressMap.get(strAddress)).intValue()+1);
}

String strBirthday = dtrs.getString("birthday");
if (!isBlank(strBirthday))
{
if (BirthdayMap.get(strBirthday)==null) BirthdayMap.put(strBirthday, 1);
else BirthdayMap.put(strBirthday, ((Integer)BirthdayMap.get(strBirthday)).intValue()+1);
}

String strPhone = dtrs.getString("phone");
if (!isBlank(strPhone))
{
if (PhoneMap.get(strPhone)==null) PhoneMap.put(strPhone, 1);
else PhoneMap.put(strPhone, ((Integer)PhoneMap.get(strPhone)).intValue()+1);
}

String strCity = dtrs.getString("city");
if (!isBlank(strCity))
{
if (CityMap.get(strCity)==null) CityMap.put(strCity, 1);
else CityMap.put(strCity, ((Integer)CityMap.get(strCity)).intValue()+1);
}

String strGender = dtrs.getString("gender");
if (!isBlank(strGender))
{
if (GenderMap.get(strGender)==null) GenderMap.put(strGender, 1);
else GenderMap.put(strGender, ((Integer)GenderMap.get(strGender)).intValue()+1);
}

String strCountry = dtrs.getString("country");
if (!isBlank(strCountry))
{
if (CountryMap.get(strCountry)==null) CountryMap.put(strCountry, 1);
else CountryMap.put(strCountry, ((Integer)CountryMap.get(strCountry)).intValue()+1);
}

String strZipcode = dtrs.getString("zipCode");
if (!isBlank(strZipcode))
{
if (ZipcodeMap.get(strZipcode)==null) ZipcodeMap.put(strZipcode, 1);
else ZipcodeMap.put(strZipcode, ((Integer)ZipcodeMap.get(strZipcode)).intValue()+1);
}

String strIP = dtrs.getString("ip");
if (!isBlank(strIP))
{
if (IPMap.get(strIP)==null) IPMap.put(strIP, 1);
else IPMap.put(strIP, ((Integer)IPMap.get(strIP)).intValue()+1);
}

String strUserName = dtrs.getString("userName");
if (!isBlank(strUserName))
{
strUserName=strUserName.substring(2);
if (UserNameMap.get(strUserName)==null) UserNameMap.put(strUserName, 1);
else UserNameMap.put(strUserName, ((Integer)UserNameMap.get(strUserName)).intValue()+1);
}
}

for (Iterator> it = FullNameMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();//remove bland character string in the key fields
}
for (Iterator> it = EmailMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = AddressMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = BirthdayMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = PhoneMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = CityMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = GenderMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = CountryMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = ZipcodeMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = IPMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = UserNameMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}


List distinctFullNameList =new ArrayList();
List distinctEmailList = new ArrayList();
List distinctAddress1List = new ArrayList();
List distinctBirthdayList = new ArrayList();
List distinctPhoneList = new ArrayList();
List distinctCityList = new ArrayList();
List distinctGenderList = new ArrayList();
List distinctCountryList = new ArrayList();
List distinctZipcodeList = new ArrayList();
List distinctIPList = new ArrayList();
List distinctuserNameList = new ArrayList();

distinctFullNameList.addAll(FullNameMap.keySet());
distinctEmailList.addAll(EmailMap.keySet());
distinctAddress1List.addAll(AddressMap.keySet());
distinctBirthdayList.addAll(BirthdayMap.keySet());
distinctPhoneList.addAll(PhoneMap.keySet());
distinctCityList.addAll(CityMap.keySet());
distinctGenderList.addAll(GenderMap.keySet());
distinctCountryList.addAll(CountryMap.keySet());
distinctZipcodeList.addAll(ZipcodeMap.keySet());
distinctIPList.addAll(IPMap.keySet());
distinctuserNameList.addAll(UserNameMap.keySet());

List fullNameList = new ArrayList();
List firstNameList = new ArrayList();
List secondNameList = new ArrayList();
List emailList = new ArrayList();
List address1List = new ArrayList();
List phoneList = new ArrayList();
List birthdayList = new ArrayList();
List cityList = new ArrayList();
List genderList = new ArrayList();
List countryList = new ArrayList();
List zipcodeList = new ArrayList();
List ipList = new ArrayList();
List createDateList = new ArrayList();
List userNameList = new ArrayList();
List linkList = new ArrayList();

for(Record record:recordList){;
fullNameList.add(record.getFirstName()+record.getSecondName());
firstNameList.add(record.getFirstName());
secondNameList.add(record.getSecondName());
emailList.add(record.getEmail());
address1List.add(record.getAddress1());
phoneList.add(record.getPhone());
birthdayList.add(record.getBirthday());
cityList.add(record.getCity());
genderList.add(record.getGender());
countryList.add(record.getCountry());
zipcodeList.add(record.getZipCode());
ipList.add(record.getIpStr());
createDateList.add(record.getCreateDate());
userNameList.add(record.getUserName());
linkList.add(record.getLink());
}

int[] fullNameScores= calculateAttScore(fullNameList,distinctFullNameList,20,1);
int[] emailScores= calculateAttScore(emailList,distinctEmailList,20,1);
int[] address1Scores= calculateAttScore(address1List,distinctAddress1List,10,1);
int[] phoneScores= calculateAttScore(phoneList,distinctPhoneList,20,1);
int[] birthdayScores = calculateAttScore(birthdayList,distinctBirthdayList, 10,1);
int[] cityScores = calculateAttScore(cityList, distinctCityList, 2,1);
int[] genderScores = calculateAttScore(genderList, distinctGenderList, 1,1);
int[] countryScores = calculateAttScore(countryList, distinctCountryList, 2,1);
int[] zipcodeScores = calculateAttScore(zipcodeList, distinctZipcodeList, 3,1);
int[] ipScores = calculateAttScore(ipList, distinctIPList, 10,1);
int[] userNameScores = calculateAttScore(userNameList, distinctuserNameList, 2,2);

int size = recordList.size();
int[] totalScores = new int[size];

List aList = new ArrayList();
for(int i=0;i totalScores[i]=fullNameScores[i]+
emailScores[i]+
address1Scores[i]+
phoneScores[i]+
birthdayScores[i]+
cityScores[i]+
genderScores[i]+
countryScores[i]+
zipcodeScores[i]+
ipScores[i]+
userNameScores[i];

if(totalScores[i]>=nScore)
{
String fullName = fullNameList.get(i);
String firstName = firstNameList.get(i);
String secondName = secondNameList.get(i);
String email = emailList.get(i);
String address1 = address1List.get(i);
String zipCode = zipcodeList.get(i);
String city = cityList.get(i);
String country = countryList.get(i);
String gender = genderList.get(i);
String phone = phoneList.get(i);
String birthday = birthdayList.get(i);
String ipStr = ipList.get(i);
String Score =Integer.toString(totalScores[i]);
String regDate=createDateList.get(i);
String userName=userNameList.get(i);
String url=linkList.get(i);
Record record = new Record( Score,firstName,secondName, email,
address1, zipCode, city,
country, gender, phone, birthday,ipStr,regDate,userName,url);
aList.add(record);
}
}
aList=Record.sort(aList);
System.out.println("Total execution time:"+(System.currentTimeMillis()-startTime));
return aList;
}

public static List output2(String myemail,String myphone,String myfirstName,String mysecondName,String myaddress,String mybirthday,String myip,String myfieldName, String myfieldValue, int choice)throws Exception{
Connection conn=initConnect();;
Statement statement = conn.createStatement();
Long startTime =System.currentTimeMillis();

String orderSql="";
String judgeSql="";
String sql="";

if(choice==0)
{
judgeSql=transSql("email",myemail,judgeSql);
judgeSql=transSql("phone",myphone,judgeSql);
judgeSql=trans2Sql("familyName",myfirstName,"givenName",mysecondName,judgeSql);
judgeSql=trans2Sql("addressLine1",myaddress,"birthday",mybirthday,judgeSql);
judgeSql=trans2Sql("addressLine1",myaddress,"ip",myip,judgeSql);
judgeSql=trans2Sql("birthday",mybirthday,"ip",myip,judgeSql);

sql = "select userName,familyName,givenName,email,addressLine1,zipCode,city,country,gender,phone,birthday,ip,createdDate from UserEntity where 1=0" +judgeSql;
orderSql=" order by email,phone,familyName,givenName,addressLine1,birthday,ip";
sql=sql+orderSql;
}
else
{
if(myfieldName.equals("createdDate"))
{
myfieldValue=myfieldValue.substring(0,10);
sql = "select userName,familyName,givenName,email,addressLine1,zipCode,city,country,gender,phone,birthday,ip,createdDate from UserEntity where date(createdDate) ='"+myfieldValue+"'";
}
else
sql = "select userName,familyName,givenName,email,addressLine1,zipCode,city,country,gender,phone,birthday,ip,createdDate from UserEntity where " +myfieldName+"='"+myfieldValue+"'";
orderSql=" order by email,phone,familyName,givenName,addressLine1,birthday,ip";
sql=sql+orderSql;
}

ResultSet rs= statement.executeQuery(sql);
System.out.println(sql);

List recordList = new ArrayList();
while(rs.next()){
String fullName = rs.getString("familyName") +rs.getString("givenName");
String UserName = rs.getString("userName");
String firstName = rs.getString("familyName");
String secondName = rs.getString("givenName");
String email = rs.getString("email");
String address1 = rs.getString("addressLine1");
String zipCode = rs.getString("zipCode");
String city = rs.getString("city");
String country = rs.getString("country");
String gender = rs.getString("gender");
String phone = rs.getString("phone");
String birthday = rs.getString("birthday");
String ipStr = rs.getString("ip");
String CreateDate = rs.getString("createdDate");
//String link="duplicatedUser.do?act=1&firstName="+java.net.URLEncoder.encode(firstName)
//+"&secondName="+java.net.URLEncoder.encode(secondName)+"&birthday="+java.net.URLEncoder.encode(birthday)
//+"&ip="+java.net.URLEncoder.encode(ipStr)+"&email="+java.net.URLEncoder.encode(email)+"&phone="+java.net.URLEncoder.encode(phone)+"&address="+java.net.URLEncoder.encode(address1);
String link="dup.do?act=1&firstName="+firstName
+"&secondName="+secondName+"&birthday="+birthday
+"&ip="+ipStr+"&email="+email+"&phone="+phone+"&address="+address1;
//link=java.net.URLEncoder.encode(link, encoding);
link=link.replace(" ", "%20");

Record record = new Record( firstName,secondName, email,
address1, zipCode, city,
country, gender, phone, birthday,ipStr,CreateDate,UserName,link);
recordList.add(record);
}

/* List distinctFullNameList = getAttList(statement, sqlList.get(0), "familyName", "givenName");
List distinctEmailList = getAttList(statement, sqlList.get(1), "email",null);
List distinctAddress1List = getAttList(statement, sqlList.get(2), "addressLine1",null);
List distinctBirthdayList = getAttList(statement, sqlList.get(3), "birthday", null);
List distinctPhoneList = getAttList(statement, sqlList.get(4), "phone", null);
List distinctCityList = getAttList(statement, sqlList.get(5), "city", null);
List distinctGenderList = getAttList(statement, sqlList.get(6), "gender", null);
List distinctCountryList = getAttList(statement, sqlList.get(7), "country", null);
List distinctZipcodeList = getAttList(statement, sqlList.get(8), "zipCode", null);
List distinctIPList = getAttList(statement, sqlList.get(9), "ip", null);
List distinctuserNameList = getAttList(statement, sqlList.get(10), "userName1", null);
*/

String fullsql="select userName,familyName,givenName,email,addressLine1,zipCode,city,country,gender,phone,birthday,ip,createdDate from UserEntity";
ResultSet dtrs= statement.executeQuery(fullsql);

Map FullNameMap = new HashMap();
Map EmailMap = new HashMap();
Map AddressMap = new HashMap();
Map BirthdayMap = new HashMap();
Map PhoneMap = new HashMap();
Map CityMap = new HashMap();
Map GenderMap = new HashMap();
Map CountryMap = new HashMap();
Map ZipcodeMap = new HashMap();
Map IPMap = new HashMap();
Map UserNameMap = new HashMap();

while(dtrs.next()){
String FullName = dtrs.getString("familyName")+dtrs.getString("givenName");
if (!isBlank(FullName))
{
if (FullNameMap.get(FullName)==null) FullNameMap.put(FullName, 1);
else FullNameMap.put(FullName, ((Integer)FullNameMap.get(FullName)).intValue()+1);
}

String strEmail = dtrs.getString("email");
if (!isBlank(strEmail))
{
if (EmailMap.get(strEmail)==null) EmailMap.put(strEmail, 1);
else EmailMap.put(strEmail, ((Integer)EmailMap.get(strEmail)).intValue()+1);
}

String strAddress = dtrs.getString("addressLine1");
if (!isBlank(strAddress))
{
if (AddressMap.get(strAddress)==null) AddressMap.put(strAddress, 1);
else AddressMap.put(strAddress, ((Integer)AddressMap.get(strAddress)).intValue()+1);
}

String strBirthday = dtrs.getString("birthday");
if (!isBlank(strBirthday))
{
if (BirthdayMap.get(strBirthday)==null) BirthdayMap.put(strBirthday, 1);
else BirthdayMap.put(strBirthday, ((Integer)BirthdayMap.get(strBirthday)).intValue()+1);
}

String strPhone = dtrs.getString("phone");
if (!isBlank(strPhone))
{
if (PhoneMap.get(strPhone)==null) PhoneMap.put(strPhone, 1);
else PhoneMap.put(strPhone, ((Integer)PhoneMap.get(strPhone)).intValue()+1);
}

String strCity = dtrs.getString("city");
if (!isBlank(strCity))
{
if (CityMap.get(strCity)==null) CityMap.put(strCity, 1);
else CityMap.put(strCity, ((Integer)CityMap.get(strCity)).intValue()+1);
}

String strGender = dtrs.getString("gender");
if (!isBlank(strGender))
{
if (GenderMap.get(strGender)==null) GenderMap.put(strGender, 1);
else GenderMap.put(strGender, ((Integer)GenderMap.get(strGender)).intValue()+1);
}

String strCountry = dtrs.getString("country");
if (!isBlank(strCountry))
{
if (CountryMap.get(strCountry)==null) CountryMap.put(strCountry, 1);
else CountryMap.put(strCountry, ((Integer)CountryMap.get(strCountry)).intValue()+1);
}

String strZipcode = dtrs.getString("zipCode");
if (!isBlank(strZipcode))
{
if (ZipcodeMap.get(strZipcode)==null) ZipcodeMap.put(strZipcode, 1);
else ZipcodeMap.put(strZipcode, ((Integer)ZipcodeMap.get(strZipcode)).intValue()+1);
}

String strIP = dtrs.getString("ip");
if (!isBlank(strIP))
{
if (IPMap.get(strIP)==null) IPMap.put(strIP, 1);
else IPMap.put(strIP, ((Integer)IPMap.get(strIP)).intValue()+1);
}

String strUserName = dtrs.getString("userName");
if (!isBlank(strUserName))
{
strUserName=strUserName.substring(2);
if (UserNameMap.get(strUserName)==null) UserNameMap.put(strUserName, 1);
else UserNameMap.put(strUserName, ((Integer)UserNameMap.get(strUserName)).intValue()+1);
}
}

for (Iterator> it = FullNameMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = EmailMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = AddressMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = BirthdayMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = PhoneMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = CityMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = GenderMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = CountryMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = ZipcodeMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = IPMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}
for (Iterator> it = UserNameMap.entrySet().iterator(); it.hasNext();) {
Entry entry = it.next();
if (entry.getValue().intValue()<2) {
it.remove();
continue;
}
if (entry.getKey()==null || entry.getKey().trim().isEmpty()) it.remove();
}

List distinctFullNameList =new ArrayList();
List distinctEmailList = new ArrayList();
List distinctAddress1List = new ArrayList();
List distinctBirthdayList = new ArrayList();
List distinctPhoneList = new ArrayList();
List distinctCityList = new ArrayList();
List distinctGenderList = new ArrayList();
List distinctCountryList = new ArrayList();
List distinctZipcodeList = new ArrayList();
List distinctIPList = new ArrayList();
List distinctuserNameList = new ArrayList();

distinctFullNameList.addAll(FullNameMap.keySet());
distinctEmailList.addAll(EmailMap.keySet());
distinctAddress1List.addAll(AddressMap.keySet());
distinctBirthdayList.addAll(BirthdayMap.keySet());
distinctPhoneList.addAll(PhoneMap.keySet());
distinctCityList.addAll(CityMap.keySet());
distinctGenderList.addAll(GenderMap.keySet());
distinctCountryList.addAll(CountryMap.keySet());
distinctZipcodeList.addAll(ZipcodeMap.keySet());
distinctIPList.addAll(IPMap.keySet());
distinctuserNameList.addAll(UserNameMap.keySet());

List fullNameList = new ArrayList();
List firstNameList = new ArrayList();
List secondNameList = new ArrayList();
List emailList = new ArrayList();
List address1List = new ArrayList();
List phoneList = new ArrayList();
List birthdayList = new ArrayList();
List cityList = new ArrayList();
List genderList = new ArrayList();
List countryList = new ArrayList();
List zipcodeList = new ArrayList();
List ipList = new ArrayList();
List createDateList = new ArrayList();
List userNameList = new ArrayList();
List linkList = new ArrayList();

for(Record record:recordList){
fullNameList.add(record.getFirstName()+record.getSecondName());
firstNameList.add(record.getFirstName());
secondNameList.add(record.getSecondName());
emailList.add(record.getEmail());
address1List.add(record.getAddress1());
phoneList.add(record.getPhone());
birthdayList.add(record.getBirthday());
cityList.add(record.getCity());
genderList.add(record.getGender());
countryList.add(record.getCountry());
zipcodeList.add(record.getZipCode());
ipList.add(record.getIpStr());
createDateList.add(record.getCreateDate());
userNameList.add(record.getUserName());
linkList.add(record.getLink());
}

int[] fullNameScores= calculateAttScore(fullNameList,distinctFullNameList,20,1);
int[] emailScores= calculateAttScore(emailList,distinctEmailList,20,1);
int[] address1Scores= calculateAttScore(address1List,distinctAddress1List,10,1);
int[] phoneScores= calculateAttScore(phoneList,distinctPhoneList,20,1);
int[] birthdayScores = calculateAttScore(birthdayList,distinctBirthdayList, 10,1);
int[] cityScores = calculateAttScore(cityList, distinctCityList, 2,1);
int[] genderScores = calculateAttScore(genderList, distinctGenderList, 1,1);
int[] countryScores = calculateAttScore(countryList, distinctCountryList, 2,1);
int[] zipcodeScores = calculateAttScore(zipcodeList, distinctZipcodeList, 3,1);
int[] ipScores = calculateAttScore(ipList, distinctIPList, 10,1);
int[] userNameScores = calculateAttScore(userNameList, distinctuserNameList, 2,2);

int size = recordList.size();
int[] totalScores = new int[size];

List aList = new ArrayList();
for(int i=0;i totalScores[i]=fullNameScores[i]+
emailScores[i]+
address1Scores[i]+
phoneScores[i]+
birthdayScores[i]+
cityScores[i]+
genderScores[i]+
countryScores[i]+
zipcodeScores[i]+
ipScores[i]+
userNameScores[i];

if(totalScores[i]>=20)
{
String fullName = fullNameList.get(i);
String firstName = firstNameList.get(i);
String secondName = secondNameList.get(i);
String email = emailList.get(i);
String address1 = address1List.get(i);
String zipCode = zipcodeList.get(i);
String city = cityList.get(i);
String country = countryList.get(i);
String gender = genderList.get(i);
String phone = phoneList.get(i);
String birthday = birthdayList.get(i);
String ipStr = ipList.get(i);
String Score =Integer.toString(totalScores[i]);
String regDate=createDateList.get(i);
String userName=userNameList.get(i);
String url=linkList.get(i);
Record record = new Record( Score,firstName,secondName, email,
address1, zipCode, city,
country, gender, phone, birthday,ipStr,regDate,userName,url);
aList.add(record);

}
}
aList=Record.sort(aList);
System.out.println("Total execution time:"+(System.currentTimeMillis()-startTime));
return aList;
}



private static void optimizeDB(Statement statement, List optimizeSqlList) throws SQLException{
for(String sql:optimizeSqlList){
statement.execute(sql);
}

}
static int[] calculateAttScore(List attList,List distinctList,int hash,int choice){
int [] scores = new int[attList.size()];
for(int i=0;i if(scores[i]!=0 || attList.get(i)==null)
continue;
for(int j=0;j if(choice==1)
{if(attList.get(i).equals(distinctList.get(j)))
scores[i]=hash;
}
else
{
if(attList.get(i).substring(2).equals(distinctList.get(j)))
scores[i]=hash;
}
}
}
return scores;
}

static String transSql(String field,String fieldValue,String judgeSql)
{//if ((fieldValue==null) || (fieldValue.equals("")))
if(isBlank(fieldValue))
{
//stem.out.println("field is null");
//if ((judgeSql==null) || (judgeSql.equals("")))
if(isBlank(judgeSql))
return "";
else
return judgeSql;
}
else
{
judgeSql=judgeSql+" or "+field+"='"+fieldValue+"'";
return judgeSql;
}}

static String trans2Sql(String field1,String fieldValue1,String field2,String fieldValue2,String judgeSql)
{if (!isBlank(fieldValue1) && !isBlank(fieldValue2) )
{
judgeSql=judgeSql+" or ("+field1+"='"+fieldValue1+"' and "+field2+"='"+fieldValue2+"')";
return judgeSql;
}
else
{
System.out.println("field is null");
//if ((judgeSql==null) || (judgeSql.equals("")))
if(isBlank(judgeSql))
return "";
else
return judgeSql;
}
}

static String TransDate(String dateStr) {
//if ((dateStr==null) || (dateStr.equals("")))
if(isBlank(dateStr))
return "";
else
{
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date=null;
String transDate=null;

try{
date = simpleDateFormat.parse(dateStr);
}catch (Exception e) {
}
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
transDate=simpleDateFormat2.format(date);
return transDate;
}
}

public static boolean isBlank(String str) {
if(null == str || 0 == str.trim().length()) {
return true;
}
return false;
}

static Connection initConnect(){
String driver = "com.mysql.jdbc.Driver";//


String url = "jdbc:mysql://10.0.4.149/oddsmatrixdb";

String user = "a";

String password = "a";
Connection conn =null;
try {

Class.forName(driver); //

conn = DriverManager.getConnection(url, user, password);

}catch (Exception e) {
e.printStackTrace();
System.out.println("Connecting database error!");
}
return conn;
}
static List getAttList(Statement statement,String sql,String attName1,String attName2) throws Exception{

ResultSet rs= statement.executeQuery(sql);
List attValueList = new ArrayList();
String attValue = null;
while(rs.next()){
if(attName2!=null && attName1!=null){
attValue = rs.getString(attName1) +rs.getString(attName2);

attValueList.add(attValue);
}
else if(attName1!=null){
attValue = rs.getString(attName1);
attValueList.add(attValue);
}
}
return attValueList;
}
}

package addressbook.model;

import java.util.Comparator;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Record {
private String fullName;
private String UserName;
private String firstName;
private String secondName;
private String email;
private String address1;
private String zipCode;
private String city;
private String country;
private String gender;
private String phone;
private String birthday;
private String ipStr;
private String Score;
private String CreateDate;
private String link;

public String getFullName() {
return fullName;
}
public String getUserName() {
return UserName;
}

public String getFirstName() {
return firstName;
}

public String getSecondName() {
return secondName;
}

public String getEmail() {
return email;
}

public String getAddress1() {
return address1;
}

public String getCity() {
return city;
}

public String getCountry() {
return country;
}

public String getGender() {
return gender;
}

public String getPhone() {
return phone;
}

public String getBirthday() {
return birthday;
}

public String getZipCode() {
return zipCode;
}
public String getIpStr() {
return ipStr;
}


public String getScore() {
return Score;
}

public String getCreateDate() {
return CreateDate;
}

public String getLink() {
return link;
}

public Record(String firstName,String secondName,String email, String address1,
String zipCode, String city, String country, String gender,
String phone, String birthday,String ipStr,String CreateDate,String UserName,String link) {
super();
//this.fullName = fullName;
this.firstName = firstName;
this.secondName = secondName;
this.email = email;
this.address1 = address1;
this.zipCode = zipCode;
this.city = city;
this.country = country;
this.gender = gender;
this.phone = phone;
this.birthday = birthday;
this.ipStr = ipStr;
this.CreateDate=CreateDate;
this.UserName=UserName;
this.link = link;
}

public Record(String Score,String firstName,String secondName, String email, String address1,
String zipCode, String city, String country, String gender,
String phone, String birthday,String ipStr,String CreateDate,String UserName,String link) {
super();
//this.fullName = fullName;
this.firstName = firstName;
this.secondName = secondName;
this.email = email;
this.address1 = address1;
this.zipCode = zipCode;
this.city = city;
this.country = country;
this.gender = gender;
this.phone = phone;
this.birthday = birthday;
this.ipStr = ipStr;
this.Score = Score;
this.CreateDate=CreateDate;
this.UserName=UserName;
this.link = link;
}

private boolean compare(Record record){
if(Integer.parseInt(this.Score) > Integer.parseInt(record.Score))
return true;
else
return false;
}


public static List sort(List recordList){

for(int i = 0;i for(int j=i+1;j if(!recordList.get(i).compare(recordList.get(j))){
Record record = recordList.get(i);
recordList.set(i, recordList.get(j));
recordList.set(j, record);
}
}
}
//for(Record record1:recordList){
// System.out.println(record1.getFullName());
//}
return recordList;
}

public static List sort2(List recordList,int nScore ){

for(int i = 0;i if(Integer.parseInt(recordList.get(i).getScore()) {
recordList.remove(i);
i--;
}
}
//for(Record record1:recordList){
// System.out.println(record1.getFullName());
//}
return recordList;
}

public static List sortFirstName(List recordList){
compareFirstName comparator=new compareFirstName();
Collections.sort(recordList, comparator);
return recordList;
}

public static List sortSecondName(List recordList){
compareSecondName comparator=new compareSecondName();
Collections.sort(recordList, comparator);
return recordList;
}
public static List sortEmail(List recordList){
compareEmail comparator=new compareEmail();
Collections.sort(recordList, comparator);
return recordList;
}

public static List sortAddress(List recordList){
compareAddress comparator=new compareAddress();
Collections.sort(recordList, comparator);
return recordList;
}
public static List sortCity(List recordList){
compareCity comparator=new compareCity();
Collections.sort(recordList, comparator);
return recordList;
}

public static List sortCountry(List recordList){
compareCountry comparator=new compareCountry();
Collections.sort(recordList, comparator);
return recordList;
}
public static List sortGender(List recordList){
compareGender comparator=new compareGender();
Collections.sort(recordList, comparator);
return recordList;
}

public static List sortPhone(List recordList){
comparePhone comparator=new comparePhone();
Collections.sort(recordList, comparator);
return recordList;
}
public static List sortBirthday(List recordList){
compareBirthday comparator=new compareBirthday();
Collections.sort(recordList, comparator);
return recordList;
}

public static List sortZipCode(List recordList){
compareZipCode comparator=new compareZipCode();
Collections.sort(recordList, comparator);
return recordList;
}
public static List sortIp(List recordList){
compareIp comparator=new compareIp();
Collections.sort(recordList, comparator);
return recordList;
}

public static List sortCreateDate(List recordList){
compareCreateDate comparator=new compareCreateDate();
Collections.sort(recordList, comparator);
return recordList;
}
public static List sortUserName(List recordList){
compareUserName comparator=new compareUserName();
Collections.sort(recordList, comparator);
return recordList;
}

}

class compareFirstName implements Comparator{
public int compare(Object arg0, Object arg1) {
Record user0=(Record)arg0;
Record user1=(Record)arg1;
/*if((user0.getFirstName()==null) || (user0.getFirstName().equals("")) || (user1.getFirstName()==null) || (user1.getFirstName().equals("")) )
return -1;
else if(user0.getFirstName().compareTo(user1.getFirstName())>0)
return 1;
else
return -1;
}*/
if((user0.getFirstName()==null) || (user0.getFirstName().equals("")) ){
if((user1.getFirstName()==null) || (user1.getFirstName().equals("")))
return 0;
return -1;
}
else {
if((user1.getFirstName()==null) || (user1.getFirstName().equals("")))
return 1;
else return user0.getFirstName().toLowerCase().compareTo(user1.getFirstName().toLowerCase()) ;
}
}}

class compareSecondName implements Comparator{
public int compare(Object arg0, Object arg1) {
Record user0=(Record)arg0;
Record user1=(Record)arg1;
/*if((user0.getSecondName()==null) || (user0.getSecondName().equals("")) || (user1.getSecondName()==null) || (user1.getSecondName().equals("")) )
return -1;
else if(user0.getSecondName().compareTo(user1.getSecondName())>0)
return 1;
else
return -1;
}*/
if((user0.getSecondName()==null) || (user0.getSecondName().equals("")) ){
if((user1.getSecondName()==null) || (user1.getSecondName().equals("")))
return 0;
return -1;
}
else {
if((user1.getSecondName()==null) || (user1.getSecondName().equals("")))
return 1;
else return user0.getSecondName().toLowerCase().compareTo(user1.getSecondName().toLowerCase()) ;
}
}}

class compareEmail implements Comparator{
public int compare(Object arg0, Object arg1) {
Record user0=(Record)arg0;
Record user1=(Record)arg1;
if((user0.getEmail()==null) || (user0.getEmail().equals("")) ){
if((user1.getEmail()==null) || (user1.getEmail().equals("")))
return 0;
return -1;
}
else {
if((user1.getEmail()==null) || (user1.getEmail().equals("")))
return 1;
else return user0.getEmail().toLowerCase().compareTo(user1.getEmail().toLowerCase()) ;
}
}
}

class compareAddress implements Comparator{
public int compare(Object arg0, Object arg1) {
Record user0=(Record)arg0;
Record user1=(Record)arg1;
/*if((user0.getAddress1()==null) || (user0.getAddress1().equals("")) || (user1.getAddress1()==null) || (user1.getAddress1().equals("")) )
return -1;
else if(user0.getAddress1().compareTo(user1.getAddress1())>0)
return 1;
else
return -1;*/
if((user0.getAddress1()==null) || (user0.getAddress1().equals("")) ){
if((user1.getAddress1()==null) || (user1.getAddress1().equals("")))
return 0;
return -1;
}
else {
if((user1.getAddress1()==null) || (user1.getAddress1().equals("")))
return 1;
else return user0.getAddress1().toLowerCase().compareTo(user1.getAddress1().toLowerCase()) ;
}
}}

class compareCity implements Comparator{
public int compare(Object arg0, Object arg1) {
Record user0=(Record)arg0;
Record user1=(Record)arg1;
/*if((user0.getCity()==null) || (user0.getCity().equals("")) || (user1.getCity()==null) || (user1.getCity().equals("")) )
return -1;
else if(user0.getCity().compareTo(user1.getCity())>0)
return 1;
else
return -1;
}*/
if((user0.getCity()==null) || (user0.getCity().equals("")) ){
if((user1.getCity()==null)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/91551/viewspace-1029895/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/91551/viewspace-1029895/

你可能感兴趣的:(数据库,java)