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 FeatureBean objects. 015 * @author sql2java 016 */ 017public class FeatureComparator implements Comparator<FeatureBean>,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 FeatureComparator. 030 * <br> 031 * Example: 032 * <br> 033 * <code>Arrays.sort(pArray, new FeatureComparator(Constant.FL_FEATURE_ID_MD5, 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_FEATURE_ID_MD5} 040 * <li>{@link Constant#FL_FEATURE_ID_VERSION} 041 * <li>{@link Constant#FL_FEATURE_ID_PERSON_ID} 042 * <li>{@link Constant#FL_FEATURE_ID_FEATURE} 043 * <li>{@link Constant#FL_FEATURE_ID_UPDATE_TIME} 044 * </ul> 045 */ 046 public FeatureComparator(int iType) 047 { 048 this(iType, false); 049 } 050 051 /** 052 * Constructor class for FeatureComparator. 053 * <br> 054 * Example: 055 * <br> 056 * <code>Arrays.sort(pArray, new FeatureComparator(Constant.FL_FEATURE_ID_MD5, bReverse));</code> 057 * 058 * @param iType the field from which you want to sort. 059 * <br> 060 * Possible values are: 061 * <ul> 062 * <li>{@link Constant#FL_FEATURE_ID_MD5}) 063 * <li>{@link Constant#FL_FEATURE_ID_VERSION}) 064 * <li>{@link Constant#FL_FEATURE_ID_PERSON_ID}) 065 * <li>{@link Constant#FL_FEATURE_ID_FEATURE}) 066 * <li>{@link Constant#FL_FEATURE_ID_UPDATE_TIME}) 067 * </ul> 068 * 069 * @param bReverse set this value to true, if you want to reverse the sorting results 070 */ 071 public FeatureComparator(int iType, boolean bReverse) 072 { 073 this.iType = iType; 074 this.bReverse = bReverse; 075 } 076 077 @Override 078 public int compare(FeatureBean b1, FeatureBean b2) 079 { 080 int iReturn = 0; 081 switch(iType) 082 { 083 case FL_FEATURE_ID_MD5: 084 if (b1.getMd5() == null && b2.getMd5() != null) { 085 iReturn = -1; 086 } else if (b1.getMd5() == null && b2.getMd5() == null) { 087 iReturn = 0; 088 } else if (b1.getMd5() != null && b2.getMd5() == null) { 089 iReturn = 1; 090 } else { 091 iReturn = b1.getMd5().compareTo(b2.getMd5()); 092 } 093 break; 094 case FL_FEATURE_ID_VERSION: 095 if (b1.getVersion() == null && b2.getVersion() != null) { 096 iReturn = -1; 097 } else if (b1.getVersion() == null && b2.getVersion() == null) { 098 iReturn = 0; 099 } else if (b1.getVersion() != null && b2.getVersion() == null) { 100 iReturn = 1; 101 } else { 102 iReturn = b1.getVersion().compareTo(b2.getVersion()); 103 } 104 break; 105 case FL_FEATURE_ID_PERSON_ID: 106 if (b1.getPersonId() == null && b2.getPersonId() != null) { 107 iReturn = -1; 108 } else if (b1.getPersonId() == null && b2.getPersonId() == null) { 109 iReturn = 0; 110 } else if (b1.getPersonId() != null && b2.getPersonId() == null) { 111 iReturn = 1; 112 } else { 113 iReturn = b1.getPersonId().compareTo(b2.getPersonId()); 114 } 115 break; 116 case FL_FEATURE_ID_FEATURE: 117 if (b1.getFeature() == null && b2.getFeature() != null) { 118 iReturn = -1; 119 } else if (b1.getFeature() == null && b2.getFeature() == null) { 120 iReturn = 0; 121 } else if (b1.getFeature() != null && b2.getFeature() == null) { 122 iReturn = 1; 123 } else { 124 iReturn = b1.getFeature().compareTo(b2.getFeature()); 125 } 126 break; 127 case FL_FEATURE_ID_UPDATE_TIME: 128 if (b1.getUpdateTime() == null && b2.getUpdateTime() != null) { 129 iReturn = -1; 130 } else if (b1.getUpdateTime() == null && b2.getUpdateTime() == null) { 131 iReturn = 0; 132 } else if (b1.getUpdateTime() != null && b2.getUpdateTime() == null) { 133 iReturn = 1; 134 } else { 135 iReturn = b1.getUpdateTime().compareTo(b2.getUpdateTime()); 136 } 137 break; 138 default: 139 throw new IllegalArgumentException("Type passed for the field is not supported"); 140 } 141 142 return bReverse ? (-1 * iReturn) : iReturn; 143 }}