commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r661699 - in /commons/proper/cli/branches/cli-1.x/src: java/org/apache/commons/cli/Options.java test/org/apache/commons/cli/OptionsTest.java
Date Fri, 30 May 2008 12:57:46 GMT
Author: ebourg
Date: Fri May 30 05:57:45 2008
New Revision: 661699

URL: http://svn.apache.org/viewvc?rev=661699&view=rev
Log:
Simplified Options.helpOptions(), the loop looking into the lonOpts wasn't necessary since
all options are already in shortOpts
Minor style & doc improvements

Modified:
    commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Options.java
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionsTest.java

Modified: commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Options.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Options.java?rev=661699&r1=661698&r2=661699&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Options.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Options.java Fri May
30 05:57:45 2008
@@ -14,6 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.commons.cli;
 
 import java.io.Serializable;
@@ -98,10 +99,12 @@
     
     /**
      * Lists the OptionGroups that are members of this Options instance.
+     * 
      * @return a Collection of OptionGroup instances.
      */
-    Collection getOptionGroups(){
-    	return new HashSet(optionGroups.values());
+    Collection getOptionGroups()
+    {
+        return new HashSet(optionGroups.values());
     }
 
     /** 
@@ -185,30 +188,13 @@
      */
     List helpOptions()
     {
-        List opts = new ArrayList(shortOpts.values());
-
-        // now look through the long opts to see if there are any Long-opt
-        // only options
-        Iterator iter = longOpts.values().iterator();
-
-        while (iter.hasNext())
-        {
-            Object item = iter.next();
-
-            if (!opts.contains(item))
-            {
-                opts.add(item);
-            }
-        }
-
-        return new ArrayList(opts);
+        return new ArrayList(shortOpts.values());
     }
 
     /** 
-     * Returns the required options as a
-     * <code>java.util.Collection</code>.
+     * Returns the required options.
      *
-     * @return Collection of required options
+     * @return List of required options
      */
     public List getRequiredOptions()
     {
@@ -216,7 +202,8 @@
     }
 
     /** 
-     * Retrieve the named {@link Option}
+     * Retrieve the {@link Option} matching the long or short name specified.
+     * The leading hyphens in the name are ignored (up to 2).
      *
      * @param opt short or long name of the {@link Option}
      * @return the option represented by opt
@@ -278,4 +265,4 @@
 
         return buf.toString();
     }
-}
\ No newline at end of file
+}

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionsTest.java?rev=661699&r1=661698&r2=661699&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionsTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/OptionsTest.java Fri
May 30 05:57:45 2008
@@ -30,27 +30,12 @@
 {
     public void testHelpOptions(){
         
-        Option longOnly1 = OptionBuilder
-            .withLongOpt("long-only1")
-            .create();
-        
-        Option longOnly2 = OptionBuilder
-            .withLongOpt("long-only2")
-            .create();
-                
-        Option shortOnly1 = OptionBuilder
-            .create("1");
-                
-        Option shortOnly2 = OptionBuilder
-            .create("2");
-                
-        Option bothA = OptionBuilder
-            .withLongOpt("bothA")
-            .create("a");
-                
-        Option bothB = OptionBuilder
-            .withLongOpt("bothB")
-            .create("b");
+        Option longOnly1 = OptionBuilder.withLongOpt("long-only1").create();
+        Option longOnly2 = OptionBuilder.withLongOpt("long-only2").create();
+        Option shortOnly1 = OptionBuilder.create("1");
+        Option shortOnly2 = OptionBuilder.create("2");
+        Option bothA = OptionBuilder.withLongOpt("bothA").create("a");
+        Option bothB = OptionBuilder.withLongOpt("bothB").create("b");
         
         Options options = new Options();
         options.addOption(longOnly1);
@@ -70,8 +55,8 @@
         
         Collection helpOptions = options.helpOptions();
         
-        assertTrue("Everything in all should be in help",helpOptions.containsAll(allOptions));
-        assertTrue("Everything in help should be in all",allOptions.containsAll(helpOptions));
       
+        assertTrue("Everything in all should be in help", helpOptions.containsAll(allOptions));
+        assertTrue("Everything in help should be in all", allOptions.containsAll(helpOptions));
       
     }
 
     public void testMissingOptionException() throws ParseException {



Mime
View raw message