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 PersonGroupBean objects. 015 * @author sql2java 016 */ 017public class PersonGroupComparator implements Comparator<PersonGroupBean>,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 PersonGroupComparator. 030 * <br> 031 * Example: 032 * <br> 033 * <code>Arrays.sort(pArray, new PersonGroupComparator(Constant.FL_PERSON_GROUP_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_GROUP_ID_ID} 040 * <li>{@link Constant#FL_PERSON_GROUP_ID_NAME} 041 * <li>{@link Constant#FL_PERSON_GROUP_ID_LEAF} 042 * <li>{@link Constant#FL_PERSON_GROUP_ID_PARENT} 043 * <li>{@link Constant#FL_PERSON_GROUP_ID_ROOT_GROUP} 044 * <li>{@link Constant#FL_PERSON_GROUP_ID_REMARK} 045 * <li>{@link Constant#FL_PERSON_GROUP_ID_EXT_BIN} 046 * <li>{@link Constant#FL_PERSON_GROUP_ID_EXT_TXT} 047 * <li>{@link Constant#FL_PERSON_GROUP_ID_CREATE_TIME} 048 * <li>{@link Constant#FL_PERSON_GROUP_ID_UPDATE_TIME} 049 * </ul> 050 */ 051 public PersonGroupComparator(int iType) 052 { 053 this(iType, false); 054 } 055 056 /** 057 * Constructor class for PersonGroupComparator. 058 * <br> 059 * Example: 060 * <br> 061 * <code>Arrays.sort(pArray, new PersonGroupComparator(Constant.FL_PERSON_GROUP_ID_ID, bReverse));</code> 062 * 063 * @param iType the field from which you want to sort. 064 * <br> 065 * Possible values are: 066 * <ul> 067 * <li>{@link Constant#FL_PERSON_GROUP_ID_ID}) 068 * <li>{@link Constant#FL_PERSON_GROUP_ID_NAME}) 069 * <li>{@link Constant#FL_PERSON_GROUP_ID_LEAF}) 070 * <li>{@link Constant#FL_PERSON_GROUP_ID_PARENT}) 071 * <li>{@link Constant#FL_PERSON_GROUP_ID_ROOT_GROUP}) 072 * <li>{@link Constant#FL_PERSON_GROUP_ID_REMARK}) 073 * <li>{@link Constant#FL_PERSON_GROUP_ID_EXT_BIN}) 074 * <li>{@link Constant#FL_PERSON_GROUP_ID_EXT_TXT}) 075 * <li>{@link Constant#FL_PERSON_GROUP_ID_CREATE_TIME}) 076 * <li>{@link Constant#FL_PERSON_GROUP_ID_UPDATE_TIME}) 077 * </ul> 078 * 079 * @param bReverse set this value to true, if you want to reverse the sorting results 080 */ 081 public PersonGroupComparator(int iType, boolean bReverse) 082 { 083 this.iType = iType; 084 this.bReverse = bReverse; 085 } 086 087 @Override 088 public int compare(PersonGroupBean b1, PersonGroupBean b2) 089 { 090 int iReturn = 0; 091 switch(iType) 092 { 093 case FL_PERSON_GROUP_ID_ID: 094 if (b1.getId() == null && b2.getId() != null) { 095 iReturn = -1; 096 } else if (b1.getId() == null && b2.getId() == null) { 097 iReturn = 0; 098 } else if (b1.getId() != null && b2.getId() == null) { 099 iReturn = 1; 100 } else { 101 iReturn = b1.getId().compareTo(b2.getId()); 102 } 103 break; 104 case FL_PERSON_GROUP_ID_NAME: 105 if (b1.getName() == null && b2.getName() != null) { 106 iReturn = -1; 107 } else if (b1.getName() == null && b2.getName() == null) { 108 iReturn = 0; 109 } else if (b1.getName() != null && b2.getName() == null) { 110 iReturn = 1; 111 } else { 112 iReturn = b1.getName().compareTo(b2.getName()); 113 } 114 break; 115 case FL_PERSON_GROUP_ID_LEAF: 116 if (b1.getLeaf() == null && b2.getLeaf() != null) { 117 iReturn = -1; 118 } else if (b1.getLeaf() == null && b2.getLeaf() == null) { 119 iReturn = 0; 120 } else if (b1.getLeaf() != null && b2.getLeaf() == null) { 121 iReturn = 1; 122 } else { 123 iReturn = b1.getLeaf().compareTo(b2.getLeaf()); 124 } 125 break; 126 case FL_PERSON_GROUP_ID_PARENT: 127 if (b1.getParent() == null && b2.getParent() != null) { 128 iReturn = -1; 129 } else if (b1.getParent() == null && b2.getParent() == null) { 130 iReturn = 0; 131 } else if (b1.getParent() != null && b2.getParent() == null) { 132 iReturn = 1; 133 } else { 134 iReturn = b1.getParent().compareTo(b2.getParent()); 135 } 136 break; 137 case FL_PERSON_GROUP_ID_ROOT_GROUP: 138 if (b1.getRootGroup() == null && b2.getRootGroup() != null) { 139 iReturn = -1; 140 } else if (b1.getRootGroup() == null && b2.getRootGroup() == null) { 141 iReturn = 0; 142 } else if (b1.getRootGroup() != null && b2.getRootGroup() == null) { 143 iReturn = 1; 144 } else { 145 iReturn = b1.getRootGroup().compareTo(b2.getRootGroup()); 146 } 147 break; 148 case FL_PERSON_GROUP_ID_REMARK: 149 if (b1.getRemark() == null && b2.getRemark() != null) { 150 iReturn = -1; 151 } else if (b1.getRemark() == null && b2.getRemark() == null) { 152 iReturn = 0; 153 } else if (b1.getRemark() != null && b2.getRemark() == null) { 154 iReturn = 1; 155 } else { 156 iReturn = b1.getRemark().compareTo(b2.getRemark()); 157 } 158 break; 159 case FL_PERSON_GROUP_ID_EXT_BIN: 160 if (b1.getExtBin() == null && b2.getExtBin() != null) { 161 iReturn = -1; 162 } else if (b1.getExtBin() == null && b2.getExtBin() == null) { 163 iReturn = 0; 164 } else if (b1.getExtBin() != null && b2.getExtBin() == null) { 165 iReturn = 1; 166 } else { 167 iReturn = b1.getExtBin().compareTo(b2.getExtBin()); 168 } 169 break; 170 case FL_PERSON_GROUP_ID_EXT_TXT: 171 if (b1.getExtTxt() == null && b2.getExtTxt() != null) { 172 iReturn = -1; 173 } else if (b1.getExtTxt() == null && b2.getExtTxt() == null) { 174 iReturn = 0; 175 } else if (b1.getExtTxt() != null && b2.getExtTxt() == null) { 176 iReturn = 1; 177 } else { 178 iReturn = b1.getExtTxt().compareTo(b2.getExtTxt()); 179 } 180 break; 181 case FL_PERSON_GROUP_ID_CREATE_TIME: 182 if (b1.getCreateTime() == null && b2.getCreateTime() != null) { 183 iReturn = -1; 184 } else if (b1.getCreateTime() == null && b2.getCreateTime() == null) { 185 iReturn = 0; 186 } else if (b1.getCreateTime() != null && b2.getCreateTime() == null) { 187 iReturn = 1; 188 } else { 189 iReturn = b1.getCreateTime().compareTo(b2.getCreateTime()); 190 } 191 break; 192 case FL_PERSON_GROUP_ID_UPDATE_TIME: 193 if (b1.getUpdateTime() == null && b2.getUpdateTime() != null) { 194 iReturn = -1; 195 } else if (b1.getUpdateTime() == null && b2.getUpdateTime() == null) { 196 iReturn = 0; 197 } else if (b1.getUpdateTime() != null && b2.getUpdateTime() == null) { 198 iReturn = 1; 199 } else { 200 iReturn = b1.getUpdateTime().compareTo(b2.getUpdateTime()); 201 } 202 break; 203 default: 204 throw new IllegalArgumentException("Type passed for the field is not supported"); 205 } 206 207 return bReverse ? (-1 * iReturn) : iReturn; 208 }}