commons-io git commit: Don't need to nest else clause. Refactor magic numbers into constants.
Repository: commons-io Updated Branches: refs/heads/master f03149e07 -> 8993c0060 Don't need to nest else clause. Refactor magic numbers into constants. Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/8993c006 Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/8993c006 Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/8993c006 Branch: refs/heads/master Commit: 8993c0060e4eb2d5bca20e3529a829a9dd90efdf Parents: f03149e Author: Gary Gregory Authored: Tue Mar 6 10:00:42 2018 -0700 Committer: Gary Gregory Committed: Tue Mar 6 10:00:42 2018 -0700 -- .../java/org/apache/commons/io/FileUtils.java | 19 + .../io/comparator/DirectoryFileComparator.java | 10 +++ .../io/filefilter/DelegateFileFilter.java | 6 ++-- .../commons/io/filefilter/EmptyFileFilter.java | 3 +- .../commons/io/filefilter/FileFilterUtils.java | 12 ++-- .../commons/io/input/CharSequenceReader.java| 3 +- .../commons/io/input/DemuxInputStream.java | 5 +--- .../io/input/ReversedLinesFileReader.java | 13 - .../io/input/UnixLineEndingInputStream.java | 29 +--- .../io/input/WindowsLineEndingInputStream.java | 3 +- .../commons/io/input/XmlStreamReader.java | 16 --- 11 files changed, 45 insertions(+), 74 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-io/blob/8993c006/src/main/java/org/apache/commons/io/FileUtils.java -- diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java index 714f4c8..0049cbc 100644 --- a/src/main/java/org/apache/commons/io/FileUtils.java +++ b/src/main/java/org/apache/commons/io/FileUtils.java @@ -823,11 +823,10 @@ public class FileUtils { public static File toFile(final URL url) { if (url == null || !"file".equalsIgnoreCase(url.getProtocol())) { return null; -} else { -String filename = url.getFile().replace('/', File.separatorChar); -filename = decodeUrl(filename); -return new File(filename); } +String filename = url.getFile().replace('/', File.separatorChar); +filename = decodeUrl(filename); +return new File(filename); } /** @@ -2542,9 +2541,8 @@ public class FileUtils { if (file.isDirectory()) { return sizeOfDirectory0(file); // private method; expects directory -} else { -return file.length(); } +return file.length(); } @@ -2575,9 +2573,8 @@ public class FileUtils { if (file.isDirectory()) { return sizeOfDirectoryBig0(file); // internal method -} else { -return BigInteger.valueOf(file.length()); } +return BigInteger.valueOf(file.length()); } @@ -2638,9 +2635,8 @@ public class FileUtils { private static long sizeOf0(final File file) { if (file.isDirectory()) { return sizeOfDirectory0(file); -} else { -return file.length(); // will be 0 if file does not exist } +return file.length(); // will be 0 if file does not exist } /** @@ -2694,9 +2690,8 @@ public class FileUtils { private static BigInteger sizeOfBig0(final File fileOrDir) { if (fileOrDir.isDirectory()) { return sizeOfDirectoryBig0(fileOrDir); -} else { -return BigInteger.valueOf(fileOrDir.length()); } +return BigInteger.valueOf(fileOrDir.length()); } /** http://git-wip-us.apache.org/repos/asf/commons-io/blob/8993c006/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java -- diff --git a/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java b/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java index 1ab872b..c340191 100644 --- a/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java +++ b/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java @@ -44,6 +44,10 @@ import java.util.Comparator; */ public class DirectoryFileComparator extends AbstractFileComparator implements Serializable { +private static final int TYPE_FILE = 2; + +private static final int TYPE_DIRECTORY = 1; + private static final long serialVersionUID = 296132640160964395L; /** Singleton default comparator instance */ @@ -72,10 +76,6 @@ public class DirectoryFileComparator extends AbstractFileComparator implements S * @return 1 for directories and 2 for files */ private int getType(final File file)
commons-io git commit: Don't need to nest else clause.
Repository: commons-io Updated Branches: refs/heads/master a653a4487 -> 0f98e790a Don't need to nest else clause. Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/0f98e790 Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/0f98e790 Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/0f98e790 Branch: refs/heads/master Commit: 0f98e790a43b17ae1bb60d264931fb4f13300762 Parents: a653a44 Author: Gary Gregory Authored: Tue Mar 6 09:45:28 2018 -0700 Committer: Gary Gregory Committed: Tue Mar 6 09:45:28 2018 -0700 -- .../org/apache/commons/io/FilenameUtils.java| 91 +--- 1 file changed, 41 insertions(+), 50 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-io/blob/0f98e790/src/main/java/org/apache/commons/io/FilenameUtils.java -- diff --git a/src/main/java/org/apache/commons/io/FilenameUtils.java b/src/main/java/org/apache/commons/io/FilenameUtils.java index fbcfc27..e638813 100644 --- a/src/main/java/org/apache/commons/io/FilenameUtils.java +++ b/src/main/java/org/apache/commons/io/FilenameUtils.java @@ -500,9 +500,8 @@ public class FilenameUtils { final char ch = basePath.charAt(len - 1); if (isSeparator(ch)) { return normalize(basePath + fullFilenameToAdd); -} else { -return normalize(basePath + '/' + fullFilenameToAdd); } +return normalize(basePath + '/' + fullFilenameToAdd); } /** @@ -586,9 +585,8 @@ public class FilenameUtils { } if (isSystemWindows()) { return separatorsToWindows(path); -} else { -return separatorsToUnix(path); } +return separatorsToUnix(path); } //--- @@ -647,42 +645,41 @@ public class FilenameUtils { return 2; // return a length greater than the input } return isSeparator(ch0) ? 1 : 0; -} else { -if (ch0 == '~') { -int posUnix = filename.indexOf(UNIX_SEPARATOR, 1); -int posWin = filename.indexOf(WINDOWS_SEPARATOR, 1); -if (posUnix == NOT_FOUND && posWin == NOT_FOUND) { -return len + 1; // return a length greater than the input -} -posUnix = posUnix == NOT_FOUND ? posWin : posUnix; -posWin = posWin == NOT_FOUND ? posUnix : posWin; -return Math.min(posUnix, posWin) + 1; +} +if (ch0 == '~') { +int posUnix = filename.indexOf(UNIX_SEPARATOR, 1); +int posWin = filename.indexOf(WINDOWS_SEPARATOR, 1); +if (posUnix == NOT_FOUND && posWin == NOT_FOUND) { +return len + 1; // return a length greater than the input } -final char ch1 = filename.charAt(1); -if (ch1 == ':') { -ch0 = Character.toUpperCase(ch0); -if (ch0 >= 'A' && ch0 <= 'Z') { -if (len == 2 || isSeparator(filename.charAt(2)) == false) { -return 2; -} -return 3; -} else if (ch0 == UNIX_SEPARATOR) { -return 1; +posUnix = posUnix == NOT_FOUND ? posWin : posUnix; +posWin = posWin == NOT_FOUND ? posUnix : posWin; +return Math.min(posUnix, posWin) + 1; +} +final char ch1 = filename.charAt(1); +if (ch1 == ':') { +ch0 = Character.toUpperCase(ch0); +if (ch0 >= 'A' && ch0 <= 'Z') { +if (len == 2 || isSeparator(filename.charAt(2)) == false) { +return 2; } -return NOT_FOUND; +return 3; +} else if (ch0 == UNIX_SEPARATOR) { +return 1; +} +return NOT_FOUND; -} else if (isSeparator(ch0) && isSeparator(ch1)) { -int posUnix = filename.indexOf(UNIX_SEPARATOR, 2); -int posWin = filename.indexOf(WINDOWS_SEPARATOR, 2); -if (posUnix == NOT_FOUND && posWin == NOT_FOUND || posUnix == 2 || posWin == 2) { -return NOT_FOUND; -} -posUnix = posUnix == NOT_FOUND ? posWin : posUnix; -posWin = posWin == NOT_FOUND ? posUnix : posWin; -return Math.min(posUnix, posWin) + 1; -} else { -return isSeparator(ch0) ? 1 : 0; +} else if (isSeparator(ch0) && isSeparator(ch1)) { +int posUnix = filename.indexOf(UNIX_SEPARATOR, 2); +int posWin = filename.i
commons-io git commit: Don't need to nest else clause.
Repository: commons-io Updated Branches: refs/heads/master 27fb1044f -> 467386105 Don't need to nest else clause. Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/46738610 Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/46738610 Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/46738610 Branch: refs/heads/master Commit: 467386105ad855e793a09632142c00cd01c5dd10 Parents: 27fb104 Author: Gary Gregory Authored: Tue Mar 6 09:27:13 2018 -0700 Committer: Gary Gregory Committed: Tue Mar 6 09:27:13 2018 -0700 -- .../org/apache/commons/io/input/Tailer.java | 37 ++-- 1 file changed, 18 insertions(+), 19 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-io/blob/46738610/src/main/java/org/apache/commons/io/input/Tailer.java -- diff --git a/src/main/java/org/apache/commons/io/input/Tailer.java b/src/main/java/org/apache/commons/io/input/Tailer.java index 0434e83..3702fc5 100644 --- a/src/main/java/org/apache/commons/io/input/Tailer.java +++ b/src/main/java/org/apache/commons/io/input/Tailer.java @@ -449,25 +449,24 @@ public class Tailer implements Runnable { Thread.sleep(delayMillis); } continue; -} else { -// File was not rotated -// See if the file needs to be read again -if (length > position) { -// The file has more content than it did last time -position = readLines(reader); -last = file.lastModified(); -} else if (newer) { -/* - * This can happen if the file is truncated or overwritten with the exact same length of - * information. In cases like this, the file position needs to be reset - */ -position = 0; -reader.seek(position); // cannot be null here - -// Now we can read new lines -position = readLines(reader); -last = file.lastModified(); -} +} +// File was not rotated +// See if the file needs to be read again +if (length > position) { +// The file has more content than it did last time +position = readLines(reader); +last = file.lastModified(); +} else if (newer) { +/* + * This can happen if the file is truncated or overwritten with the exact same length of + * information. In cases like this, the file position needs to be reset + */ +position = 0; +reader.seek(position); // cannot be null here + +// Now we can read new lines +position = readLines(reader); +last = file.lastModified(); } if (reOpen && reader != null) { reader.close();