Subversion Repository Public Repository

litesoft

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

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