Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/ScarPlus/src/com/esotericsoftware/scar/support/Arguments.java

Diff revisions: vs.
  @@ -1,135 +1,135 @@
1 - package com.esotericsoftware.scar.support;
2 -
3 - import com.esotericsoftware.scar.*;
4 - import com.esotericsoftware.utils.*;
5 -
6 - import java.util.*;
7 -
8 - /**
9 - * Stores command line arguments as 'String' name/value pairs. Arguments containing an equals sign are considered a name/value pair. All
10 - * other arguments are stored as a name/value pair with a "" value.
11 - */
12 - @SuppressWarnings({"UnusedDeclaration"})
13 - public class Arguments
14 - {
15 - public static class NameValuePair
16 - {
17 - private String mName, mValue;
18 -
19 - public NameValuePair( String pName, String pValue )
20 - {
21 - mName = pName;
22 - mValue = pValue;
23 - }
24 -
25 - public String getName()
26 - {
27 - return mName;
28 - }
29 -
30 - public String getValue()
31 - {
32 - return mValue;
33 - }
34 - }
35 -
36 - private final Map<String, String> mParameters = new LinkedHashMap<String, String>();
37 -
38 - public Arguments()
39 - {
40 - }
41 -
42 - public Arguments( String[] pArgs )
43 - {
44 - for ( String zArg : pArgs )
45 - {
46 - if ( null != (zArg = Utils.noEmpty( zArg )) )
47 - {
48 - int at = zArg.indexOf( '=' );
49 - if ( at == -1 )
50 - {
51 - set( zArg, "" );
52 - }
53 - else
54 - {
55 - set( zArg.substring( 0, at ), zArg.substring( at + 1 ).trim() );
56 - }
57 - }
58 - }
59 - }
60 -
61 - private void set( String pName, String pValue )
62 - {
63 - mParameters.put( normalizeName( pName ), pValue );
64 - }
65 -
66 - /**
67 - * Get (and remove if there) the 'Next' Name/Value.
68 - * <p/>
69 - * Returns null means no more.
70 - */
71 - public NameValuePair getNext()
72 - {
73 - if ( mParameters.isEmpty() )
74 - {
75 - return null;
76 - }
77 - String zName = mParameters.keySet().iterator().next();
78 - return new NameValuePair( zName, get( zName ) );
79 - }
80 -
81 - /**
82 - * Get (and remove if there) the value assocciated w/ pName.
83 - * <p/>
84 - * Returns the value of the argument with the specified Name,
85 - * or "" if the argument was specified without a value,
86 - * or null if it was not specified.
87 - */
88 - public String get( String pName )
89 - {
90 - return mParameters.remove( normalizeName( pName ) );
91 - }
92 -
93 - /**
94 - * Get (and remove if there) the value assocciated w/ pName.
95 - * <p/>
96 - * Returns the value of the argument with the specified Name,
97 - * or "" if the argument was specified without a value,
98 - * or pDefaultValue if it was not specified.
99 - */
100 - public String get( String pName, String pDefaultValue )
101 - {
102 - String zValue = get( pName );
103 - return (zValue != null) ? zValue : pDefaultValue;
104 - }
105 -
106 - public int count()
107 - {
108 - return mParameters.size();
109 - }
110 -
111 - private String normalizeName( String pName )
112 - {
113 - return Util.assertNotEmpty( "Name", pName ).toLowerCase();
114 - }
115 -
116 - public String toString()
117 - {
118 - StringBuilder buffer = new StringBuilder( 100 );
119 - for ( String param : mParameters.keySet() )
120 - {
121 - if ( buffer.length() > 1 )
122 - {
123 - buffer.append( ' ' );
124 - }
125 - buffer.append( param );
126 - String value = get( param );
127 - if ( "".equals( value ) )
128 - {
129 - buffer.append( '=' );
130 - buffer.append( value );
131 - }
132 - }
133 - return buffer.toString();
134 - }
135 - }
1 + package com.esotericsoftware.scar.support;
2 +
3 + import com.esotericsoftware.scar.*;
4 + import com.esotericsoftware.utils.*;
5 +
6 + import java.util.*;
7 +
8 + /**
9 + * Stores command line arguments as 'String' name/value pairs. Arguments containing an equals sign are considered a name/value pair. All
10 + * other arguments are stored as a name/value pair with a "" value.
11 + */
12 + @SuppressWarnings({"UnusedDeclaration"})
13 + public class Arguments
14 + {
15 + public static class NameValuePair
16 + {
17 + private String mName, mValue;
18 +
19 + public NameValuePair( String pName, String pValue )
20 + {
21 + mName = pName;
22 + mValue = pValue;
23 + }
24 +
25 + public String getName()
26 + {
27 + return mName;
28 + }
29 +
30 + public String getValue()
31 + {
32 + return mValue;
33 + }
34 + }
35 +
36 + private final Map<String, String> mParameters = new LinkedHashMap<String, String>();
37 +
38 + public Arguments()
39 + {
40 + }
41 +
42 + public Arguments( String[] pArgs )
43 + {
44 + for ( String zArg : pArgs )
45 + {
46 + if ( null != (zArg = Utils.noEmpty( zArg )) )
47 + {
48 + int at = zArg.indexOf( '=' );
49 + if ( at == -1 )
50 + {
51 + set( zArg, "" );
52 + }
53 + else
54 + {
55 + set( zArg.substring( 0, at ), zArg.substring( at + 1 ).trim() );
56 + }
57 + }
58 + }
59 + }
60 +
61 + private void set( String pName, String pValue )
62 + {
63 + mParameters.put( normalizeName( pName ), pValue );
64 + }
65 +
66 + /**
67 + * Get (and remove if there) the 'Next' Name/Value.
68 + * <p/>
69 + * Returns null means no more.
70 + */
71 + public NameValuePair getNext()
72 + {
73 + if ( mParameters.isEmpty() )
74 + {
75 + return null;
76 + }
77 + String zName = mParameters.keySet().iterator().next();
78 + return new NameValuePair( zName, get( zName ) );
79 + }
80 +
81 + /**
82 + * Get (and remove if there) the value assocciated w/ pName.
83 + * <p/>
84 + * Returns the value of the argument with the specified Name,
85 + * or "" if the argument was specified without a value,
86 + * or null if it was not specified.
87 + */
88 + public String get( String pName )
89 + {
90 + return mParameters.remove( normalizeName( pName ) );
91 + }
92 +
93 + /**
94 + * Get (and remove if there) the value assocciated w/ pName.
95 + * <p/>
96 + * Returns the value of the argument with the specified Name,
97 + * or "" if the argument was specified without a value,
98 + * or pDefaultValue if it was not specified.
99 + */
100 + public String get( String pName, String pDefaultValue )
101 + {
102 + String zValue = get( pName );
103 + return (zValue != null) ? zValue : pDefaultValue;
104 + }
105 +
106 + public int count()
107 + {
108 + return mParameters.size();
109 + }
110 +
111 + private String normalizeName( String pName )
112 + {
113 + return Util.assertNotEmpty( "Name", pName ).toLowerCase();
114 + }
115 +
116 + public String toString()
117 + {
118 + StringBuilder buffer = new StringBuilder( 100 );
119 + for ( String param : mParameters.keySet() )
120 + {
121 + if ( buffer.length() > 1 )
122 + {
123 + buffer.append( ' ' );
124 + }
125 + buffer.append( param );
126 + String value = get( param );
127 + if ( "".equals( value ) )
128 + {
129 + buffer.append( '=' );
130 + buffer.append( value );
131 + }
132 + }
133 + return buffer.toString();
134 + }
135 + }