Skip to content

Commit b3e8123

Browse files
author
Stephen Colebourne
committed
TrueFileFilter/FalseFileFilter/DirectoryFileFilter new constants
- New singleton instance constants (TRUE/FALSE/DIRECTORY) - The new constants are more JDK 1.5 friendly with regards to static imports (whereas if everything uses INSTANCE, then they just clash) - The old INSTANCE constants are still present and have not been deprecated git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@424745 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9286d35 commit b3e8123

6 files changed

Lines changed: 76 additions & 36 deletions

File tree

RELEASE-NOTES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ Enhancements from 1.2
7575
- New IOFileFilter implementation
7676
- Accepts files or directories that are empty
7777

78+
- TrueFileFilter/FalseFileFilter/DirectoryFileFilter
79+
- New singleton instance constants (TRUE/FALSE/DIRECTORY)
80+
- The new constants are more JDK 1.5 friendly with regards to static imports
81+
(whereas if everything uses INSTANCE, then they just clash)
82+
- The old INSTANCE constants are still present and have not been deprecated
83+
7884

7985
Feedback
8086
--------

src/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2004 The Apache Software Foundation.
2+
* Copyright 2002-2004,2006 The Apache Software Foundation.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,30 +33,40 @@
3333
*
3434
* @since Commons IO 1.0
3535
* @version $Revision$ $Date$
36-
*
36+
*
3737
* @author Henri Yandell
3838
* @author Stephen Colebourne
3939
* @author Peter Donald
4040
*/
4141
public class DirectoryFileFilter extends AbstractFileFilter {
42-
43-
/** Singleton instance of directory filter */
44-
public static final IOFileFilter INSTANCE = new DirectoryFileFilter();
45-
42+
43+
/**
44+
* Singleton instance of directory filter.
45+
* @since Commons IO 1.3
46+
*/
47+
public static final IOFileFilter DIRECTORY = new DirectoryFileFilter();
48+
/**
49+
* Singleton instance of directory filter.
50+
* Please use the identical DirectoryFileFilter.DIRECTORY constant.
51+
* The new name is more JDK 1.5 friendly as it doesn't clash with other
52+
* values when using static imports.
53+
*/
54+
public static final IOFileFilter INSTANCE = DIRECTORY;
55+
4656
/**
4757
* Restrictive consructor.
4858
*/
4959
protected DirectoryFileFilter() {
5060
}
51-
61+
5262
/**
5363
* Checks to see if the file is a directory.
54-
*
64+
*
5565
* @param file the File to check
5666
* @return true if the file is a directory
5767
*/
5868
public boolean accept(File file) {
5969
return file.isDirectory();
6070
}
61-
71+
6272
}
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2004 The Apache Software Foundation.
2+
* Copyright 2002-2004,2006 The Apache Software Foundation.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,43 +19,53 @@
1919

2020
/**
2121
* A file filter that always returns false.
22-
*
22+
*
2323
* @since Commons IO 1.0
2424
* @version $Revision$ $Date$
25-
*
25+
*
2626
* @author Henri Yandell
2727
* @author Stephen Colebourne
2828
*/
2929
public class FalseFileFilter implements IOFileFilter {
30-
31-
/** Singleton instance of false filter */
32-
public static final IOFileFilter INSTANCE = new FalseFileFilter();
33-
30+
31+
/**
32+
* Singleton instance of false filter.
33+
* @since Commons IO 1.3
34+
*/
35+
public static final IOFileFilter FALSE = new FalseFileFilter();
36+
/**
37+
* Singleton instance of false filter.
38+
* Please use the identical FalseFileFilter.FALSE constant.
39+
* The new name is more JDK 1.5 friendly as it doesn't clash with other
40+
* values when using static imports.
41+
*/
42+
public static final IOFileFilter INSTANCE = FALSE;
43+
3444
/**
3545
* Restrictive consructor.
3646
*/
3747
protected FalseFileFilter() {
3848
}
39-
49+
4050
/**
4151
* Returns false.
42-
*
52+
*
4353
* @param file the file to check
4454
* @return false
4555
*/
4656
public boolean accept(File file) {
4757
return false;
4858
}
49-
59+
5060
/**
5161
* Returns false.
52-
*
62+
*
5363
* @param dir the directory to check
5464
* @param name the filename
5565
* @return false
5666
*/
5767
public boolean accept(File dir, String name) {
5868
return false;
5969
}
60-
70+
6171
}

src/java/org/apache/commons/io/filefilter/FileFilterUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static IOFileFilter nameFileFilter(String name) {
7979
* @return file filter that accepts only directories and not files
8080
*/
8181
public static IOFileFilter directoryFileFilter() {
82-
return DirectoryFileFilter.INSTANCE;
82+
return DirectoryFileFilter.DIRECTORY;
8383
}
8484

8585
/**
@@ -131,7 +131,7 @@ public static IOFileFilter notFileFilter(IOFileFilter filter) {
131131
* @return a true filter
132132
*/
133133
public static IOFileFilter trueFileFilter() {
134-
return TrueFileFilter.INSTANCE;
134+
return TrueFileFilter.TRUE;
135135
}
136136

137137
/**
@@ -140,7 +140,7 @@ public static IOFileFilter trueFileFilter() {
140140
* @return a false filter
141141
*/
142142
public static IOFileFilter falseFileFilter() {
143-
return FalseFileFilter.INSTANCE;
143+
return FalseFileFilter.FALSE;
144144
}
145145

146146
//-----------------------------------------------------------------------
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2004 The Apache Software Foundation.
2+
* Copyright 2002-2004,2006 The Apache Software Foundation.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,43 +19,53 @@
1919

2020
/**
2121
* A file filter that always returns true.
22-
*
22+
*
2323
* @since Commons IO 1.0
2424
* @version $Revision$ $Date$
25-
*
25+
*
2626
* @author Henri Yandell
2727
* @author Stephen Colebourne
2828
*/
2929
public class TrueFileFilter implements IOFileFilter {
30-
31-
/** Singleton instance of true filter */
32-
public static final IOFileFilter INSTANCE = new TrueFileFilter();
33-
30+
31+
/**
32+
* Singleton instance of true filter.
33+
* @since Commons IO 1.3
34+
*/
35+
public static final IOFileFilter TRUE = new TrueFileFilter();
36+
/**
37+
* Singleton instance of true filter.
38+
* Please use the identical TrueFileFilter.TRUE constant.
39+
* The new name is more JDK 1.5 friendly as it doesn't clash with other
40+
* values when using static imports.
41+
*/
42+
public static final IOFileFilter INSTANCE = TRUE;
43+
3444
/**
3545
* Restrictive consructor.
3646
*/
3747
protected TrueFileFilter() {
3848
}
39-
49+
4050
/**
4151
* Returns true.
42-
*
52+
*
4353
* @param file the file to check
4454
* @return true
4555
*/
4656
public boolean accept(File file) {
4757
return true;
4858
}
49-
59+
5060
/**
5161
* Returns true.
52-
*
62+
*
5363
* @param dir the directory to check
5464
* @param name the filename
5565
* @return true
5666
*/
5767
public boolean accept(File dir, String name) {
5868
return true;
5969
}
60-
70+
6171
}

src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ public void testDirectory() throws Exception {
136136
assertFiltering(filter, new File("imaginary/"), false);
137137

138138
assertFiltering(filter, new File("STATUS.html"), false);
139+
140+
assertSame(DirectoryFileFilter.DIRECTORY, DirectoryFileFilter.INSTANCE);
139141
}
140142

141143
public void testFiles() throws Exception {
@@ -282,13 +284,15 @@ public void testTrue() throws Exception {
282284
assertFiltering(filter, new File("foo.test"), true);
283285
assertFiltering(filter, new File("foo"), true);
284286
assertFiltering(filter, null, true);
287+
assertSame(TrueFileFilter.TRUE, TrueFileFilter.INSTANCE);
285288
}
286289

287290
public void testFalse() throws Exception {
288291
IOFileFilter filter = FileFilterUtils.falseFileFilter();
289292
assertFiltering(filter, new File("foo.test"), false);
290293
assertFiltering(filter, new File("foo"), false);
291294
assertFiltering(filter, null, false);
295+
assertSame(FalseFileFilter.FALSE, FalseFileFilter.INSTANCE);
292296
}
293297

294298
public void testNot() throws Exception {

0 commit comments

Comments
 (0)