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
package com.esotericsoftware.scar.support;

import com.esotericsoftware.scar.*;
import com.esotericsoftware.utils.*;

import java.util.*;

/**
 * Stores command line arguments as 'String' name/value pairs. Arguments containing an equals sign are considered a name/value pair. All
 * other arguments are stored as a name/value pair with a "" value.
 */
@SuppressWarnings({"UnusedDeclaration"})
public class Arguments {
    public static class NameValuePair {
        private String mName, mValue;

        public NameValuePair( String pName, String pValue ) {
            mName = pName;
            mValue = pValue;
        }

        public String getName() {
            return mName;
        }

        public String getValue() {
            return mValue;
        }
    }

    private final Map<String, String> mParameters = new LinkedHashMap<String, String>();

    public Arguments() {
    }

    public Arguments( String[] pArgs ) {
        for ( String zArg : pArgs ) {
            if ( null != (zArg = Utils.noEmpty( zArg )) ) {
                int at = zArg.indexOf( '=' );
                if ( at == -1 ) {
                    set( zArg, "" );
                } else {
                    set( zArg.substring( 0, at ), zArg.substring( at + 1 ).trim() );
                }
            }
        }
    }

    private void set( String pName, String pValue ) {
        mParameters.put( normalizeName( pName ), pValue );
    }

    /**
     * Get (and remove if there) the 'Next' Name/Value.
     * <p/>
     * Returns null means no more.
     */
    public NameValuePair getNext() {
        if ( mParameters.isEmpty() ) {
            return null;
        }
        String zName = mParameters.keySet().iterator().next();
        return new NameValuePair( zName, get( zName ) );
    }

    /**
     * Get (and remove if there) the value assocciated w/ pName.
     * <p/>
     * Returns the value of the argument with the specified Name,
     * or "" if the argument was specified without a value,
     * or null if it was not specified.
     */
    public String get( String pName ) {
        return mParameters.remove( normalizeName( pName ) );
    }

    /**
     * Get (and remove if there) the value assocciated w/ pName.
     * <p/>
     * Returns the value of the argument with the specified Name,
     * or "" if the argument was specified without a value,
     * or pDefaultValue if it was not specified.
     */
    public String get( String pName, String pDefaultValue ) {
        String zValue = get( pName );
        return (zValue != null) ? zValue : pDefaultValue;
    }

    public int count() {
        return mParameters.size();
    }

    private String normalizeName( String pName ) {
        return Util.assertNotEmpty( "Name", pName ).toLowerCase();
    }

    public String toString() {
        StringBuilder buffer = new StringBuilder( 100 );
        for ( String param : mParameters.keySet() ) {
            if ( buffer.length() > 1 ) {
                buffer.append( ' ' );
            }
            buffer.append( param );
            String value = get( param );
            if ( "".equals( value ) ) {
                buffer.append( '=' );
                buffer.append( value );
            }
        }
        return buffer.toString();
    }
}

Commits for litesoft/trunk/Java/ScarPlus/src/com/esotericsoftware/scar/support/Arguments.java

Diff revisions: vs.
Revision Author Commited Message
959 Diff Diff GeorgeS picture GeorgeS Sat 19 Jul, 2014 15:27:50 +0000

Scar update

950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

943 Diff Diff GeorgeS picture GeorgeS Tue 03 Jun, 2014 04:25:50 +0000

Extracting commonfoundation

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

422 Diff Diff GeorgeS picture GeorgeS Sat 20 Aug, 2011 17:30:50 +0000
291 Diff Diff GeorgeS picture GeorgeS Wed 22 Jun, 2011 00:33:37 +0000
290 Diff Diff GeorgeS picture GeorgeS Tue 21 Jun, 2011 14:58:27 +0000
289 Diff Diff GeorgeS picture GeorgeS Tue 21 Jun, 2011 00:43:29 +0000
287 GeorgeS picture GeorgeS Mon 20 Jun, 2011 06:24:24 +0000