litesoft
@ 947
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.core.simpletypes.nonpublic; public abstract class CompareSupport<T> extends EqualSupport implements Comparable<T> { public static final int EQUAL = 0; public static final int GREATER = 1; public static final int LESSER = -1; public CompareSupport() { } public static boolean lessThan( Comparable pThis, Comparable pThem ) { return lessThan( compare( pThis, pThem ) ); } public static boolean greaterThan( Comparable pThis, Comparable pThem ) { return greaterThan( compare( pThis, pThem ) ); } public static boolean lessThan( int pCompareResult ) { return (pCompareResult < 0); } public static boolean greaterThan( int pCompareResult ) { return (pCompareResult > 0); } /** * @return 1, 0, -1 as pThis > pThem, pThis == pThem, pThis < pThem */ public static int compare( int pThis, int pThem ) { return (pThis == pThem) ? 0 : (pThis > pThem) ? 1 : -1; } /** * @return 1, 0, -1 as pThis > pThem, pThis == pThem, pThis < pThem */ public static int compare( long pThis, long pThem ) { return (pThis == pThem) ? 0 : (pThis > pThem) ? 1 : -1; } /** * @return 1, 0, -1 as pThis & !pThem, pThis == pThem, !pThis & pThem */ public static int compare( boolean pThis, boolean pThem ) { return (pThis == pThem) ? 0 : pThis ? 1 : -1; } /** * @return >0, 0, <0 as pThis > pThem, pThis == pThem, pThis < pThem */ public static int compare( Comparable pThis, Comparable pThem ) { if ( pThis == pThem ) { return 0; // the same (or both null) } if ( pThis == null ) // null - !null { return -1; } if ( pThem == null ) // !null - null { return 1; } return LLcompare( pThis, pThem ); } @SuppressWarnings({"unchecked"}) private static int LLcompare( Comparable pThis, Comparable pThem ) { return pThis.compareTo( pThem ); } public static int compareObjects( Object pThis, Object pThem ) { return compare( toComparable( pThis ), toComparable( pThem ) ); } public static Comparable toComparable( Object pObject ) { return (pObject instanceof Comparable) ? (Comparable) pObject : null; } public static int compareEm( int pCompare1, int pCompare2 ) { return (pCompare1 != 0) ? // pCompare1 : // pCompare2; } public static int compareEm( int pCompare1, int pCompare2, int pCompare3 ) { return (pCompare1 != 0) ? // pCompare1 : (pCompare2 != 0) ? // pCompare2 : // pCompare3; } public static int compareEm( int pCompare1, int pCompare2, int pCompare3, int pCompare4 ) { return (pCompare1 != 0) ? // pCompare1 : (pCompare2 != 0) ? // pCompare2 : (pCompare3 != 0) ? // pCompare3 : // pCompare4; } public static int compareEm( int pCompare1, int pCompare2, int pCompare3, int pCompare4, int pCompare5 ) { return (pCompare1 != 0) ? // pCompare1 : (pCompare2 != 0) ? // pCompare2 : (pCompare3 != 0) ? // pCompare3 : (pCompare4 != 0) ? // pCompare4 : // pCompare5; } } |