001// ______________________________________________________ 002// Generated by sql2java - https://github.com/10km/sql2java-2-6-7 (custom branch) 003// modified by guyadong from 004// sql2java original version https://sourceforge.net/projects/sql2java/ 005// JDBC driver used at code generation time: com.mysql.jdbc.Driver 006// template: comparator.java.vm 007// ______________________________________________________ 008package net.gdface.facelog.db; 009 010import java.util.Comparator; 011 012 013/** 014 * Comparator class is used to sort the PersonBean objects. 015 * @author sql2java 016 */ 017public class PersonComparator implements Comparator<PersonBean>,Constant 018{ 019 /** 020 * Holds the field on which the comparison is performed. 021 */ 022 private int iType; 023 /** 024 * Value that will contain the information about the order of the sort: normal or reversal. 025 */ 026 private boolean bReverse; 027 028 /** 029 * Constructor class for PersonComparator. 030 * <br> 031 * Example: 032 * <br> 033 * <code>Arrays.sort(pArray, new PersonComparator(Constant.FL_PERSON_ID_ID, bReverse));</code> 034 * 035 * @param iType the field from which you want to sort 036 * <br> 037 * Possible values are: 038 * <ul> 039 * <li>{@link Constant#FL_PERSON_ID_ID} 040 * <li>{@link Constant#FL_PERSON_ID_GROUP_ID} 041 * <li>{@link Constant#FL_PERSON_ID_NAME} 042 * <li>{@link Constant#FL_PERSON_ID_SEX} 043 * <li>{@link Constant#FL_PERSON_ID_RANK} 044 * <li>{@link Constant#FL_PERSON_ID_PASSWORD} 045 * <li>{@link Constant#FL_PERSON_ID_BIRTHDATE} 046 * <li>{@link Constant#FL_PERSON_ID_MOBILE_PHONE} 047 * <li>{@link Constant#FL_PERSON_ID_PAPERS_TYPE} 048 * <li>{@link Constant#FL_PERSON_ID_PAPERS_NUM} 049 * <li>{@link Constant#FL_PERSON_ID_IMAGE_MD5} 050 * <li>{@link Constant#FL_PERSON_ID_EXPIRY_DATE} 051 * <li>{@link Constant#FL_PERSON_ID_ACTIVATED_DATE} 052 * <li>{@link Constant#FL_PERSON_ID_REMARK} 053 * <li>{@link Constant#FL_PERSON_ID_EXT_BIN} 054 * <li>{@link Constant#FL_PERSON_ID_EXT_TXT} 055 * <li>{@link Constant#FL_PERSON_ID_CREATE_TIME} 056 * <li>{@link Constant#FL_PERSON_ID_UPDATE_TIME} 057 * </ul> 058 */ 059 public PersonComparator(int iType) 060 { 061 this(iType, false); 062 } 063 064 /** 065 * Constructor class for PersonComparator. 066 * <br> 067 * Example: 068 * <br> 069 * <code>Arrays.sort(pArray, new PersonComparator(Constant.FL_PERSON_ID_ID, bReverse));</code> 070 * 071 * @param iType the field from which you want to sort. 072 * <br> 073 * Possible values are: 074 * <ul> 075 * <li>{@link Constant#FL_PERSON_ID_ID}) 076 * <li>{@link Constant#FL_PERSON_ID_GROUP_ID}) 077 * <li>{@link Constant#FL_PERSON_ID_NAME}) 078 * <li>{@link Constant#FL_PERSON_ID_SEX}) 079 * <li>{@link Constant#FL_PERSON_ID_RANK}) 080 * <li>{@link Constant#FL_PERSON_ID_PASSWORD}) 081 * <li>{@link Constant#FL_PERSON_ID_BIRTHDATE}) 082 * <li>{@link Constant#FL_PERSON_ID_MOBILE_PHONE}) 083 * <li>{@link Constant#FL_PERSON_ID_PAPERS_TYPE}) 084 * <li>{@link Constant#FL_PERSON_ID_PAPERS_NUM}) 085 * <li>{@link Constant#FL_PERSON_ID_IMAGE_MD5}) 086 * <li>{@link Constant#FL_PERSON_ID_EXPIRY_DATE}) 087 * <li>{@link Constant#FL_PERSON_ID_ACTIVATED_DATE}) 088 * <li>{@link Constant#FL_PERSON_ID_REMARK}) 089 * <li>{@link Constant#FL_PERSON_ID_EXT_BIN}) 090 * <li>{@link Constant#FL_PERSON_ID_EXT_TXT}) 091 * <li>{@link Constant#FL_PERSON_ID_CREATE_TIME}) 092 * <li>{@link Constant#FL_PERSON_ID_UPDATE_TIME}) 093 * </ul> 094 * 095 * @param bReverse set this value to true, if you want to reverse the sorting results 096 */ 097 public PersonComparator(int iType, boolean bReverse) 098 { 099 this.iType = iType; 100 this.bReverse = bReverse; 101 } 102 103 @Override 104 public int compare(PersonBean b1, PersonBean b2) 105 { 106 int iReturn = 0; 107 switch(iType) 108 { 109 case FL_PERSON_ID_ID: 110 if (b1.getId() == null && b2.getId() != null) { 111 iReturn = -1; 112 } else if (b1.getId() == null && b2.getId() == null) { 113 iReturn = 0; 114 } else if (b1.getId() != null && b2.getId() == null) { 115 iReturn = 1; 116 } else { 117 iReturn = b1.getId().compareTo(b2.getId()); 118 } 119 break; 120 case FL_PERSON_ID_GROUP_ID: 121 if (b1.getGroupId() == null && b2.getGroupId() != null) { 122 iReturn = -1; 123 } else if (b1.getGroupId() == null && b2.getGroupId() == null) { 124 iReturn = 0; 125 } else if (b1.getGroupId() != null && b2.getGroupId() == null) { 126 iReturn = 1; 127 } else { 128 iReturn = b1.getGroupId().compareTo(b2.getGroupId()); 129 } 130 break; 131 case FL_PERSON_ID_NAME: 132 if (b1.getName() == null && b2.getName() != null) { 133 iReturn = -1; 134 } else if (b1.getName() == null && b2.getName() == null) { 135 iReturn = 0; 136 } else if (b1.getName() != null && b2.getName() == null) { 137 iReturn = 1; 138 } else { 139 iReturn = b1.getName().compareTo(b2.getName()); 140 } 141 break; 142 case FL_PERSON_ID_SEX: 143 if (b1.getSex() == null && b2.getSex() != null) { 144 iReturn = -1; 145 } else if (b1.getSex() == null && b2.getSex() == null) { 146 iReturn = 0; 147 } else if (b1.getSex() != null && b2.getSex() == null) { 148 iReturn = 1; 149 } else { 150 iReturn = b1.getSex().compareTo(b2.getSex()); 151 } 152 break; 153 case FL_PERSON_ID_RANK: 154 if (b1.getRank() == null && b2.getRank() != null) { 155 iReturn = -1; 156 } else if (b1.getRank() == null && b2.getRank() == null) { 157 iReturn = 0; 158 } else if (b1.getRank() != null && b2.getRank() == null) { 159 iReturn = 1; 160 } else { 161 iReturn = b1.getRank().compareTo(b2.getRank()); 162 } 163 break; 164 case FL_PERSON_ID_PASSWORD: 165 if (b1.getPassword() == null && b2.getPassword() != null) { 166 iReturn = -1; 167 } else if (b1.getPassword() == null && b2.getPassword() == null) { 168 iReturn = 0; 169 } else if (b1.getPassword() != null && b2.getPassword() == null) { 170 iReturn = 1; 171 } else { 172 iReturn = b1.getPassword().compareTo(b2.getPassword()); 173 } 174 break; 175 case FL_PERSON_ID_BIRTHDATE: 176 if (b1.getBirthdate() == null && b2.getBirthdate() != null) { 177 iReturn = -1; 178 } else if (b1.getBirthdate() == null && b2.getBirthdate() == null) { 179 iReturn = 0; 180 } else if (b1.getBirthdate() != null && b2.getBirthdate() == null) { 181 iReturn = 1; 182 } else { 183 iReturn = b1.getBirthdate().compareTo(b2.getBirthdate()); 184 } 185 break; 186 case FL_PERSON_ID_MOBILE_PHONE: 187 if (b1.getMobilePhone() == null && b2.getMobilePhone() != null) { 188 iReturn = -1; 189 } else if (b1.getMobilePhone() == null && b2.getMobilePhone() == null) { 190 iReturn = 0; 191 } else if (b1.getMobilePhone() != null && b2.getMobilePhone() == null) { 192 iReturn = 1; 193 } else { 194 iReturn = b1.getMobilePhone().compareTo(b2.getMobilePhone()); 195 } 196 break; 197 case FL_PERSON_ID_PAPERS_TYPE: 198 if (b1.getPapersType() == null && b2.getPapersType() != null) { 199 iReturn = -1; 200 } else if (b1.getPapersType() == null && b2.getPapersType() == null) { 201 iReturn = 0; 202 } else if (b1.getPapersType() != null && b2.getPapersType() == null) { 203 iReturn = 1; 204 } else { 205 iReturn = b1.getPapersType().compareTo(b2.getPapersType()); 206 } 207 break; 208 case FL_PERSON_ID_PAPERS_NUM: 209 if (b1.getPapersNum() == null && b2.getPapersNum() != null) { 210 iReturn = -1; 211 } else if (b1.getPapersNum() == null && b2.getPapersNum() == null) { 212 iReturn = 0; 213 } else if (b1.getPapersNum() != null && b2.getPapersNum() == null) { 214 iReturn = 1; 215 } else { 216 iReturn = b1.getPapersNum().compareTo(b2.getPapersNum()); 217 } 218 break; 219 case FL_PERSON_ID_IMAGE_MD5: 220 if (b1.getImageMd5() == null && b2.getImageMd5() != null) { 221 iReturn = -1; 222 } else if (b1.getImageMd5() == null && b2.getImageMd5() == null) { 223 iReturn = 0; 224 } else if (b1.getImageMd5() != null && b2.getImageMd5() == null) { 225 iReturn = 1; 226 } else { 227 iReturn = b1.getImageMd5().compareTo(b2.getImageMd5()); 228 } 229 break; 230 case FL_PERSON_ID_EXPIRY_DATE: 231 if (b1.getExpiryDate() == null && b2.getExpiryDate() != null) { 232 iReturn = -1; 233 } else if (b1.getExpiryDate() == null && b2.getExpiryDate() == null) { 234 iReturn = 0; 235 } else if (b1.getExpiryDate() != null && b2.getExpiryDate() == null) { 236 iReturn = 1; 237 } else { 238 iReturn = b1.getExpiryDate().compareTo(b2.getExpiryDate()); 239 } 240 break; 241 case FL_PERSON_ID_ACTIVATED_DATE: 242 if (b1.getActivatedDate() == null && b2.getActivatedDate() != null) { 243 iReturn = -1; 244 } else if (b1.getActivatedDate() == null && b2.getActivatedDate() == null) { 245 iReturn = 0; 246 } else if (b1.getActivatedDate() != null && b2.getActivatedDate() == null) { 247 iReturn = 1; 248 } else { 249 iReturn = b1.getActivatedDate().compareTo(b2.getActivatedDate()); 250 } 251 break; 252 case FL_PERSON_ID_REMARK: 253 if (b1.getRemark() == null && b2.getRemark() != null) { 254 iReturn = -1; 255 } else if (b1.getRemark() == null && b2.getRemark() == null) { 256 iReturn = 0; 257 } else if (b1.getRemark() != null && b2.getRemark() == null) { 258 iReturn = 1; 259 } else { 260 iReturn = b1.getRemark().compareTo(b2.getRemark()); 261 } 262 break; 263 case FL_PERSON_ID_EXT_BIN: 264 if (b1.getExtBin() == null && b2.getExtBin() != null) { 265 iReturn = -1; 266 } else if (b1.getExtBin() == null && b2.getExtBin() == null) { 267 iReturn = 0; 268 } else if (b1.getExtBin() != null && b2.getExtBin() == null) { 269 iReturn = 1; 270 } else { 271 iReturn = b1.getExtBin().compareTo(b2.getExtBin()); 272 } 273 break; 274 case FL_PERSON_ID_EXT_TXT: 275 if (b1.getExtTxt() == null && b2.getExtTxt() != null) { 276 iReturn = -1; 277 } else if (b1.getExtTxt() == null && b2.getExtTxt() == null) { 278 iReturn = 0; 279 } else if (b1.getExtTxt() != null && b2.getExtTxt() == null) { 280 iReturn = 1; 281 } else { 282 iReturn = b1.getExtTxt().compareTo(b2.getExtTxt()); 283 } 284 break; 285 case FL_PERSON_ID_CREATE_TIME: 286 if (b1.getCreateTime() == null && b2.getCreateTime() != null) { 287 iReturn = -1; 288 } else if (b1.getCreateTime() == null && b2.getCreateTime() == null) { 289 iReturn = 0; 290 } else if (b1.getCreateTime() != null && b2.getCreateTime() == null) { 291 iReturn = 1; 292 } else { 293 iReturn = b1.getCreateTime().compareTo(b2.getCreateTime()); 294 } 295 break; 296 case FL_PERSON_ID_UPDATE_TIME: 297 if (b1.getUpdateTime() == null && b2.getUpdateTime() != null) { 298 iReturn = -1; 299 } else if (b1.getUpdateTime() == null && b2.getUpdateTime() == null) { 300 iReturn = 0; 301 } else if (b1.getUpdateTime() != null && b2.getUpdateTime() == null) { 302 iReturn = 1; 303 } else { 304 iReturn = b1.getUpdateTime().compareTo(b2.getUpdateTime()); 305 } 306 break; 307 default: 308 throw new IllegalArgumentException("Type passed for the field is not supported"); 309 } 310 311 return bReverse ? (-1 * iReturn) : iReturn; 312 }}