Thread: [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.
|
|
From: <chr...@us...> - 2007-06-30 11:52:01
|
Revision: 473
http://svn.sourceforge.net/japi/?rev=473&view=rev
Author: christianhujer
Date: 2007-06-30 04:52:00 -0700 (Sat, 30 Jun 2007)
Log Message:
-----------
Added missing @Nullable / @NotNull annotations.
Added missing Javadoc comments.
Added missing @Override annotation.
Added missing final modifier.
Modified Paths:
--------------
tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java
Modified: tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java
===================================================================
--- tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java 2007-06-30 11:46:40 UTC (rev 472)
+++ tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java 2007-06-30 11:52:00 UTC (rev 473)
@@ -38,16 +38,24 @@
ArgParser.simpleParseAndRun(new FindLongestPath(), args);
}
- private String maxPathname;
+ /** The longest path name found so far. */
+ @NotNull private String maxPathname;
+ /** The length of the longest path name found so far. */
private int maxLength;
+ /** Whether to operate with absolute paths.
+ * <code>true</code> means paths are converted to absolute paths, even if they are relative.
+ * <code>false</code> means paths stay relative if they are relative.
+ */
private boolean absolute;
+ /** Create a FindLongestPath. */
public FindLongestPath() {
reset();
}
+ /** Reset this FindLongestPath to its initial state. */
public void reset() {
maxPathname = "";
maxLength = 0;
@@ -55,7 +63,7 @@
/** {@inheritDoc} */
@SuppressWarnings({"InstanceMethodNamingConvention"})
- public int run(@NotNull List<String> args) throws Exception {
+ public int run(@NotNull final List<String> args) throws Exception {
if (args.size() == 0) {
find(".");
System.out.println(this);
@@ -69,16 +77,25 @@
return 0;
}
+ /** Sets whether to operate with absolute paths.
+ * @param absolute Whether to operate with absolute paths, <code>true</code> to convert paths to absolute paths, <code>false</code> to not perform any conversion.
+ */
@Option({"a", "absolute"})
public void setAbsolute(final boolean absolute) {
this.absolute = absolute;
}
- private void find(final String pathname) {
+ /** Performs a search based on a pathname.
+ * @param pathname Pathname to search for the longest pathname.
+ */
+ private void find(@NotNull final String pathname) {
find(new File(pathname));
}
- private void find(final File path) {
+ /** Performs a search based on a file.
+ * @param path File to search for the longest pathname.
+ */
+ private void find(@NotNull final File path) {
final String pathname = absolute ? path.getAbsolutePath() : path.getPath();
final int length = pathname.length();
if (length > maxLength) {
@@ -88,7 +105,7 @@
}
/** {@inheritDoc} */
- public String toString() {
+ @Override public String toString() {
return maxPathname + ":" + maxLength;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-08-27 13:54:14
|
Revision: 598
http://japi.svn.sourceforge.net/japi/?rev=598&view=rev
Author: christianhujer
Date: 2007-08-27 06:42:01 -0700 (Mon, 27 Aug 2007)
Log Message:
-----------
Changed FindLongestPath to use new log() method from LogCommand.
Modified Paths:
--------------
tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java
Modified: tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java
===================================================================
--- tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java 2007-08-27 13:24:12 UTC (rev 597)
+++ tools/findLongestPath/trunk/src/net/sf/japi/findLongestPath/FindLongestPath.java 2007-08-27 13:42:01 UTC (rev 598)
@@ -104,7 +104,7 @@
maxPathname = pathname;
}
if (path.isDirectory()) {
- getLog().log(Level.FINE, "descending", path);
+ log(Level.FINE, "descending", path);
for (final File child : path.listFiles()) {
find(child);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|