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 LogBean objects.
015 * @author sql2java
016 */
017public class LogComparator implements Comparator<LogBean>,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 LogComparator.
030     * <br>
031     * Example:
032     * <br>
033     * <code>Arrays.sort(pArray, new LogComparator(Constant.FL_LOG_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_ID_ID}
040     *   <li>{@link Constant#FL_LOG_ID_PERSON_ID}
041     *   <li>{@link Constant#FL_LOG_ID_DEVICE_ID}
042     *   <li>{@link Constant#FL_LOG_ID_VERIFY_FEATURE}
043     *   <li>{@link Constant#FL_LOG_ID_COMPARE_FACE}
044     *   <li>{@link Constant#FL_LOG_ID_VERIFY_STATUS}
045     *   <li>{@link Constant#FL_LOG_ID_SIMILARTY}
046     *   <li>{@link Constant#FL_LOG_ID_DIRECTION}
047     *   <li>{@link Constant#FL_LOG_ID_VERIFY_TIME}
048     *   <li>{@link Constant#FL_LOG_ID_CREATE_TIME}
049     * </ul>
050     */
051    public LogComparator(int iType)
052    {
053        this(iType, false);
054    }
055
056    /**
057     * Constructor class for LogComparator.
058     * <br>
059     * Example:
060     * <br>
061     * <code>Arrays.sort(pArray, new LogComparator(Constant.FL_LOG_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_LOG_ID_ID})
068     *   <li>{@link Constant#FL_LOG_ID_PERSON_ID})
069     *   <li>{@link Constant#FL_LOG_ID_DEVICE_ID})
070     *   <li>{@link Constant#FL_LOG_ID_VERIFY_FEATURE})
071     *   <li>{@link Constant#FL_LOG_ID_COMPARE_FACE})
072     *   <li>{@link Constant#FL_LOG_ID_VERIFY_STATUS})
073     *   <li>{@link Constant#FL_LOG_ID_SIMILARTY})
074     *   <li>{@link Constant#FL_LOG_ID_DIRECTION})
075     *   <li>{@link Constant#FL_LOG_ID_VERIFY_TIME})
076     *   <li>{@link Constant#FL_LOG_ID_CREATE_TIME})
077     * </ul>
078     *
079     * @param bReverse set this value to true, if you want to reverse the sorting results
080     */
081    public LogComparator(int iType, boolean bReverse)
082    {
083        this.iType = iType;
084        this.bReverse = bReverse;
085    }
086
087    @Override
088    public int compare(LogBean b1, LogBean b2)
089    {
090        int iReturn = 0;
091        switch(iType)
092        {
093            case FL_LOG_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_LOG_ID_PERSON_ID:
105                if (b1.getPersonId() == null && b2.getPersonId() != null) {
106                    iReturn = -1;
107                } else if (b1.getPersonId() == null && b2.getPersonId() == null) {
108                    iReturn = 0;
109                } else if (b1.getPersonId() != null && b2.getPersonId() == null) {
110                    iReturn = 1;
111                } else {
112                    iReturn = b1.getPersonId().compareTo(b2.getPersonId());
113                }
114                break;
115            case FL_LOG_ID_DEVICE_ID:
116                if (b1.getDeviceId() == null && b2.getDeviceId() != null) {
117                    iReturn = -1;
118                } else if (b1.getDeviceId() == null && b2.getDeviceId() == null) {
119                    iReturn = 0;
120                } else if (b1.getDeviceId() != null && b2.getDeviceId() == null) {
121                    iReturn = 1;
122                } else {
123                    iReturn = b1.getDeviceId().compareTo(b2.getDeviceId());
124                }
125                break;
126            case FL_LOG_ID_VERIFY_FEATURE:
127                if (b1.getVerifyFeature() == null && b2.getVerifyFeature() != null) {
128                    iReturn = -1;
129                } else if (b1.getVerifyFeature() == null && b2.getVerifyFeature() == null) {
130                    iReturn = 0;
131                } else if (b1.getVerifyFeature() != null && b2.getVerifyFeature() == null) {
132                    iReturn = 1;
133                } else {
134                    iReturn = b1.getVerifyFeature().compareTo(b2.getVerifyFeature());
135                }
136                break;
137            case FL_LOG_ID_COMPARE_FACE:
138                if (b1.getCompareFace() == null && b2.getCompareFace() != null) {
139                    iReturn = -1;
140                } else if (b1.getCompareFace() == null && b2.getCompareFace() == null) {
141                    iReturn = 0;
142                } else if (b1.getCompareFace() != null && b2.getCompareFace() == null) {
143                    iReturn = 1;
144                } else {
145                    iReturn = b1.getCompareFace().compareTo(b2.getCompareFace());
146                }
147                break;
148            case FL_LOG_ID_VERIFY_STATUS:
149                if (b1.getVerifyStatus() == null && b2.getVerifyStatus() != null) {
150                    iReturn = -1;
151                } else if (b1.getVerifyStatus() == null && b2.getVerifyStatus() == null) {
152                    iReturn = 0;
153                } else if (b1.getVerifyStatus() != null && b2.getVerifyStatus() == null) {
154                    iReturn = 1;
155                } else {
156                    iReturn = b1.getVerifyStatus().compareTo(b2.getVerifyStatus());
157                }
158                break;
159            case FL_LOG_ID_SIMILARTY:
160                if (b1.getSimilarty() == null && b2.getSimilarty() != null) {
161                    iReturn = -1;
162                } else if (b1.getSimilarty() == null && b2.getSimilarty() == null) {
163                    iReturn = 0;
164                } else if (b1.getSimilarty() != null && b2.getSimilarty() == null) {
165                    iReturn = 1;
166                } else {
167                    iReturn = b1.getSimilarty().compareTo(b2.getSimilarty());
168                }
169                break;
170            case FL_LOG_ID_DIRECTION:
171                if (b1.getDirection() == null && b2.getDirection() != null) {
172                    iReturn = -1;
173                } else if (b1.getDirection() == null && b2.getDirection() == null) {
174                    iReturn = 0;
175                } else if (b1.getDirection() != null && b2.getDirection() == null) {
176                    iReturn = 1;
177                } else {
178                    iReturn = b1.getDirection().compareTo(b2.getDirection());
179                }
180                break;
181            case FL_LOG_ID_VERIFY_TIME:
182                if (b1.getVerifyTime() == null && b2.getVerifyTime() != null) {
183                    iReturn = -1;
184                } else if (b1.getVerifyTime() == null && b2.getVerifyTime() == null) {
185                    iReturn = 0;
186                } else if (b1.getVerifyTime() != null && b2.getVerifyTime() == null) {
187                    iReturn = 1;
188                } else {
189                    iReturn = b1.getVerifyTime().compareTo(b2.getVerifyTime());
190                }
191                break;
192            case FL_LOG_ID_CREATE_TIME:
193                if (b1.getCreateTime() == null && b2.getCreateTime() != null) {
194                    iReturn = -1;
195                } else if (b1.getCreateTime() == null && b2.getCreateTime() == null) {
196                    iReturn = 0;
197                } else if (b1.getCreateTime() != null && b2.getCreateTime() == null) {
198                    iReturn = 1;
199                } else {
200                    iReturn = b1.getCreateTime().compareTo(b2.getCreateTime());
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    }}