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 LogLightBean objects. 015 * @author sql2java 016 */ 017public class LogLightComparator implements Comparator<LogLightBean>,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 LogLightComparator. 030 * <br> 031 * Example: 032 * <br> 033 * <code>Arrays.sort(pArray, new LogLightComparator(Constant.FL_LOG_LIGHT_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_LOG_LIGHT_ID_ID} 040 * <li>{@link Constant#FL_LOG_LIGHT_ID_PERSON_ID} 041 * <li>{@link Constant#FL_LOG_LIGHT_ID_NAME} 042 * <li>{@link Constant#FL_LOG_LIGHT_ID_PAPERS_TYPE} 043 * <li>{@link Constant#FL_LOG_LIGHT_ID_PAPERS_NUM} 044 * <li>{@link Constant#FL_LOG_LIGHT_ID_VERIFY_TIME} 045 * <li>{@link Constant#FL_LOG_LIGHT_ID_DIRECTION} 046 * </ul> 047 */ 048 public LogLightComparator(int iType) 049 { 050 this(iType, false); 051 } 052 053 /** 054 * Constructor class for LogLightComparator. 055 * <br> 056 * Example: 057 * <br> 058 * <code>Arrays.sort(pArray, new LogLightComparator(Constant.FL_LOG_LIGHT_ID_ID, bReverse));</code> 059 * 060 * @param iType the field from which you want to sort. 061 * <br> 062 * Possible values are: 063 * <ul> 064 * <li>{@link Constant#FL_LOG_LIGHT_ID_ID}) 065 * <li>{@link Constant#FL_LOG_LIGHT_ID_PERSON_ID}) 066 * <li>{@link Constant#FL_LOG_LIGHT_ID_NAME}) 067 * <li>{@link Constant#FL_LOG_LIGHT_ID_PAPERS_TYPE}) 068 * <li>{@link Constant#FL_LOG_LIGHT_ID_PAPERS_NUM}) 069 * <li>{@link Constant#FL_LOG_LIGHT_ID_VERIFY_TIME}) 070 * <li>{@link Constant#FL_LOG_LIGHT_ID_DIRECTION}) 071 * </ul> 072 * 073 * @param bReverse set this value to true, if you want to reverse the sorting results 074 */ 075 public LogLightComparator(int iType, boolean bReverse) 076 { 077 this.iType = iType; 078 this.bReverse = bReverse; 079 } 080 081 @Override 082 public int compare(LogLightBean b1, LogLightBean b2) 083 { 084 int iReturn = 0; 085 switch(iType) 086 { 087 case FL_LOG_LIGHT_ID_ID: 088 if (b1.getId() == null && b2.getId() != null) { 089 iReturn = -1; 090 } else if (b1.getId() == null && b2.getId() == null) { 091 iReturn = 0; 092 } else if (b1.getId() != null && b2.getId() == null) { 093 iReturn = 1; 094 } else { 095 iReturn = b1.getId().compareTo(b2.getId()); 096 } 097 break; 098 case FL_LOG_LIGHT_ID_PERSON_ID: 099 if (b1.getPersonId() == null && b2.getPersonId() != null) { 100 iReturn = -1; 101 } else if (b1.getPersonId() == null && b2.getPersonId() == null) { 102 iReturn = 0; 103 } else if (b1.getPersonId() != null && b2.getPersonId() == null) { 104 iReturn = 1; 105 } else { 106 iReturn = b1.getPersonId().compareTo(b2.getPersonId()); 107 } 108 break; 109 case FL_LOG_LIGHT_ID_NAME: 110 if (b1.getName() == null && b2.getName() != null) { 111 iReturn = -1; 112 } else if (b1.getName() == null && b2.getName() == null) { 113 iReturn = 0; 114 } else if (b1.getName() != null && b2.getName() == null) { 115 iReturn = 1; 116 } else { 117 iReturn = b1.getName().compareTo(b2.getName()); 118 } 119 break; 120 case FL_LOG_LIGHT_ID_PAPERS_TYPE: 121 if (b1.getPapersType() == null && b2.getPapersType() != null) { 122 iReturn = -1; 123 } else if (b1.getPapersType() == null && b2.getPapersType() == null) { 124 iReturn = 0; 125 } else if (b1.getPapersType() != null && b2.getPapersType() == null) { 126 iReturn = 1; 127 } else { 128 iReturn = b1.getPapersType().compareTo(b2.getPapersType()); 129 } 130 break; 131 case FL_LOG_LIGHT_ID_PAPERS_NUM: 132 if (b1.getPapersNum() == null && b2.getPapersNum() != null) { 133 iReturn = -1; 134 } else if (b1.getPapersNum() == null && b2.getPapersNum() == null) { 135 iReturn = 0; 136 } else if (b1.getPapersNum() != null && b2.getPapersNum() == null) { 137 iReturn = 1; 138 } else { 139 iReturn = b1.getPapersNum().compareTo(b2.getPapersNum()); 140 } 141 break; 142 case FL_LOG_LIGHT_ID_VERIFY_TIME: 143 if (b1.getVerifyTime() == null && b2.getVerifyTime() != null) { 144 iReturn = -1; 145 } else if (b1.getVerifyTime() == null && b2.getVerifyTime() == null) { 146 iReturn = 0; 147 } else if (b1.getVerifyTime() != null && b2.getVerifyTime() == null) { 148 iReturn = 1; 149 } else { 150 iReturn = b1.getVerifyTime().compareTo(b2.getVerifyTime()); 151 } 152 break; 153 case FL_LOG_LIGHT_ID_DIRECTION: 154 if (b1.getDirection() == null && b2.getDirection() != null) { 155 iReturn = -1; 156 } else if (b1.getDirection() == null && b2.getDirection() == null) { 157 iReturn = 0; 158 } else if (b1.getDirection() != null && b2.getDirection() == null) { 159 iReturn = 1; 160 } else { 161 iReturn = b1.getDirection().compareTo(b2.getDirection()); 162 } 163 break; 164 default: 165 throw new IllegalArgumentException("Type passed for the field is not supported"); 166 } 167 168 return bReverse ? (-1 * iReturn) : iReturn; 169 }}