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
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.esotericsoftware.utils;

import org.litesoft.logger.*;

@SuppressWarnings({"UnusedDeclaration"})
public class Util
{
    public static LineSink PROGRESS_LINE_SINK = LineSink.SYSTEM_OUT;

    public static void progress( String pMessage )
    {
        PROGRESS_LINE_SINK.addLine( pMessage );
    }

    /**
     * True if running on a Mac OS.
     */
    public static final boolean isMac = System.getProperty( "os.name" ).toLowerCase().contains( "mac os x" );

    /**
     * True if running on a Windows OS.
     */
    public static final boolean isWindows = System.getProperty( "os.name" ).toLowerCase().contains( "windows" );

    public static final String[] EMPTY_STRING_ARRAY = new String[0];

    public static final Logger LOGGER = LoggerFactory.getLogger( Util.class );

    public static String noEmpty( String pToTest )
    {
        if ( pToTest != null )
        {
            if ( (pToTest = pToTest.trim()).length() != 0 )
            {
                return pToTest;
            }
        }
        return null;
    }

    public static <T> T deNull( T pToTest, T pDefaultValue )
    {
        return (pToTest != null) ? pToTest : pDefaultValue;
    }

    public static <T> T assertNotNull( String pWhat, T pToTest )
    {
        if ( pToTest == null )
        {
            throw new IllegalArgumentException( pWhat + " cannot be null." );
        }
        return pToTest;
    }

    public static String assertNotEmpty( String pWhat, String pToTest )
    {
        if ( (pToTest = assertNotNull( pWhat, pToTest ).trim()).length() == 0 )
        {
            throw new IllegalArgumentException( pWhat + " cannot be empty/blank." );
        }
        return pToTest;
    }

    public static void assertNotEmpty( String pWhat, String[] pToTest )
    {
        assertNotNull( pWhat, pToTest );
        if ( pToTest.length == 0 )
        {
            throw new IllegalArgumentException( pWhat + " cannot be empty." );
        }
    }

    public static int assertNotNegative( String pWhat, int pInt )
    {
        if ( pInt < 0 )
        {
            throw new IllegalArgumentException( pWhat + " was " + pInt + ", cannot be negative." );
        }
        return pInt;
    }

    public static void assertPairedEntries( String pWhat, Object[] pArray )
    {
        if ( (pArray != null) && ((pArray.length & 1) == 1) ) // Odd Length == Not Paired!
        {
            throw new IllegalArgumentException( pWhat + " had '" + pArray.length + "' entries, should have been either '" + (pArray.length - 1) + "' or '" + (pArray.length + 1) + "'" );
        }
    }

    public static String replace( String pSource, String pOfInterest, String pReplaceWith )
    {
        for ( int at; -1 != (at = pSource.indexOf( pOfInterest )); )
        {
            pSource = pSource.substring( 0, at ) + pReplaceWith + pSource.substring( at + pOfInterest.length() );
        }
        return pSource;
    }

    public static String toString( Object o )
    {
        return (o != null) ? o.toString() : null;
    }
}

Commits for litesoft/trunk/Java/ScarPlus/src/com/esotericsoftware/utils/Util.java

Diff revisions: vs.
Revision Author Commited Message
315 Diff Diff GeorgeS picture GeorgeS Sun 17 Jul, 2011 15:48:36 +0000
314 Diff Diff GeorgeS picture GeorgeS Fri 15 Jul, 2011 01:01:49 +0000
308 Diff Diff GeorgeS picture GeorgeS Sun 10 Jul, 2011 23:55:06 +0000
307 Diff Diff GeorgeS picture GeorgeS Sun 10 Jul, 2011 01:43:51 +0000
306 Diff Diff GeorgeS picture GeorgeS Sat 09 Jul, 2011 00:00:17 +0000
303 Diff Diff GeorgeS picture GeorgeS Fri 08 Jul, 2011 15:17:00 +0000
302 Diff Diff GeorgeS picture GeorgeS Fri 08 Jul, 2011 14:08:10 +0000
301 Diff Diff GeorgeS picture GeorgeS Fri 08 Jul, 2011 00:02:58 +0000
300 Diff Diff GeorgeS picture GeorgeS Thu 07 Jul, 2011 00:30:55 +0000
299 GeorgeS picture GeorgeS Tue 05 Jul, 2011 04:45:50 +0000