Skip to content

Commit a74a5a0

Browse files
author
Niall Pemberton
committed
IO-140 JDK 1.5 changes: Use generics
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@619103 13f79535-47bb-0310-9956-ffa450edef68
1 parent a7628b0 commit a74a5a0

25 files changed

Lines changed: 132 additions & 180 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class FileCleaningTracker {
4848
/**
4949
* Collection of <code>Tracker</code> instances in existence.
5050
*/
51-
final Collection /* Tracker */ trackers = new Vector(); // synchronized
51+
final Collection<Tracker> trackers = new Vector<Tracker>(); // synchronized
5252
/**
5353
* Whether to terminate the thread when the tracking is complete.
5454
*/

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,14 @@ long freeSpaceUnix(String path, boolean kb, boolean posix) throws IOException {
320320
(flags.length() > 1 ? new String[] {"df", flags, path} : new String[] {"df", path});
321321

322322
// perform the command, asking for up to 3 lines (header, interesting, overflow)
323-
List lines = performCommand(cmdAttribs, 3);
323+
List<String> lines = performCommand(cmdAttribs, 3);
324324
if (lines.size() < 2) {
325325
// unknown problem, throw exception
326326
throw new IOException(
327327
"Command line 'df' did not return info as expected " +
328328
"for path '" + path + "'- response was " + lines);
329329
}
330-
String line2 = (String) lines.get(1); // the line we're interested in
330+
String line2 = lines.get(1); // the line we're interested in
331331

332332
// Now, we tokenize the string. The fourth element is what we want.
333333
StringTokenizer tok = new StringTokenizer(line2, " ");
@@ -385,7 +385,7 @@ long parseBytes(String freeSpace, String path) throws IOException {
385385
* @return the parsed data
386386
* @throws IOException if an error occurs
387387
*/
388-
List performCommand(String[] cmdAttribs, int max) throws IOException {
388+
List<String> performCommand(String[] cmdAttribs, int max) throws IOException {
389389
// this method does what it can to avoid the 'Too many open files' error
390390
// based on trial and error and these links:
391391
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4784692
@@ -394,7 +394,7 @@ List performCommand(String[] cmdAttribs, int max) throws IOException {
394394
// however, its still not perfect as the JDK support is so poor
395395
// (see commond-exec or ant for a better multi-threaded multi-os solution)
396396

397-
List lines = new ArrayList(20);
397+
List<String> lines = new ArrayList<String>(20);
398398
Process proc = null;
399399
InputStream in = null;
400400
OutputStream out = null;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ public static void touch(File file) throws IOException {
235235
* @param files a Collection containing java.io.File instances
236236
* @return an array of java.io.File
237237
*/
238-
public static File[] convertFileCollectionToFileArray(Collection files) {
239-
return (File[]) files.toArray(new File[files.size()]);
238+
public static File[] convertFileCollectionToFileArray(Collection<File> files) {
239+
return files.toArray(new File[files.size()]);
240240
}
241241

242242
//-----------------------------------------------------------------------
@@ -248,7 +248,7 @@ public static File[] convertFileCollectionToFileArray(Collection files) {
248248
* @param directory the directory to search in.
249249
* @param filter the filter to apply to files and directories.
250250
*/
251-
private static void innerListFiles(Collection files, File directory,
251+
private static void innerListFiles(Collection<File> files, File directory,
252252
IOFileFilter filter) {
253253
File[] found = directory.listFiles((FileFilter) filter);
254254
if (found != null) {
@@ -287,7 +287,7 @@ private static void innerListFiles(Collection files, File directory,
287287
* @see org.apache.commons.io.filefilter.FileFilterUtils
288288
* @see org.apache.commons.io.filefilter.NameFileFilter
289289
*/
290-
public static Collection listFiles(
290+
public static Collection<File> listFiles(
291291
File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {
292292
if (!directory.isDirectory()) {
293293
throw new IllegalArgumentException(
@@ -311,7 +311,7 @@ public static Collection listFiles(
311311
}
312312

313313
//Find files
314-
Collection files = new java.util.LinkedList();
314+
Collection<File> files = new java.util.LinkedList<File>();
315315
innerListFiles(files, directory,
316316
FileFilterUtils.orFileFilter(effFileFilter, effDirFilter));
317317
return files;
@@ -873,11 +873,11 @@ public static void copyDirectory(File srcDir, File destDir,
873873
}
874874

875875
// Cater for destination being directory within the source directory (see IO-141)
876-
List exclusionList = null;
876+
List<String> exclusionList = null;
877877
if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) {
878878
File[] srcFiles = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter);
879879
if (srcFiles != null && srcFiles.length > 0) {
880-
exclusionList = new ArrayList(srcFiles.length);
880+
exclusionList = new ArrayList<String>(srcFiles.length);
881881
for (int i = 0; i < srcFiles.length; i++) {
882882
File copiedFile = new File(destDir, srcFiles[i].getName());
883883
exclusionList.add(copiedFile.getCanonicalPath());
@@ -899,7 +899,7 @@ public static void copyDirectory(File srcDir, File destDir,
899899
* @since Commons IO 1.1
900900
*/
901901
private static void doCopyDirectory(File srcDir, File destDir, FileFilter filter,
902-
boolean preserveFileDate, List exclusionList) throws IOException {
902+
boolean preserveFileDate, List<String> exclusionList) throws IOException {
903903
if (destDir.exists()) {
904904
if (destDir.isDirectory() == false) {
905905
throw new IOException("Destination '" + destDir + "' exists but is not a directory");

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,12 +1152,12 @@ public static boolean wildcardMatch(String filename, String wildcardMatcher, IOC
11521152
boolean anyChars = false;
11531153
int textIdx = 0;
11541154
int wcsIdx = 0;
1155-
Stack backtrack = new Stack();
1155+
Stack<int[]> backtrack = new Stack<int[]>();
11561156

11571157
// loop around a backtrack stack, to handle complex * matching
11581158
do {
11591159
if (backtrack.size() > 0) {
1160-
int[] array = (int[]) backtrack.pop();
1160+
int[] array = backtrack.pop();
11611161
wcsIdx = array[0];
11621162
textIdx = array[1];
11631163
anyChars = true;
@@ -1232,7 +1232,7 @@ static String[] splitOnTokens(String text) {
12321232
}
12331233

12341234
char[] array = text.toCharArray();
1235-
ArrayList list = new ArrayList();
1235+
ArrayList<String> list = new ArrayList<String>();
12361236
StringBuffer buffer = new StringBuffer();
12371237
for (int i = 0; i < array.length; i++) {
12381238
if (array[i] == '?' || array[i] == '*') {
@@ -1254,7 +1254,7 @@ static String[] splitOnTokens(String text) {
12541254
list.add(buffer.toString());
12551255
}
12561256

1257-
return (String[]) list.toArray( new String[ list.size() ] );
1257+
return list.toArray( new String[ list.size() ] );
12581258
}
12591259

12601260
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,9 @@ public static List readLines(InputStream input, String encoding) throws IOExcept
496496
* @throws IOException if an I/O error occurs
497497
* @since Commons IO 1.1
498498
*/
499-
public static List readLines(Reader input) throws IOException {
499+
public static List<String> readLines(Reader input) throws IOException {
500500
BufferedReader reader = new BufferedReader(input);
501-
List list = new ArrayList();
501+
List<String> list = new ArrayList<String>();
502502
String line = reader.readLine();
503503
while (line != null) {
504504
list.add(line);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* @version $Id$
5151
* @since Commons IO 1.2
5252
*/
53-
public class LineIterator implements Iterator {
53+
public class LineIterator implements Iterator<String> {
5454

5555
/** The reader that is being read. */
5656
private final BufferedReader bufferedReader;
@@ -125,7 +125,7 @@ protected boolean isValidLine(String line) {
125125
* @return the next line from the input
126126
* @throws NoSuchElementException if there is no line to return
127127
*/
128-
public Object next() {
128+
public String next() {
129129
return nextLine();
130130
}
131131

src/java/org/apache/commons/io/comparator/DefaultFileComparator.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,23 @@
4444
* @version $Revision$ $Date$
4545
* @since Commons IO 1.4
4646
*/
47-
public class DefaultFileComparator implements Comparator, Serializable {
47+
public class DefaultFileComparator implements Comparator<File>, Serializable {
4848

4949
/** Singleton default comparator instance */
50-
public static final Comparator DEFAULT_COMPARATOR = new DefaultFileComparator();
50+
public static final Comparator<File> DEFAULT_COMPARATOR = new DefaultFileComparator();
5151

5252
/** Singleton reverse default comparator instance */
53-
public static final Comparator DEFAULT_REVERSE = new ReverseComparator(DEFAULT_COMPARATOR);
53+
public static final Comparator<File> DEFAULT_REVERSE = new ReverseComparator(DEFAULT_COMPARATOR);
5454

5555
/**
5656
* Compare the two files using the {@link File#compareTo(File)} method.
5757
*
58-
* @param obj1 The first file to compare
59-
* @param obj2 The second file to compare
58+
* @param file1 The first file to compare
59+
* @param file2 The second file to compare
6060
* @return the result of calling file1's
6161
* {@link File#compareTo(File)} with file2 as the parameter.
6262
*/
63-
public int compare(Object obj1, Object obj2) {
64-
File file1 = (File)obj1;
65-
File file2 = (File)obj2;
63+
public int compare(File file1, File file2) {
6664
return file1.compareTo(file2);
6765
}
6866
}

src/java/org/apache/commons/io/comparator/ExtensionFileComparator.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,26 @@
5151
* @version $Revision$ $Date$
5252
* @since Commons IO 1.4
5353
*/
54-
public class ExtensionFileComparator implements Comparator, Serializable {
54+
public class ExtensionFileComparator implements Comparator<File>, Serializable {
5555

5656
/** Case-sensitive extension comparator instance (see {@link IOCase#SENSITIVE}) */
57-
public static final Comparator EXTENSION_COMPARATOR = new ExtensionFileComparator();
57+
public static final Comparator<File> EXTENSION_COMPARATOR = new ExtensionFileComparator();
5858

5959
/** Reverse case-sensitive extension comparator instance (see {@link IOCase#SENSITIVE}) */
60-
public static final Comparator EXTENSION_REVERSE = new ReverseComparator(EXTENSION_COMPARATOR);
60+
public static final Comparator<File> EXTENSION_REVERSE = new ReverseComparator(EXTENSION_COMPARATOR);
6161

6262
/** Case-insensitive extension comparator instance (see {@link IOCase#INSENSITIVE}) */
63-
public static final Comparator EXTENSION_INSENSITIVE_COMPARATOR = new ExtensionFileComparator(IOCase.INSENSITIVE);
63+
public static final Comparator<File> EXTENSION_INSENSITIVE_COMPARATOR = new ExtensionFileComparator(IOCase.INSENSITIVE);
6464

6565
/** Reverse case-insensitive extension comparator instance (see {@link IOCase#INSENSITIVE}) */
66-
public static final Comparator EXTENSION_INSENSITIVE_REVERSE
66+
public static final Comparator<File> EXTENSION_INSENSITIVE_REVERSE
6767
= new ReverseComparator(EXTENSION_INSENSITIVE_COMPARATOR);
6868

6969
/** System sensitive extension comparator instance (see {@link IOCase#SYSTEM}) */
70-
public static final Comparator EXTENSION_SYSTEM_COMPARATOR = new ExtensionFileComparator(IOCase.SYSTEM);
70+
public static final Comparator<File> EXTENSION_SYSTEM_COMPARATOR = new ExtensionFileComparator(IOCase.SYSTEM);
7171

7272
/** Reverse system sensitive path comparator instance (see {@link IOCase#SYSTEM}) */
73-
public static final Comparator EXTENSION_SYSTEM_REVERSE = new ReverseComparator(EXTENSION_SYSTEM_COMPARATOR);
73+
public static final Comparator<File> EXTENSION_SYSTEM_REVERSE = new ReverseComparator(EXTENSION_SYSTEM_COMPARATOR);
7474

7575
/** Whether the comparison is case sensitive. */
7676
private final IOCase caseSensitivity;
@@ -94,17 +94,15 @@ public ExtensionFileComparator(IOCase caseSensitivity) {
9494
/**
9595
* Compare the extensions of two files the specified case sensitivity.
9696
*
97-
* @param obj1 The first file to compare
98-
* @param obj2 The second file to compare
97+
* @param file1 The first file to compare
98+
* @param file2 The second file to compare
9999
* @return a negative value if the first file's extension
100100
* is less than the second, zero if the extensions are the
101101
* same and a positive value if the first files extension
102102
* is greater than the second file.
103103
*
104104
*/
105-
public int compare(Object obj1, Object obj2) {
106-
File file1 = (File)obj1;
107-
File file2 = (File)obj2;
105+
public int compare(File file1, File file2) {
108106
String suffix1 = FilenameUtils.getExtension(file1.getName());
109107
String suffix2 = FilenameUtils.getExtension(file2.getName());
110108
return caseSensitivity.checkCompareTo(suffix1, suffix2);

src/java/org/apache/commons/io/comparator/LastModifiedFileComparator.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,26 @@
4545
* @version $Revision$ $Date$
4646
* @since Commons IO 1.4
4747
*/
48-
public class LastModifiedFileComparator implements Comparator, Serializable {
48+
public class LastModifiedFileComparator implements Comparator<File>, Serializable {
4949

5050
/** Last modified comparator instance */
51-
public static final Comparator LASTMODIFIED_COMPARATOR = new LastModifiedFileComparator();
51+
public static final Comparator<File> LASTMODIFIED_COMPARATOR = new LastModifiedFileComparator();
5252

5353
/** Reverse last modified comparator instance */
54-
public static final Comparator LASTMODIFIED_REVERSE = new ReverseComparator(LASTMODIFIED_COMPARATOR);
54+
public static final Comparator<File> LASTMODIFIED_REVERSE = new ReverseComparator(LASTMODIFIED_COMPARATOR);
5555

5656
/**
5757
* Compare the last the last modified date/time of two files.
5858
*
59-
* @param obj1 The first file to compare
60-
* @param obj2 The second file to compare
59+
* @param file1 The first file to compare
60+
* @param file2 The second file to compare
6161
* @return a negative value if the first file's lastmodified date/time
6262
* is less than the second, zero if the lastmodified date/time are the
6363
* same and a positive value if the first files lastmodified date/time
6464
* is greater than the second file.
6565
*
6666
*/
67-
public int compare(Object obj1, Object obj2) {
68-
File file1 = (File)obj1;
69-
File file2 = (File)obj2;
67+
public int compare(File file1, File file2) {
7068
long result = file1.lastModified() - file2.lastModified();
7169
if (result < 0) {
7270
return -1;

src/java/org/apache/commons/io/comparator/NameFileComparator.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,25 @@
4949
* @version $Revision$ $Date$
5050
* @since Commons IO 1.4
5151
*/
52-
public class NameFileComparator implements Comparator, Serializable {
52+
public class NameFileComparator implements Comparator<File>, Serializable {
5353

5454
/** Case-sensitive name comparator instance (see {@link IOCase#SENSITIVE}) */
55-
public static final Comparator NAME_COMPARATOR = new NameFileComparator();
55+
public static final Comparator<File> NAME_COMPARATOR = new NameFileComparator();
5656

5757
/** Reverse case-sensitive name comparator instance (see {@link IOCase#SENSITIVE}) */
58-
public static final Comparator NAME_REVERSE = new ReverseComparator(NAME_COMPARATOR);
58+
public static final Comparator<File> NAME_REVERSE = new ReverseComparator(NAME_COMPARATOR);
5959

6060
/** Case-insensitive name comparator instance (see {@link IOCase#INSENSITIVE}) */
61-
public static final Comparator NAME_INSENSITIVE_COMPARATOR = new NameFileComparator(IOCase.INSENSITIVE);
61+
public static final Comparator<File> NAME_INSENSITIVE_COMPARATOR = new NameFileComparator(IOCase.INSENSITIVE);
6262

6363
/** Reverse case-insensitive name comparator instance (see {@link IOCase#INSENSITIVE}) */
64-
public static final Comparator NAME_INSENSITIVE_REVERSE = new ReverseComparator(NAME_INSENSITIVE_COMPARATOR);
64+
public static final Comparator<File> NAME_INSENSITIVE_REVERSE = new ReverseComparator(NAME_INSENSITIVE_COMPARATOR);
6565

6666
/** System sensitive name comparator instance (see {@link IOCase#SYSTEM}) */
67-
public static final Comparator NAME_SYSTEM_COMPARATOR = new NameFileComparator(IOCase.SYSTEM);
67+
public static final Comparator<File> NAME_SYSTEM_COMPARATOR = new NameFileComparator(IOCase.SYSTEM);
6868

6969
/** Reverse system sensitive name comparator instance (see {@link IOCase#SYSTEM}) */
70-
public static final Comparator NAME_SYSTEM_REVERSE = new ReverseComparator(NAME_SYSTEM_COMPARATOR);
70+
public static final Comparator<File> NAME_SYSTEM_REVERSE = new ReverseComparator(NAME_SYSTEM_COMPARATOR);
7171

7272
/** Whether the comparison is case sensitive. */
7373
private final IOCase caseSensitivity;
@@ -91,16 +91,14 @@ public NameFileComparator(IOCase caseSensitivity) {
9191
/**
9292
* Compare the names of two files with the specified case sensitivity.
9393
*
94-
* @param obj1 The first file to compare
95-
* @param obj2 The second file to compare
94+
* @param file1 The first file to compare
95+
* @param file2 The second file to compare
9696
* @return a negative value if the first file's name
9797
* is less than the second, zero if the names are the
9898
* same and a positive value if the first files name
9999
* is greater than the second file.
100100
*/
101-
public int compare(Object obj1, Object obj2) {
102-
File file1 = (File)obj1;
103-
File file2 = (File)obj2;
101+
public int compare(File file1, File file2) {
104102
return caseSensitivity.checkCompareTo(file1.getName(), file2.getName());
105103
}
106104
}

0 commit comments

Comments
 (0)