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