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