Skip to content

Commit 40a0443

Browse files
Minor improvements: (#233)
* Use Method reference * Use List.sort() * Change Explicit with <> * Simplify conditional expression
1 parent 16f90c7 commit 40a0443

6 files changed

Lines changed: 14 additions & 14 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public class FileCleaningTracker {
5252
/**
5353
* Collection of {@code Tracker} instances in existence.
5454
*/
55-
final Collection<Tracker> trackers = Collections.synchronizedSet(new HashSet<Tracker>()); // synchronized
55+
final Collection<Tracker> trackers = Collections.synchronizedSet(new HashSet<>()); // synchronized
5656
/**
5757
* Collection of File paths that failed to delete.
5858
*/
59-
final List<String> deleteFailures = Collections.synchronizedList(new ArrayList<String>());
59+
final List<String> deleteFailures = Collections.synchronizedList(new ArrayList<>());
6060
/**
6161
* Whether to terminate the thread when the tracking is complete.
6262
*/

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ public static String getUserDirectoryPath() {
15071507
* @since 2.9.0
15081508
*/
15091509
public static boolean isDirectory(final File file, final LinkOption... options) {
1510-
return file != null ? Files.isDirectory(file.toPath(), options) : false;
1510+
return file != null && Files.isDirectory(file.toPath(), options);
15111511
}
15121512

15131513
/**
@@ -1681,7 +1681,7 @@ public static boolean isFileNewer(final File file, final Instant instant) {
16811681
*/
16821682
public static boolean isFileNewer(final File file, final long timeMillis) {
16831683
Objects.requireNonNull(file, "file");
1684-
return file.exists() ? lastModifiedUnchecked(file) > timeMillis : false;
1684+
return file.exists() && lastModifiedUnchecked(file) > timeMillis;
16851685
}
16861686

16871687
/**
@@ -1842,7 +1842,7 @@ public static boolean isFileOlder(final File file, final Instant instant) {
18421842
*/
18431843
public static boolean isFileOlder(final File file, final long timeMillis) {
18441844
Objects.requireNonNull(file, "file");
1845-
return file.exists() ? lastModifiedUnchecked(file) < timeMillis : false;
1845+
return file.exists() && lastModifiedUnchecked(file) < timeMillis;
18461846
}
18471847

18481848
/**
@@ -1860,7 +1860,7 @@ public static boolean isFileOlder(final File file, final long timeMillis) {
18601860
* @since 2.9.0
18611861
*/
18621862
public static boolean isRegularFile(final File file, final LinkOption... options) {
1863-
return file != null ? Files.isRegularFile(file.toPath(), options) : false;
1863+
return file != null && Files.isRegularFile(file.toPath(), options);
18641864
}
18651865

18661866
/**
@@ -1875,7 +1875,7 @@ public static boolean isRegularFile(final File file, final LinkOption... options
18751875
* @see Files#isSymbolicLink(Path)
18761876
*/
18771877
public static boolean isSymlink(final File file) {
1878-
return file != null ? Files.isSymbolicLink(file.toPath()) : false;
1878+
return file != null && Files.isSymbolicLink(file.toPath());
18791879
}
18801880

18811881
/**
@@ -2060,7 +2060,7 @@ public static LineIterator lineIterator(final File file, final String charsetNam
20602060
inputStream = openInputStream(file);
20612061
return IOUtils.lineIterator(inputStream, charsetName);
20622062
} catch (final IOException | RuntimeException ex) {
2063-
IOUtils.closeQuietly(inputStream, e -> ex.addSuppressed(e));
2063+
IOUtils.closeQuietly(inputStream, ex::addSuppressed);
20642064
throw ex;
20652065
}
20662066
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ public class IOUtils {
180180
/**
181181
* Internal byte array buffer.
182182
*/
183-
private static final ThreadLocal<byte[]> SKIP_BYTE_BUFFER = ThreadLocal.withInitial(() -> byteArray());
183+
private static final ThreadLocal<byte[]> SKIP_BYTE_BUFFER = ThreadLocal.withInitial(IOUtils::byteArray);
184184

185185
/**
186186
* Internal byte array buffer.
187187
*/
188-
private static final ThreadLocal<char[]> SKIP_CHAR_BUFFER = ThreadLocal.withInitial(() -> charArray());
188+
private static final ThreadLocal<char[]> SKIP_CHAR_BUFFER = ThreadLocal.withInitial(IOUtils::charArray);
189189

190190
/**
191191
* Returns the given InputStream if it is already a {@link BufferedInputStream}, otherwise creates a

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public boolean hasNext() {
105105
}
106106
}
107107
} catch(final IOException ioe) {
108-
IOUtils.closeQuietly(this, e -> ioe.addSuppressed(e));
108+
IOUtils.closeQuietly(this, ioe::addSuppressed);
109109
throw new IllegalStateException(ioe);
110110
}
111111
}

src/main/java/org/apache/commons/io/comparator/AbstractFileComparator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public File[] sort(final File... files) {
5858
*/
5959
public List<File> sort(final List<File> files) {
6060
if (files != null) {
61-
Collections.sort(files, this);
61+
files.sort(this);
6262
}
6363
return files;
6464
}

src/main/java/org/apache/commons/io/file/PathUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ public static List<AclEntry> getAclEntryList(final Path sourcePath) throws IOExc
733733
* @since 2.9.0
734734
*/
735735
public static boolean isDirectory(final Path path, final LinkOption... options) {
736-
return path != null ? Files.isDirectory(path, options) : false;
736+
return path != null && Files.isDirectory(path, options);
737737
}
738738

739739
/**
@@ -815,7 +815,7 @@ public static boolean isNewer(final Path file, final long timeMillis, final Link
815815
* @since 2.9.0
816816
*/
817817
public static boolean isRegularFile(final Path path, final LinkOption... options) {
818-
return path != null ? Files.isRegularFile(path, options) : false;
818+
return path != null && Files.isRegularFile(path, options);
819819
}
820820

821821
/**

0 commit comments

Comments
 (0)