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
package org.litesoft.core.typeutils;

import org.litesoft.core.annotations.*;

public class Strings
{
    public static final String[] EMPTY_ARRAY = new String[0];

    /**
     * Adjust a String Array so that it is either null (error condition) or has the <code>DesiredLength</code>.
     * <p/>
     * Note: The <code>Source</code> (original) array may be return.
     *
     * @param pDesiredLength of the resulting array (must NOT be < 0)
     * @param pSource        array
     *
     * @return null if the <code>Source</code> is longer then the <code>DesiredLength</code>; otherwise
     *         an Array that is exactly <code>DesiredLength</code> long (padded with nulls).
     */
    public static @Nullable String[] expectArray( int pDesiredLength, @Nullable String[] pSource )
    {
        Integers.assertNonNegative( "DesiredLength", pDesiredLength );
        int zCurrentLength = (pSource == null) ? 0 : pSource.length;
        if ( pDesiredLength < zCurrentLength )
        {
            return null;
        }
        if ( pDesiredLength == zCurrentLength )
        {
            return pSource;
        }
        String[] rv = new String[pDesiredLength];
        if ( zCurrentLength != 0 )
        {
            System.arraycopy( pSource, 0, rv, 0, zCurrentLength );
        }
        return rv;
    }

    /**
     * Return an String Array made up of the end elements of <code>Strings</code>, but who's first element is
     * the <code>FromIndex</code> element of <code>Strings</code>.
     * <p/>
     * Note: It is OK for <code>Strings</code> to be too short (or even null).
     * Note: The <code>Strings</code> (original) array may be return.
     *
     * @param pStrings   array
     * @param pFromIndex is the index into <code>Strings</code> to start the resulting array from (must be >= 0).
     *
     * @return null if
     */
    public static @Nullable String[] everythingFrom( @Nullable String[] pStrings, int pFromIndex )
    {
        Integers.assertNonNegative( "FromIndex", pFromIndex );
        if ( (pStrings == null) || (pStrings.length <= pFromIndex) )
        {
            return EMPTY_ARRAY;
        }
        String[] rv = new String[pStrings.length - pFromIndex];
        System.arraycopy( pStrings, pFromIndex, rv, 0, rv.length );
        return rv;
    }
}

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

Diff revisions: vs.
Revision Author Commited Message
787 GeorgeS picture GeorgeS Mon 30 Jul, 2012 03:00:12 +0000