commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r1403792 - in /commons/proper/cli/trunk/src/main/java/org/apache/commons/cli: GnuParser.java HelpFormatter.java Parser.java PosixParser.java TypeHandler.java
Date Tue, 30 Oct 2012 17:24:20 GMT
Author: ebourg
Date: Tue Oct 30 17:24:20 2012
New Revision: 1403792

URL: http://svn.apache.org/viewvc?rev=1403792&view=rev
Log:
Minor syntax changes

Modified:
    commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/GnuParser.java
    commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/HelpFormatter.java
    commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/Parser.java
    commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/PosixParser.java
    commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/TypeHandler.java

Modified: commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/GnuParser.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/GnuParser.java?rev=1403792&r1=1403791&r2=1403792&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/GnuParser.java (original)
+++ commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/GnuParser.java Tue Oct 30
17:24:20 2012
@@ -49,7 +49,7 @@ public class GnuParser extends Parser
      */
     protected String[] flatten(Options options, String[] arguments, boolean stopAtNonOption)
     {
-        List tokens = new ArrayList();
+        List<String> tokens = new ArrayList<String>();
 
         boolean eatTheRest = false;
 
@@ -109,6 +109,6 @@ public class GnuParser extends Parser
             }
         }
 
-        return (String[]) tokens.toArray(new String[tokens.size()]);
+        return tokens.toArray(new String[tokens.size()]);
     }
 }

Modified: commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/HelpFormatter.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/HelpFormatter.java?rev=1403792&r1=1403791&r2=1403792&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/HelpFormatter.java (original)
+++ commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/HelpFormatter.java Tue Oct
30 17:24:20 2012
@@ -577,10 +577,10 @@ public class HelpFormatter
             Collections.sort(optList, getOptionComparator());
         }
         // iterate over the options
-        for (Iterator i = optList.iterator(); i.hasNext();)
+        for (Iterator<Option> it = optList.iterator(); it.hasNext();)
         {
             // get the next Option
-            Option option = (Option) i.next();
+            Option option = it.next();
 
             // check if the option is part of an OptionGroup
             OptionGroup group = options.getOptionGroup(option);
@@ -609,7 +609,7 @@ public class HelpFormatter
                 appendOption(buff, option, option.isRequired());
             }
 
-            if (i.hasNext())
+            if (it.hasNext())
             {
                 buff.append(" ");
             }
@@ -641,12 +641,12 @@ public class HelpFormatter
             Collections.sort(optList, getOptionComparator());
         }
         // for each option in the OptionGroup
-        for (Iterator i = optList.iterator(); i.hasNext();)
+        for (Iterator<Option> it = optList.iterator(); it.hasNext();)
         {
             // whether the option is required or not is handled at group level
-            appendOption(buff, (Option) i.next(), true);
+            appendOption(buff, it.next(), true);
 
-            if (i.hasNext())
+            if (it.hasNext())
             {
                 buff.append(" | ");
             }
@@ -833,9 +833,9 @@ public class HelpFormatter
 
         int x = 0;
 
-        for (Iterator i = optList.iterator(); i.hasNext();)
+        for (Iterator<Option> it = optList.iterator(); it.hasNext();)
         {
-            Option option = (Option) i.next();
+            Option option = it.next();
             StringBuilder optBuf = new StringBuilder(prefixList.get(x++).toString());
 
             if (optBuf.length() < max)
@@ -854,7 +854,7 @@ public class HelpFormatter
 
             renderWrappedText(sb, width, nextLineTabStop, optBuf.toString());
 
-            if (i.hasNext())
+            if (it.hasNext())
             {
                 sb.append(getNewLine());
             }

Modified: commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/Parser.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/Parser.java?rev=1403792&r1=1403791&r2=1403792&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/Parser.java (original)
+++ commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/Parser.java Tue Oct 30 17:24:20
2012
@@ -20,7 +20,6 @@ package org.apache.commons.cli;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Enumeration;
-import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Properties;
@@ -140,20 +139,15 @@ public abstract class Parser implements 
      *
      * @since 1.1
      */
-    public CommandLine parse(Options options, String[] arguments, Properties properties,
boolean stopAtNonOption)
-            throws ParseException
+    public CommandLine parse(Options options, String[] arguments, Properties properties,
boolean stopAtNonOption) throws ParseException
     {
         // clear out the data in options in case it's been used before (CLI-71)
-        for (Iterator it = options.helpOptions().iterator(); it.hasNext();)
-        {
-            Option opt = (Option) it.next();
+        for (Option opt : options.helpOptions()) {
             opt.clearValues();
         }
         
         // clear the data from the groups
-        for (Iterator it = options.getOptionGroups().iterator(); it.hasNext();)
-        {
-            OptionGroup group = (OptionGroup) it.next();
+        for (OptionGroup group : options.getOptionGroups()) {
             group.setSelected(null);
         }        
 
@@ -169,14 +163,14 @@ public abstract class Parser implements 
             arguments = new String[0];
         }
 
-        List tokenList = Arrays.asList(flatten(getOptions(), arguments, stopAtNonOption));
+        List<String> tokenList = Arrays.asList(flatten(getOptions(), arguments, stopAtNonOption));
 
-        ListIterator iterator = tokenList.listIterator();
+        ListIterator<String> iterator = tokenList.listIterator();
 
         // process each flattened token
         while (iterator.hasNext())
         {
-            String t = (String) iterator.next();
+            String t = iterator.next();
 
             // the value is the double-dash
             if ("--".equals(t))
@@ -227,7 +221,7 @@ public abstract class Parser implements 
             {
                 while (iterator.hasNext())
                 {
-                    String str = (String) iterator.next();
+                    String str = iterator.next();
 
                     // ensure only one double-dash is added
                     if (!"--".equals(str))
@@ -308,8 +302,7 @@ public abstract class Parser implements 
      * Throws a {@link MissingOptionException} if all of the required options
      * are not present.
      *
-     * @throws MissingOptionException if any of the required Options
-     * are not present.
+     * @throws MissingOptionException if any of the required Options are not present.
      */
     protected void checkRequiredOptions() throws MissingOptionException
     {
@@ -321,24 +314,23 @@ public abstract class Parser implements 
     }
 
     /**
-     * <p>Process the argument values for the specified Option
+     * Process the argument values for the specified Option
      * <code>opt</code> using the values retrieved from the
      * specified iterator <code>iter</code>.
      *
      * @param opt The current Option
-     * @param iter The iterator over the flattened command line
-     * Options.
+     * @param iter The iterator over the flattened command line Options.
      *
      * @throws ParseException if an argument value is required
      * and it is has not been found.
      */
-    public void processArgs(Option opt, ListIterator iter) throws ParseException
+    public void processArgs(Option opt, ListIterator<String> iter) throws ParseException
     {
         // loop until an option is found
         while (iter.hasNext())
         {
-            String str = (String) iter.next();
-
+            String str = iter.next();
+            
             // found an Option, not an argument
             if (getOptions().hasOption(str) && str.startsWith("-"))
             {
@@ -373,7 +365,7 @@ public abstract class Parser implements 
      *
      * @throws ParseException if <code>arg</code> does not represent an Option
      */
-    protected void processOption(String arg, ListIterator iter) throws ParseException
+    protected void processOption(String arg, ListIterator<String> iter) throws ParseException
     {
         boolean hasOption = getOptions().hasOption(arg);
 
@@ -384,7 +376,7 @@ public abstract class Parser implements 
         }
 
         // get the option represented by arg
-        Option opt = (Option) getOptions().getOption(arg).clone();
+        Option opt = getOptions().getOption(arg).clone();
         
         // update the required options and groups
         updateRequiredOptions(opt);

Modified: commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/PosixParser.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/PosixParser.java?rev=1403792&r1=1403791&r2=1403792&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/PosixParser.java (original)
+++ commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/PosixParser.java Tue Oct
30 17:24:20 2012
@@ -33,7 +33,7 @@ import java.util.List;
 public class PosixParser extends Parser
 {
     /** holder for flattened tokens */
-    private List tokens = new ArrayList();
+    private List<String> tokens = new ArrayList<String>();
 
     /** specifies if bursting should continue */
     private boolean eatTheRest;
@@ -99,13 +99,13 @@ public class PosixParser extends Parser
         this.options = options;
 
         // an iterator for the command line tokens
-        Iterator iter = Arrays.asList(arguments).iterator();
+        Iterator<String> iter = Arrays.asList(arguments).iterator();
 
         // process each command line token
         while (iter.hasNext())
         {
             // get the next command line token
-            String token = (String) iter.next();
+            String token = iter.next();
 
             // single or double hyphen
             if ("-".equals(token) || "--".equals(token))
@@ -119,7 +119,7 @@ public class PosixParser extends Parser
                 int pos = token.indexOf('=');
                 String opt = pos == -1 ? token : token.substring(0, pos); // --foo
                 
-                List matchingOpts = options.getMatchingOptions(opt);
+                List<String> matchingOpts = options.getMatchingOptions(opt);
 
                 if (matchingOpts.isEmpty())
                 {
@@ -131,7 +131,7 @@ public class PosixParser extends Parser
                 }
                 else
                 {
-                    currentOption = options.getOption((String) matchingOpts.get(0));
+                    currentOption = options.getOption(matchingOpts.get(0));
                     
                     tokens.add("--" + currentOption.getLongOpt());
                     if (pos != -1)
@@ -149,14 +149,14 @@ public class PosixParser extends Parser
                 }
                 else if (!options.getMatchingOptions(token).isEmpty())
                 {
-                    List matchingOpts = options.getMatchingOptions(token);
+                    List<String> matchingOpts = options.getMatchingOptions(token);
                     if (matchingOpts.size() > 1)
                     {
                         throw new AmbiguousOptionException(token, matchingOpts);
                     }
                     else
                     {
-                        Option opt = options.getOption((String) matchingOpts.get(0));
+                        Option opt = options.getOption(matchingOpts.get(0));
                         processOptionToken("-" + opt.getLongOpt(), stopAtNonOption);
                     }
                 }
@@ -174,7 +174,7 @@ public class PosixParser extends Parser
             gobble(iter);
         }
 
-        return (String[]) tokens.toArray(new String[tokens.size()]);
+        return tokens.toArray(new String[tokens.size()]);
     }
 
     /**
@@ -182,7 +182,7 @@ public class PosixParser extends Parser
      *
      * @param iter An iterator over the remaining tokens
      */
-    private void gobble(Iterator iter)
+    private void gobble(Iterator<String> iter)
     {
         if (eatTheRest)
         {

Modified: commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/TypeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/TypeHandler.java?rev=1403792&r1=1403791&r2=1403792&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/TypeHandler.java (original)
+++ commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/TypeHandler.java Tue Oct
30 17:24:20 2012
@@ -110,7 +110,7 @@ public class TypeHandler
       */
     public static Object createObject(String classname) throws ParseException
     {
-        Class cl = null;
+        Class cl;
 
         try
         {
@@ -120,19 +120,15 @@ public class TypeHandler
         {
             throw new ParseException("Unable to find the class: " + classname);
         }
-
-        Object instance = null;
-
+        
         try
         {
-            instance = cl.newInstance();
+            return cl.newInstance();
         }
         catch (Exception e)
         {
             throw new ParseException(e.getClass().getName() + "; Unable to create an instance
of: " + classname);
         }
-
-        return instance;
     }
 
     /**



Mime
View raw message