Skip to content

Commit b49f609

Browse files
committed
Add new ComposableFileFilter extension and implementation of Java's FileFilter interface.
1 parent db0f304 commit b49f609

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2017-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13+
* or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
package org.springframework.data.gemfire.tests.util;
17+
18+
import java.io.FileFilter;
19+
20+
import org.springframework.lang.NonNull;
21+
import org.springframework.lang.Nullable;
22+
23+
/**
24+
* Java {@link FileFilter} implementation capable of being composed
25+
*
26+
* @author John Blum
27+
* @see java.lang.FunctionalInterface
28+
* @see java.io.FileFilter
29+
* @since 0.3.5-RAJ
30+
*/
31+
@FunctionalInterface
32+
@SuppressWarnings("unused")
33+
public interface ComposableFileFilter extends FileFilter {
34+
35+
default @NonNull ComposableFileFilter andThen(@Nullable ComposableFileFilter fileFilter) {
36+
return fileFilter == null ? this
37+
: file -> this.accept(file) && fileFilter.accept(file);
38+
}
39+
40+
default @NonNull ComposableFileFilter orThen(@Nullable ComposableFileFilter fileFilter) {
41+
return fileFilter == null ? this
42+
: file -> this.accept(file) || fileFilter.accept(file);
43+
}
44+
}

spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/util/FileSystemUtils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ public static boolean isEmpty(@Nullable File path) {
121121

122122
File[] files = isDirectory(directory) ? directory.listFiles(resolvedFileFilter) : null;
123123

124-
return files != null
125-
? files
126-
: NO_FILES;
124+
return files != null ? files : NO_FILES;
127125
}
128126

129127
public static class AllFilesFilter implements FileFilter {

0 commit comments

Comments
 (0)