Skip to content

Commit 49ca3a4

Browse files
author
Stephen Colebourne
committed
Refactor windows identification to a method
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@417086 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4574908 commit 49ca3a4

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/java/org/apache/commons/io/FilenameUtils.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public class FilenameUtils {
116116
*/
117117
private static final char OTHER_SEPARATOR;
118118
static {
119-
if (SYSTEM_SEPARATOR == WINDOWS_SEPARATOR) {
119+
if (isSystemWindows()) {
120120
OTHER_SEPARATOR = UNIX_SEPARATOR;
121121
} else {
122122
OTHER_SEPARATOR = WINDOWS_SEPARATOR;
@@ -130,6 +130,16 @@ public FilenameUtils() {
130130
super();
131131
}
132132

133+
//-----------------------------------------------------------------------
134+
/**
135+
* Determines if Windows file system is in use.
136+
*
137+
* @return true if the system is Windows
138+
*/
139+
static boolean isSystemWindows() {
140+
return SYSTEM_SEPARATOR == WINDOWS_SEPARATOR;
141+
}
142+
133143
//-----------------------------------------------------------------------
134144
/**
135145
* Checks if the character is a separator.
@@ -432,7 +442,7 @@ public static String separatorsToSystem(String path) {
432442
if (path == null) {
433443
return null;
434444
}
435-
if (SYSTEM_SEPARATOR == WINDOWS_SEPARATOR) {
445+
if (isSystemWindows()) {
436446
return separatorsToWindows(path);
437447
} else {
438448
return separatorsToUnix(path);
@@ -966,7 +976,7 @@ private static boolean equals(
966976
filename1 = normalize(filename1);
967977
filename2 = normalize(filename2);
968978
}
969-
if (system && (SYSTEM_SEPARATOR == WINDOWS_SEPARATOR)) {
979+
if (system && isSystemWindows()) {
970980
return filename1.equalsIgnoreCase(filename2);
971981
} else {
972982
return filename1.equals(filename2);
@@ -1117,7 +1127,7 @@ private static boolean wildcardMatch(String filename, String wildcardMatcher, bo
11171127
if (filename == null || wildcardMatcher == null) {
11181128
return false;
11191129
}
1120-
if (system && (SYSTEM_SEPARATOR == WINDOWS_SEPARATOR)) {
1130+
if (system && isSystemWindows()) {
11211131
filename = filename.toLowerCase();
11221132
wildcardMatcher = wildcardMatcher.toLowerCase();
11231133
}

0 commit comments

Comments
 (0)