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 StoreBean objects. 015 * @author sql2java 016 */ 017public class StoreComparator implements Comparator<StoreBean>,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 StoreComparator. 030 * <br> 031 * Example: 032 * <br> 033 * <code>Arrays.sort(pArray, new StoreComparator(Constant.FL_STORE_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_STORE_ID_MD5} 040 * <li>{@link Constant#FL_STORE_ID_ENCODING} 041 * <li>{@link Constant#FL_STORE_ID_DATA} 042 * </ul> 043 */ 044 public StoreComparator(int iType) 045 { 046 this(iType, false); 047 } 048 049 /** 050 * Constructor class for StoreComparator. 051 * <br> 052 * Example: 053 * <br> 054 * <code>Arrays.sort(pArray, new StoreComparator(Constant.FL_STORE_ID_MD5, bReverse));</code> 055 * 056 * @param iType the field from which you want to sort. 057 * <br> 058 * Possible values are: 059 * <ul> 060 * <li>{@link Constant#FL_STORE_ID_MD5}) 061 * <li>{@link Constant#FL_STORE_ID_ENCODING}) 062 * <li>{@link Constant#FL_STORE_ID_DATA}) 063 * </ul> 064 * 065 * @param bReverse set this value to true, if you want to reverse the sorting results 066 */ 067 public StoreComparator(int iType, boolean bReverse) 068 { 069 this.iType = iType; 070 this.bReverse = bReverse; 071 } 072 073 @Override 074 public int compare(StoreBean b1, StoreBean b2) 075 { 076 int iReturn = 0; 077 switch(iType) 078 { 079 case FL_STORE_ID_MD5: 080 if (b1.getMd5() == null && b2.getMd5() != null) { 081 iReturn = -1; 082 } else if (b1.getMd5() == null && b2.getMd5() == null) { 083 iReturn = 0; 084 } else if (b1.getMd5() != null && b2.getMd5() == null) { 085 iReturn = 1; 086 } else { 087 iReturn = b1.getMd5().compareTo(b2.getMd5()); 088 } 089 break; 090 case FL_STORE_ID_ENCODING: 091 if (b1.getEncoding() == null && b2.getEncoding() != null) { 092 iReturn = -1; 093 } else if (b1.getEncoding() == null && b2.getEncoding() == null) { 094 iReturn = 0; 095 } else if (b1.getEncoding() != null && b2.getEncoding() == null) { 096 iReturn = 1; 097 } else { 098 iReturn = b1.getEncoding().compareTo(b2.getEncoding()); 099 } 100 break; 101 case FL_STORE_ID_DATA: 102 if (b1.getData() == null && b2.getData() != null) { 103 iReturn = -1; 104 } else if (b1.getData() == null && b2.getData() == null) { 105 iReturn = 0; 106 } else if (b1.getData() != null && b2.getData() == null) { 107 iReturn = 1; 108 } else { 109 iReturn = b1.getData().compareTo(b2.getData()); 110 } 111 break; 112 default: 113 throw new IllegalArgumentException("Type passed for the field is not supported"); 114 } 115 116 return bReverse ? (-1 * iReturn) : iReturn; 117 }}