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 FaceBean objects. 015 * @author sql2java 016 */ 017public class FaceComparator implements Comparator<FaceBean>,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 FaceComparator. 030 * <br> 031 * Example: 032 * <br> 033 * <code>Arrays.sort(pArray, new FaceComparator(Constant.FL_FACE_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_FACE_ID_ID} 040 * <li>{@link Constant#FL_FACE_ID_IMAGE_MD5} 041 * <li>{@link Constant#FL_FACE_ID_FACE_LEFT} 042 * <li>{@link Constant#FL_FACE_ID_FACE_TOP} 043 * <li>{@link Constant#FL_FACE_ID_FACE_WIDTH} 044 * <li>{@link Constant#FL_FACE_ID_FACE_HEIGHT} 045 * <li>{@link Constant#FL_FACE_ID_EYE_LEFTX} 046 * <li>{@link Constant#FL_FACE_ID_EYE_LEFTY} 047 * <li>{@link Constant#FL_FACE_ID_EYE_RIGHTX} 048 * <li>{@link Constant#FL_FACE_ID_EYE_RIGHTY} 049 * <li>{@link Constant#FL_FACE_ID_MOUTH_X} 050 * <li>{@link Constant#FL_FACE_ID_MOUTH_Y} 051 * <li>{@link Constant#FL_FACE_ID_NOSE_X} 052 * <li>{@link Constant#FL_FACE_ID_NOSE_Y} 053 * <li>{@link Constant#FL_FACE_ID_ANGLE_YAW} 054 * <li>{@link Constant#FL_FACE_ID_ANGLE_PITCH} 055 * <li>{@link Constant#FL_FACE_ID_ANGLE_ROLL} 056 * <li>{@link Constant#FL_FACE_ID_EXT_INFO} 057 * <li>{@link Constant#FL_FACE_ID_FEATURE_MD5} 058 * </ul> 059 */ 060 public FaceComparator(int iType) 061 { 062 this(iType, false); 063 } 064 065 /** 066 * Constructor class for FaceComparator. 067 * <br> 068 * Example: 069 * <br> 070 * <code>Arrays.sort(pArray, new FaceComparator(Constant.FL_FACE_ID_ID, bReverse));</code> 071 * 072 * @param iType the field from which you want to sort. 073 * <br> 074 * Possible values are: 075 * <ul> 076 * <li>{@link Constant#FL_FACE_ID_ID}) 077 * <li>{@link Constant#FL_FACE_ID_IMAGE_MD5}) 078 * <li>{@link Constant#FL_FACE_ID_FACE_LEFT}) 079 * <li>{@link Constant#FL_FACE_ID_FACE_TOP}) 080 * <li>{@link Constant#FL_FACE_ID_FACE_WIDTH}) 081 * <li>{@link Constant#FL_FACE_ID_FACE_HEIGHT}) 082 * <li>{@link Constant#FL_FACE_ID_EYE_LEFTX}) 083 * <li>{@link Constant#FL_FACE_ID_EYE_LEFTY}) 084 * <li>{@link Constant#FL_FACE_ID_EYE_RIGHTX}) 085 * <li>{@link Constant#FL_FACE_ID_EYE_RIGHTY}) 086 * <li>{@link Constant#FL_FACE_ID_MOUTH_X}) 087 * <li>{@link Constant#FL_FACE_ID_MOUTH_Y}) 088 * <li>{@link Constant#FL_FACE_ID_NOSE_X}) 089 * <li>{@link Constant#FL_FACE_ID_NOSE_Y}) 090 * <li>{@link Constant#FL_FACE_ID_ANGLE_YAW}) 091 * <li>{@link Constant#FL_FACE_ID_ANGLE_PITCH}) 092 * <li>{@link Constant#FL_FACE_ID_ANGLE_ROLL}) 093 * <li>{@link Constant#FL_FACE_ID_EXT_INFO}) 094 * <li>{@link Constant#FL_FACE_ID_FEATURE_MD5}) 095 * </ul> 096 * 097 * @param bReverse set this value to true, if you want to reverse the sorting results 098 */ 099 public FaceComparator(int iType, boolean bReverse) 100 { 101 this.iType = iType; 102 this.bReverse = bReverse; 103 } 104 105 @Override 106 public int compare(FaceBean b1, FaceBean b2) 107 { 108 int iReturn = 0; 109 switch(iType) 110 { 111 case FL_FACE_ID_ID: 112 if (b1.getId() == null && b2.getId() != null) { 113 iReturn = -1; 114 } else if (b1.getId() == null && b2.getId() == null) { 115 iReturn = 0; 116 } else if (b1.getId() != null && b2.getId() == null) { 117 iReturn = 1; 118 } else { 119 iReturn = b1.getId().compareTo(b2.getId()); 120 } 121 break; 122 case FL_FACE_ID_IMAGE_MD5: 123 if (b1.getImageMd5() == null && b2.getImageMd5() != null) { 124 iReturn = -1; 125 } else if (b1.getImageMd5() == null && b2.getImageMd5() == null) { 126 iReturn = 0; 127 } else if (b1.getImageMd5() != null && b2.getImageMd5() == null) { 128 iReturn = 1; 129 } else { 130 iReturn = b1.getImageMd5().compareTo(b2.getImageMd5()); 131 } 132 break; 133 case FL_FACE_ID_FACE_LEFT: 134 if (b1.getFaceLeft() == null && b2.getFaceLeft() != null) { 135 iReturn = -1; 136 } else if (b1.getFaceLeft() == null && b2.getFaceLeft() == null) { 137 iReturn = 0; 138 } else if (b1.getFaceLeft() != null && b2.getFaceLeft() == null) { 139 iReturn = 1; 140 } else { 141 iReturn = b1.getFaceLeft().compareTo(b2.getFaceLeft()); 142 } 143 break; 144 case FL_FACE_ID_FACE_TOP: 145 if (b1.getFaceTop() == null && b2.getFaceTop() != null) { 146 iReturn = -1; 147 } else if (b1.getFaceTop() == null && b2.getFaceTop() == null) { 148 iReturn = 0; 149 } else if (b1.getFaceTop() != null && b2.getFaceTop() == null) { 150 iReturn = 1; 151 } else { 152 iReturn = b1.getFaceTop().compareTo(b2.getFaceTop()); 153 } 154 break; 155 case FL_FACE_ID_FACE_WIDTH: 156 if (b1.getFaceWidth() == null && b2.getFaceWidth() != null) { 157 iReturn = -1; 158 } else if (b1.getFaceWidth() == null && b2.getFaceWidth() == null) { 159 iReturn = 0; 160 } else if (b1.getFaceWidth() != null && b2.getFaceWidth() == null) { 161 iReturn = 1; 162 } else { 163 iReturn = b1.getFaceWidth().compareTo(b2.getFaceWidth()); 164 } 165 break; 166 case FL_FACE_ID_FACE_HEIGHT: 167 if (b1.getFaceHeight() == null && b2.getFaceHeight() != null) { 168 iReturn = -1; 169 } else if (b1.getFaceHeight() == null && b2.getFaceHeight() == null) { 170 iReturn = 0; 171 } else if (b1.getFaceHeight() != null && b2.getFaceHeight() == null) { 172 iReturn = 1; 173 } else { 174 iReturn = b1.getFaceHeight().compareTo(b2.getFaceHeight()); 175 } 176 break; 177 case FL_FACE_ID_EYE_LEFTX: 178 if (b1.getEyeLeftx() == null && b2.getEyeLeftx() != null) { 179 iReturn = -1; 180 } else if (b1.getEyeLeftx() == null && b2.getEyeLeftx() == null) { 181 iReturn = 0; 182 } else if (b1.getEyeLeftx() != null && b2.getEyeLeftx() == null) { 183 iReturn = 1; 184 } else { 185 iReturn = b1.getEyeLeftx().compareTo(b2.getEyeLeftx()); 186 } 187 break; 188 case FL_FACE_ID_EYE_LEFTY: 189 if (b1.getEyeLefty() == null && b2.getEyeLefty() != null) { 190 iReturn = -1; 191 } else if (b1.getEyeLefty() == null && b2.getEyeLefty() == null) { 192 iReturn = 0; 193 } else if (b1.getEyeLefty() != null && b2.getEyeLefty() == null) { 194 iReturn = 1; 195 } else { 196 iReturn = b1.getEyeLefty().compareTo(b2.getEyeLefty()); 197 } 198 break; 199 case FL_FACE_ID_EYE_RIGHTX: 200 if (b1.getEyeRightx() == null && b2.getEyeRightx() != null) { 201 iReturn = -1; 202 } else if (b1.getEyeRightx() == null && b2.getEyeRightx() == null) { 203 iReturn = 0; 204 } else if (b1.getEyeRightx() != null && b2.getEyeRightx() == null) { 205 iReturn = 1; 206 } else { 207 iReturn = b1.getEyeRightx().compareTo(b2.getEyeRightx()); 208 } 209 break; 210 case FL_FACE_ID_EYE_RIGHTY: 211 if (b1.getEyeRighty() == null && b2.getEyeRighty() != null) { 212 iReturn = -1; 213 } else if (b1.getEyeRighty() == null && b2.getEyeRighty() == null) { 214 iReturn = 0; 215 } else if (b1.getEyeRighty() != null && b2.getEyeRighty() == null) { 216 iReturn = 1; 217 } else { 218 iReturn = b1.getEyeRighty().compareTo(b2.getEyeRighty()); 219 } 220 break; 221 case FL_FACE_ID_MOUTH_X: 222 if (b1.getMouthX() == null && b2.getMouthX() != null) { 223 iReturn = -1; 224 } else if (b1.getMouthX() == null && b2.getMouthX() == null) { 225 iReturn = 0; 226 } else if (b1.getMouthX() != null && b2.getMouthX() == null) { 227 iReturn = 1; 228 } else { 229 iReturn = b1.getMouthX().compareTo(b2.getMouthX()); 230 } 231 break; 232 case FL_FACE_ID_MOUTH_Y: 233 if (b1.getMouthY() == null && b2.getMouthY() != null) { 234 iReturn = -1; 235 } else if (b1.getMouthY() == null && b2.getMouthY() == null) { 236 iReturn = 0; 237 } else if (b1.getMouthY() != null && b2.getMouthY() == null) { 238 iReturn = 1; 239 } else { 240 iReturn = b1.getMouthY().compareTo(b2.getMouthY()); 241 } 242 break; 243 case FL_FACE_ID_NOSE_X: 244 if (b1.getNoseX() == null && b2.getNoseX() != null) { 245 iReturn = -1; 246 } else if (b1.getNoseX() == null && b2.getNoseX() == null) { 247 iReturn = 0; 248 } else if (b1.getNoseX() != null && b2.getNoseX() == null) { 249 iReturn = 1; 250 } else { 251 iReturn = b1.getNoseX().compareTo(b2.getNoseX()); 252 } 253 break; 254 case FL_FACE_ID_NOSE_Y: 255 if (b1.getNoseY() == null && b2.getNoseY() != null) { 256 iReturn = -1; 257 } else if (b1.getNoseY() == null && b2.getNoseY() == null) { 258 iReturn = 0; 259 } else if (b1.getNoseY() != null && b2.getNoseY() == null) { 260 iReturn = 1; 261 } else { 262 iReturn = b1.getNoseY().compareTo(b2.getNoseY()); 263 } 264 break; 265 case FL_FACE_ID_ANGLE_YAW: 266 if (b1.getAngleYaw() == null && b2.getAngleYaw() != null) { 267 iReturn = -1; 268 } else if (b1.getAngleYaw() == null && b2.getAngleYaw() == null) { 269 iReturn = 0; 270 } else if (b1.getAngleYaw() != null && b2.getAngleYaw() == null) { 271 iReturn = 1; 272 } else { 273 iReturn = b1.getAngleYaw().compareTo(b2.getAngleYaw()); 274 } 275 break; 276 case FL_FACE_ID_ANGLE_PITCH: 277 if (b1.getAnglePitch() == null && b2.getAnglePitch() != null) { 278 iReturn = -1; 279 } else if (b1.getAnglePitch() == null && b2.getAnglePitch() == null) { 280 iReturn = 0; 281 } else if (b1.getAnglePitch() != null && b2.getAnglePitch() == null) { 282 iReturn = 1; 283 } else { 284 iReturn = b1.getAnglePitch().compareTo(b2.getAnglePitch()); 285 } 286 break; 287 case FL_FACE_ID_ANGLE_ROLL: 288 if (b1.getAngleRoll() == null && b2.getAngleRoll() != null) { 289 iReturn = -1; 290 } else if (b1.getAngleRoll() == null && b2.getAngleRoll() == null) { 291 iReturn = 0; 292 } else if (b1.getAngleRoll() != null && b2.getAngleRoll() == null) { 293 iReturn = 1; 294 } else { 295 iReturn = b1.getAngleRoll().compareTo(b2.getAngleRoll()); 296 } 297 break; 298 case FL_FACE_ID_EXT_INFO: 299 if (b1.getExtInfo() == null && b2.getExtInfo() != null) { 300 iReturn = -1; 301 } else if (b1.getExtInfo() == null && b2.getExtInfo() == null) { 302 iReturn = 0; 303 } else if (b1.getExtInfo() != null && b2.getExtInfo() == null) { 304 iReturn = 1; 305 } else { 306 iReturn = b1.getExtInfo().compareTo(b2.getExtInfo()); 307 } 308 break; 309 case FL_FACE_ID_FEATURE_MD5: 310 if (b1.getFeatureMd5() == null && b2.getFeatureMd5() != null) { 311 iReturn = -1; 312 } else if (b1.getFeatureMd5() == null && b2.getFeatureMd5() == null) { 313 iReturn = 0; 314 } else if (b1.getFeatureMd5() != null && b2.getFeatureMd5() == null) { 315 iReturn = 1; 316 } else { 317 iReturn = b1.getFeatureMd5().compareTo(b2.getFeatureMd5()); 318 } 319 break; 320 default: 321 throw new IllegalArgumentException("Type passed for the field is not supported"); 322 } 323 324 return bReverse ? (-1 * iReturn) : iReturn; 325 }}