Skip to content

Commit 11cc8df

Browse files
committed
* Improve generics handling for FileUtils
1 parent 5e7dea0 commit 11cc8df

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/remote/AbstractRemoteFileStreamingMessageSource.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
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.
@@ -62,11 +62,11 @@
6262
public abstract class AbstractRemoteFileStreamingMessageSource<F>
6363
extends AbstractFetchLimitingMessageSource<InputStream> implements ManageableLifecycle {
6464

65-
private final RemoteFileTemplate<F> remoteFileTemplate;
65+
private final RemoteFileTemplate<? extends F> remoteFileTemplate;
6666

6767
private final BlockingQueue<AbstractFileInfo<F>> toBeReceived = new LinkedBlockingQueue<>();
6868

69-
private final Comparator<F> comparator;
69+
private final Comparator<? extends F> comparator;
7070

7171
private final AtomicBoolean running = new AtomicBoolean();
7272

@@ -86,8 +86,8 @@ public abstract class AbstractRemoteFileStreamingMessageSource<F>
8686
*/
8787
private FileListFilter<F> filter;
8888

89-
protected AbstractRemoteFileStreamingMessageSource(RemoteFileTemplate<F> template,
90-
@Nullable Comparator<F> comparator) {
89+
protected AbstractRemoteFileStreamingMessageSource(RemoteFileTemplate<? extends F> template,
90+
@Nullable Comparator<? extends F> comparator) {
9191

9292
Assert.notNull(template, "'template' must not be null");
9393
this.remoteFileTemplate = template;
@@ -143,7 +143,7 @@ public void setFileInfoJson(boolean fileInfoJson) {
143143
this.fileInfoJson = fileInfoJson;
144144
}
145145

146-
protected RemoteFileTemplate<F> getRemoteFileTemplate() {
146+
protected RemoteFileTemplate<? extends F> getRemoteFileTemplate() {
147147
return this.remoteFileTemplate;
148148
}
149149

spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public abstract class AbstractInboundFileSynchronizer<F>
123123
private BeanFactory beanFactory;
124124

125125
@Nullable
126-
private Comparator<F> comparator;
126+
private Comparator<? extends F> comparator;
127127

128128
private MetadataStore remoteFileMetadataStore = new SimpleMetadataStore();
129129

@@ -141,7 +141,7 @@ public AbstractInboundFileSynchronizer(SessionFactory<F> sessionFactory) {
141141
}
142142

143143
@Nullable
144-
protected Comparator<F> getComparator() {
144+
protected Comparator<? extends F> getComparator() {
145145
return this.comparator;
146146
}
147147

@@ -151,9 +151,8 @@ protected Comparator<F> getComparator() {
151151
* @param comparator the comparator.
152152
* @since 5.1
153153
*/
154-
@SuppressWarnings("unchecked")
155154
public void setComparator(@Nullable Comparator<? extends F> comparator) {
156-
this.comparator = (Comparator<F>) comparator;
155+
this.comparator = comparator;
157156
}
158157

159158
/**

spring-integration-file/src/main/java/org/springframework/integration/file/support/FileUtils.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
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.
@@ -29,6 +29,7 @@
2929
* Utilities for operations on Files.
3030
*
3131
* @author Gary Russell
32+
* @author Artem Bilan
3233
*
3334
* @since 5.0
3435
*
@@ -47,22 +48,22 @@ public final class FileUtils {
4748
* @since 5.0.7
4849
*/
4950
@SuppressWarnings("unchecked")
50-
public static <F> F[] purgeUnwantedElements(F[] fileArray, Predicate<F> predicate,
51-
@Nullable Comparator<F> comparator) {
51+
public static <F> F[] purgeUnwantedElements(F[] fileArray, Predicate<? extends F> predicate,
52+
@Nullable Comparator<? extends F> comparator) {
5253

5354
if (ObjectUtils.isEmpty(fileArray)) {
5455
return fileArray;
5556
}
5657
else {
5758
if (comparator == null) {
5859
return Arrays.stream(fileArray)
59-
.filter(predicate.negate())
60+
.filter((Predicate<? super F>) predicate.negate())
6061
.toArray(size -> (F[]) Array.newInstance(fileArray[0].getClass(), size));
6162
}
6263
else {
6364
return Arrays.stream(fileArray)
64-
.filter(predicate.negate())
65-
.sorted(comparator)
65+
.filter((Predicate<? super F>) predicate.negate())
66+
.sorted((Comparator<? super F>) comparator)
6667
.toArray(size -> (F[]) Array.newInstance(fileArray[0].getClass(), size));
6768
}
6869
}

0 commit comments

Comments
 (0)