Subversion Repository Public Repository

litesoft

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
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( 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;
    }
}

Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/typeutils/Integers.java

Diff revisions: vs.
Revision Author Commited Message
812 Diff Diff GeorgeS picture GeorgeS Sat 18 Aug, 2012 17:45:40 +0000
809 Diff Diff GeorgeS picture GeorgeS Thu 16 Aug, 2012 04:10:46 +0000
804 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 12:48:51 +0000
787 GeorgeS picture GeorgeS Mon 30 Jul, 2012 03:00:12 +0000