litesoft
@ 809
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 |
package org.litesoft.core.typeutils; import org.litesoft.core.util.*; public class Integers { public static final int[] EMPTY_ARRAY_PRIMITIVES = new int[0]; public static final Integer[] EMPTY_ARRAY = new Integer[0]; public static int assertPositive( String pWhat, int pInt ) { if ( 0 < pInt ) { return pInt; } throw new IllegalArgumentException( pWhat + " expected to be positive, but was: " + pInt ); } public static int assertNonNegative( String pWhat, int pInt ) { if ( 0 <= pInt ) { return pInt; } throw new IllegalArgumentException( pWhat + " expected to be non-negative, but was: " + pInt ); } public static void assertNotEqual( String pObjectName, int pNotExpected, int pActual ) throws IllegalArgumentException { if ( pNotExpected == pActual ) { throw new IllegalArgumentException( pObjectName + ": '" + pNotExpected + "' Not allowed" ); } } public static void assertEqual( String pObjectName, int pExpected, int pActual ) throws IllegalArgumentException { if ( pExpected != pActual ) { throw new IllegalArgumentException( pObjectName + ": Expected '" + pExpected + "', but was '" + pActual + "'" ); } } public static String zeroPadIt( int pMinDesiredLength, int pIt ) { String rv = String.valueOf( pIt ); while ( rv.length() < pMinDesiredLength ) { rv = "0" + rv; } return rv; } public static String padIt( int pMinDesiredLength, int pIt ) { return Strings.padIt( pMinDesiredLength, "" + pIt ); } public static String iTpad( int pIt, int pMinDesiredLength ) { return Strings.iTpad( "" + pIt, pMinDesiredLength ); } public static boolean isNullOrEmpty( int[] pArrayToCheck ) { return (pArrayToCheck == null || pArrayToCheck.length == 0); } public static boolean areArraysEqual( byte[] pThis, byte[] pThat ) { if ( pThis == pThat ) // handles if both are null { return true; } if ( (pThis != null) && (pThat != null) && (pThis.length == pThat.length) ) { for ( int i = pThis.length; --i >= 0; ) { if ( pThis[i] != pThat[i] ) { return false; } } return true; } return false; } public static boolean areArraysEqual( int[] pThis, int[] pThat ) { if ( pThis == pThat ) // handles if both are null { return true; } if ( (pThis != null) && (pThat != null) && (pThis.length == pThat.length) ) { for ( int i = pThis.length; --i >= 0; ) { if ( pThis[i] != pThat[i] ) { return false; } } return true; } return false; } } |