[Japi-cvs] SF.net SVN: japi: [359] tools/findLongestPath/trunk/src/net/sf/japi/ findLongestPath/Fi
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2007-06-07 19:40:05
|
Revision: 359
http://svn.sourceforge.net/japi/?rev=359&view=rev
Author: christianhujer
Date: 2007-06-07 12:40:04 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
Added main class.
Added Paths:
-----------
tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java
Added: tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java
===================================================================
--- tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java (rev 0)
+++ tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java 2007-06-07 19:40:04 UTC (rev 359)
@@ -0,0 +1,95 @@
+/*
+ * FindLongestPath recursively finds the longest pathname in directories.
+ * Copyright (C) 2007 Christian Hujer
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package net.sf.japi.findLongestPath;
+
+import net.sf.japi.io.args.BasicCommand;
+import net.sf.japi.io.args.ArgParser;
+import net.sf.japi.io.args.Option;
+import org.jetbrains.annotations.NotNull;
+import java.util.List;
+import java.io.File;
+
+/** Program that finds the longest path name.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class FindLongestPath extends BasicCommand {
+
+ /** Runs the program.
+ * @param args Command line arguments.
+ */
+ public static void main(final String... args) {
+ ArgParser.simpleParseAndRun(new FindLongestPath(), args);
+ }
+
+ private String maxPathname;
+
+ private int maxLength;
+
+ private boolean absolute;
+
+ public FindLongestPath() {
+ reset();
+ }
+
+ public void reset() {
+ maxPathname = "";
+ maxLength = 0;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings({"InstanceMethodNamingConvention"})
+ public int run(@NotNull List<String> args) throws Exception {
+ if (args.size() == 0) {
+ find(".");
+ System.out.println(this);
+ } else {
+ for (final String arg : args) {
+ find(arg);
+ System.out.println(this);
+ reset();
+ }
+ }
+ return 0;
+ }
+
+ @Option({"a", "absolute"})
+ public void setAbsolute(final boolean absolute) {
+ this.absolute = absolute;
+ }
+
+ private void find(final String pathname) {
+ find(new File(pathname));
+ }
+
+ private void find(final File path) {
+ final String pathname = absolute ? path.getAbsolutePath() : path.getPath();
+ final int length = pathname.length();
+ if (length > maxLength) {
+ maxLength = length;
+ maxPathname = pathname;
+ }
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return maxPathname + ":" + maxLength;
+ }
+
+} // class FindLongestPath
Property changes on: tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|