diff --git a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/CompositeFileListFilter.java b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/CompositeFileListFilter.java index 31109b27cb..48fbf3f8af 100644 --- a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/CompositeFileListFilter.java +++ b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/CompositeFileListFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import java.io.File; import java.io.FileFilter; import java.util.Arrays; import java.util.Collection; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -32,29 +32,32 @@ import org.springframework.util.Assert; * {@link #filterFiles(File)} method in order to be accepted by the composite. * * @author Iwein Fuld + * @author Mark Fisher */ public class CompositeFileListFilter implements FileListFilter { private final Set fileFilters; + public CompositeFileListFilter(FileListFilter... fileFilters) { - this.fileFilters = new HashSet(Arrays.asList(fileFilters)); + this.fileFilters = new LinkedHashSet(Arrays.asList(fileFilters)); } public CompositeFileListFilter(Collection fileFilters) { - this.fileFilters = new HashSet(fileFilters); + this.fileFilters = new LinkedHashSet(fileFilters); } + /** * {@inheritDoc} * - * This implementation delegates to a collection of filters and returns only files that pass all - * the filters. + * This implementation delegates to a collection of filters and returns + * only files that pass all the filters. */ public List filterFiles(File[] files) { Assert.notNull(files, "'files' should not be null"); List leftOver = Arrays.asList(files); - for (FileListFilter fileFilter : fileFilters) { + for (FileListFilter fileFilter : this.fileFilters) { leftOver = fileFilter.filterFiles(leftOver.toArray(new File[] {})); } return leftOver; @@ -62,24 +65,23 @@ public class CompositeFileListFilter implements FileListFilter { /** * @see #addFilters(Collection) - * @param filters one or more new filters to be used - * @return a new CompositeFileFilter with the additional filters + * @param filters one or more new filters to add + * @return this CompositeFileFilter instance with the added filters */ public CompositeFileListFilter addFilter(FileListFilter... filters) { return addFilters(Arrays.asList(filters)); } /** - * Creates a new CompositeFileFilter that delegates to both the filters of - * this Composite and the new filters passed in. + * Add the new filters to this CompositeFileFilter while maintaining the + * existing filters. * - * @param filtersToAdd - * @return a new CompositeFileFilter with the added filters + * @param filtersToAdd a list of filters to add + * @return this CompositeFileFilter instance with the added filters */ public CompositeFileListFilter addFilters(Collection filtersToAdd) { - HashSet newFilterSet = new HashSet(filtersToAdd); - newFilterSet.addAll(fileFilters); - return new CompositeFileListFilter(newFilterSet); + this.fileFilters.addAll(filtersToAdd); + return this; } } diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceTests.java b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceTests.java index 38979b7f85..abadaa9998 100644 --- a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceTests.java +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.file; import static org.mockito.Mockito.*; @@ -34,6 +35,7 @@ import org.springframework.integration.core.Message; /** * @author Iwein Fuld + * @author Mark Fisher */ @SuppressWarnings("unchecked") @RunWith(MockitoJUnit44Runner.class) @@ -103,6 +105,11 @@ public class FileReadingMessageSourceTests { verify(inputDirectoryMock,times(2)).listFiles(); } + @Test(expected = IllegalArgumentException.class) + public void nullFilter() throws Exception { + source.setFilter(null); + } + @Test public void orderedReception() throws Exception { File file1 = mock(File.class);