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

import java.util.*;

public class Lists
{
    public static <T> ArrayList<T> newArrayList()
    {
        return new ArrayList<T>();
    }

    public static <T> List<T> empty()
    {
        return Collections.emptyList();
    }

    public static <T> List<T> deNull( List<T> pToCheck )
    {
        if ( pToCheck == null )
        {
            pToCheck = empty();
        }
        return pToCheck;
    }

    public static <T> List<T> deNullMutable( List<T> pToCheck )
    {
        if ( pToCheck == null )
        {
            pToCheck = newArrayList();
        }
        return pToCheck;
    }

    public static <T> List<T> deNullUnmodifiable( List<T> pToCheck )
    {
        if ( pToCheck == null )
        {
            return empty();
        }
        return Collections.unmodifiableList( pToCheck );
    }

    public static boolean isNullOrEmpty( List<?> pToCheck )
    {
        return (pToCheck == null || pToCheck.isEmpty());
    }

    public static boolean isNotNullOrEmpty( List<?> pToCheck )
    {
        return (pToCheck != null && !pToCheck.isEmpty());
    }

    public static void assertNotNullNotEmpty( String pErrorMessage, List<?> pToAssert )
            throws IllegalArgumentException
    {
        if ( isNullOrEmpty( pToAssert ) )
        {
            Strings.errorNullOrEmpty( pErrorMessage, "Collection" );
        }
    }

    public static <T> List<T> of( T pEntry )
    {
        ArrayList<T> rv = newArrayList();
        rv.add( pEntry );
        return rv;
    }

    public static <T> List<T> from( Collection<T> pCollection )
    {
        ArrayList<T> rv = newArrayList();
        if ( pCollection != null )
        {
            rv.addAll( pCollection );
        }
        return rv;
    }

    public static <T> List<T> from( Enumeration<T> pEnumeration )
    {
        ArrayList<T> rv = newArrayList();
        while ( pEnumeration.hasMoreElements() )
        {
            rv.add( pEnumeration.nextElement() );
        }
        return rv;
    }

    public static <T> List<T> ofUnmodifiable( T pEntry )
    {
        return deNullUnmodifiable( of( pEntry ) );
    }

    public static <T> List<T> fromUnmodifiable( Collection<T> pCollection )
    {
        return deNullUnmodifiable( from( pCollection ) );
    }

    public static <T> List<T> fromUnmodifiable( Enumeration<T> pEnumeration )
    {
        return deNullUnmodifiable( from( pEnumeration ) );
    }

    public static String singleQuoteToString( List<String> pStrings )
    {
        StringBuilder sb = new StringBuilder();
        if ( pStrings != null )
        {
            char prefix = '[';
            if ( pStrings.size() == 0 )
            {
                sb.append( prefix );
            }
            else
            {
                for ( String zString : pStrings )
                {
                    sb.append( prefix );
                    sb.append( '\'' );
                    sb.append( zString );
                    sb.append( '\'' );
                    prefix = ',';
                }
            }
            sb.append( ']' );
        }
        return sb.toString();
    }
}

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

Diff revisions: vs.
Revision Author Commited Message
849 Diff Diff GeorgeS picture GeorgeS Tue 11 Sep, 2012 17:11:59 +0000

Clean up serialization

846 Diff Diff GeorgeS picture GeorgeS Thu 06 Sep, 2012 19:47:32 +0000
836 Diff Diff GeorgeS picture GeorgeS Wed 05 Sep, 2012 15:01:18 +0000
821 Diff Diff GeorgeS picture GeorgeS Sun 19 Aug, 2012 00:08:41 +0000
809 Diff Diff GeorgeS picture GeorgeS Thu 16 Aug, 2012 04:10:46 +0000
806 GeorgeS picture GeorgeS Thu 16 Aug, 2012 03:48:22 +0000