You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2006/09/12 08:34:45 UTC

svn commit: r442481 - /jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/Find.java

Author: bayard
Date: Mon Sep 11 23:34:44 2006
New Revision: 442481

URL: http://svn.apache.org/viewvc?view=rev&rev=442481
Log:
Refactored the option code to make it easier to add options; and added a few more options

Modified:
    jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/Find.java

Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/Find.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/Find.java?view=diff&rev=442481&r1=442480&r2=442481
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/Find.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/Find.java Mon Sep 11 23:34:44 2006
@@ -23,27 +23,26 @@
 public class Find {
 
     public static void main(String[] args) throws OptionException {
-        DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
-        ArgumentBuilder abuilder = new ArgumentBuilder();
+        new Find().find(args);
+    }
+
+    public void find(String[] args) throws OptionException {
         GroupBuilder gbuilder = new GroupBuilder();
 
-        Option type =
-            obuilder
-                .withShortName("type")
-                .withDescription("True if the file is of the specified type.")
-                .withArgument(
-                    abuilder
-                        .withName("type-flag")
-                        .withMinimum(1)
-                        .withMaximum(1)
-                        .create()
-                )
-                .create();
+        Option type = optionWithArg("type", "True if the file is of the specified type.");
+        Option empty = option("empty", "True if the current file or directory is empty.");
+        Option regex = optionWithArg("regex", "True if the whole path of the file matches pattern using regular expression."); 
+        Option name = optionWithArg("name", "True if the last component of the pathname being examined matches pattern.");
+        Option path = optionWithArg("path", "True if the pathname being examined matches pattern.");
 
         Group options =
             gbuilder
                 .withName("options")
                 .withOption(type)
+                .withOption(empty)
+                .withOption(regex)
+                .withOption(name)
+                .withOption(path)
                 .create();
 
         Parser parser = new Parser();
@@ -53,6 +52,33 @@
         if(cl.hasOption(type)) {
             System.out.println("USE TYPE: " + cl.getValue(type));
         }
+    }
+
+    // Defined outside option(...) for performance
+    private DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+    private ArgumentBuilder abuilder = new ArgumentBuilder();
+    private Option option(String name, String description) {
+        Option type =
+            obuilder
+                .withShortName(name)
+                .withDescription(description)
+                .create();
+        return type;
+    }
+    private Option optionWithArg(String name, String description) {
+        Option type =
+            obuilder
+                .withShortName(name)
+                .withDescription(description)
+                .withArgument(
+                    abuilder
+                        .withName(name + "-flag")
+                        .withMinimum(1)
+                        .withMaximum(1)
+                        .create()
+                )
+                .create();
+        return type;
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org