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 ImageBean objects.
015 * @author sql2java
016 */
017public class ImageComparator implements Comparator<ImageBean>,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 ImageComparator.
030     * <br>
031     * Example:
032     * <br>
033     * <code>Arrays.sort(pArray, new ImageComparator(Constant.FL_IMAGE_ID_MD5, 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_IMAGE_ID_MD5}
040     *   <li>{@link Constant#FL_IMAGE_ID_FORMAT}
041     *   <li>{@link Constant#FL_IMAGE_ID_WIDTH}
042     *   <li>{@link Constant#FL_IMAGE_ID_HEIGHT}
043     *   <li>{@link Constant#FL_IMAGE_ID_DEPTH}
044     *   <li>{@link Constant#FL_IMAGE_ID_FACE_NUM}
045     *   <li>{@link Constant#FL_IMAGE_ID_THUMB_MD5}
046     *   <li>{@link Constant#FL_IMAGE_ID_DEVICE_ID}
047     * </ul>
048     */
049    public ImageComparator(int iType)
050    {
051        this(iType, false);
052    }
053
054    /**
055     * Constructor class for ImageComparator.
056     * <br>
057     * Example:
058     * <br>
059     * <code>Arrays.sort(pArray, new ImageComparator(Constant.FL_IMAGE_ID_MD5, 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_IMAGE_ID_MD5})
066     *   <li>{@link Constant#FL_IMAGE_ID_FORMAT})
067     *   <li>{@link Constant#FL_IMAGE_ID_WIDTH})
068     *   <li>{@link Constant#FL_IMAGE_ID_HEIGHT})
069     *   <li>{@link Constant#FL_IMAGE_ID_DEPTH})
070     *   <li>{@link Constant#FL_IMAGE_ID_FACE_NUM})
071     *   <li>{@link Constant#FL_IMAGE_ID_THUMB_MD5})
072     *   <li>{@link Constant#FL_IMAGE_ID_DEVICE_ID})
073     * </ul>
074     *
075     * @param bReverse set this value to true, if you want to reverse the sorting results
076     */
077    public ImageComparator(int iType, boolean bReverse)
078    {
079        this.iType = iType;
080        this.bReverse = bReverse;
081    }
082
083    @Override
084    public int compare(ImageBean b1, ImageBean b2)
085    {
086        int iReturn = 0;
087        switch(iType)
088        {
089            case FL_IMAGE_ID_MD5:
090                if (b1.getMd5() == null && b2.getMd5() != null) {
091                    iReturn = -1;
092                } else if (b1.getMd5() == null && b2.getMd5() == null) {
093                    iReturn = 0;
094                } else if (b1.getMd5() != null && b2.getMd5() == null) {
095                    iReturn = 1;
096                } else {
097                    iReturn = b1.getMd5().compareTo(b2.getMd5());
098                }
099                break;
100            case FL_IMAGE_ID_FORMAT:
101                if (b1.getFormat() == null && b2.getFormat() != null) {
102                    iReturn = -1;
103                } else if (b1.getFormat() == null && b2.getFormat() == null) {
104                    iReturn = 0;
105                } else if (b1.getFormat() != null && b2.getFormat() == null) {
106                    iReturn = 1;
107                } else {
108                    iReturn = b1.getFormat().compareTo(b2.getFormat());
109                }
110                break;
111            case FL_IMAGE_ID_WIDTH:
112                if (b1.getWidth() == null && b2.getWidth() != null) {
113                    iReturn = -1;
114                } else if (b1.getWidth() == null && b2.getWidth() == null) {
115                    iReturn = 0;
116                } else if (b1.getWidth() != null && b2.getWidth() == null) {
117                    iReturn = 1;
118                } else {
119                    iReturn = b1.getWidth().compareTo(b2.getWidth());
120                }
121                break;
122            case FL_IMAGE_ID_HEIGHT:
123                if (b1.getHeight() == null && b2.getHeight() != null) {
124                    iReturn = -1;
125                } else if (b1.getHeight() == null && b2.getHeight() == null) {
126                    iReturn = 0;
127                } else if (b1.getHeight() != null && b2.getHeight() == null) {
128                    iReturn = 1;
129                } else {
130                    iReturn = b1.getHeight().compareTo(b2.getHeight());
131                }
132                break;
133            case FL_IMAGE_ID_DEPTH:
134                if (b1.getDepth() == null && b2.getDepth() != null) {
135                    iReturn = -1;
136                } else if (b1.getDepth() == null && b2.getDepth() == null) {
137                    iReturn = 0;
138                } else if (b1.getDepth() != null && b2.getDepth() == null) {
139                    iReturn = 1;
140                } else {
141                    iReturn = b1.getDepth().compareTo(b2.getDepth());
142                }
143                break;
144            case FL_IMAGE_ID_FACE_NUM:
145                if (b1.getFaceNum() == null && b2.getFaceNum() != null) {
146                    iReturn = -1;
147                } else if (b1.getFaceNum() == null && b2.getFaceNum() == null) {
148                    iReturn = 0;
149                } else if (b1.getFaceNum() != null && b2.getFaceNum() == null) {
150                    iReturn = 1;
151                } else {
152                    iReturn = b1.getFaceNum().compareTo(b2.getFaceNum());
153                }
154                break;
155            case FL_IMAGE_ID_THUMB_MD5:
156                if (b1.getThumbMd5() == null && b2.getThumbMd5() != null) {
157                    iReturn = -1;
158                } else if (b1.getThumbMd5() == null && b2.getThumbMd5() == null) {
159                    iReturn = 0;
160                } else if (b1.getThumbMd5() != null && b2.getThumbMd5() == null) {
161                    iReturn = 1;
162                } else {
163                    iReturn = b1.getThumbMd5().compareTo(b2.getThumbMd5());
164                }
165                break;
166            case FL_IMAGE_ID_DEVICE_ID:
167                if (b1.getDeviceId() == null && b2.getDeviceId() != null) {
168                    iReturn = -1;
169                } else if (b1.getDeviceId() == null && b2.getDeviceId() == null) {
170                    iReturn = 0;
171                } else if (b1.getDeviceId() != null && b2.getDeviceId() == null) {
172                    iReturn = 1;
173                } else {
174                    iReturn = b1.getDeviceId().compareTo(b2.getDeviceId());
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    }}