Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -1,135 +1,112 @@
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 + public static class NameValuePair {
15 + private String mName, mValue;
16 +
17 + public NameValuePair( String pName, String pValue ) {
18 + mName = pName;
19 + mValue = pValue;
20 + }
21 +
22 + public String getName() {
23 + return mName;
24 + }
25 +
26 + public String getValue() {
27 + return mValue;
28 + }
29 + }
30 +
31 + private final Map<String, String> mParameters = new LinkedHashMap<String, String>();
32 +
33 + public Arguments() {
34 + }
35 +
36 + public Arguments( String[] pArgs ) {
37 + for ( String zArg : pArgs ) {
38 + if ( null != (zArg = Utils.noEmpty( zArg )) ) {
39 + int at = zArg.indexOf( '=' );
40 + if ( at == -1 ) {
41 + set( zArg, "" );
42 + } else {
43 + set( zArg.substring( 0, at ), zArg.substring( at + 1 ).trim() );
44 + }
45 + }
46 + }
47 + }
48 +
49 + private void set( String pName, String pValue ) {
50 + mParameters.put( normalizeName( pName ), pValue );
51 + }
52 +
53 + /**
54 + * Get (and remove if there) the 'Next' Name/Value.
55 + * <p/>
56 + * Returns null means no more.
57 + */
58 + public NameValuePair getNext() {
59 + if ( mParameters.isEmpty() ) {
60 + return null;
61 + }
62 + String zName = mParameters.keySet().iterator().next();
63 + return new NameValuePair( zName, get( zName ) );
64 + }
65 +
66 + /**
67 + * Get (and remove if there) the value assocciated w/ pName.
68 + * <p/>
69 + * Returns the value of the argument with the specified Name,
70 + * or "" if the argument was specified without a value,
71 + * or null if it was not specified.
72 + */
73 + public String get( String pName ) {
74 + return mParameters.remove( normalizeName( pName ) );
75 + }
76 +
77 + /**
78 + * Get (and remove if there) the value assocciated w/ pName.
79 + * <p/>
80 + * Returns the value of the argument with the specified Name,
81 + * or "" if the argument was specified without a value,
82 + * or pDefaultValue if it was not specified.
83 + */
84 + public String get( String pName, String pDefaultValue ) {
85 + String zValue = get( pName );
86 + return (zValue != null) ? zValue : pDefaultValue;
87 + }
88 +
89 + public int count() {
90 + return mParameters.size();
91 + }
92 +
93 + private String normalizeName( String pName ) {
94 + return Util.assertNotEmpty( "Name", pName ).toLowerCase();
95 + }
96 +
97 + public String toString() {
98 + StringBuilder buffer = new StringBuilder( 100 );
99 + for ( String param : mParameters.keySet() ) {
100 + if ( buffer.length() > 1 ) {
101 + buffer.append( ' ' );
102 + }
103 + buffer.append( param );
104 + String value = get( param );
105 + if ( "".equals( value ) ) {
106 + buffer.append( '=' );
107 + buffer.append( value );
108 + }
109 + }
110 + return buffer.toString();
111 + }
112 + }