From 8a46cfc0e881fd56caac3255d2d91831fe0a8653 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 8 Nov 2010 17:51:25 -0500 Subject: [PATCH] INT-1591 removed 'entries' package --- .../file/entries/AbstractEntryListFilter.java | 61 ------------ .../entries/AcceptAllEntryListFilter.java | 34 ------- .../AcceptOnceEntryFileListFilter.java | 71 -------------- .../entries/CompositeEntryListFilter.java | 95 ------------------- .../file/entries/EntryListFilter.java | 40 -------- .../PatternMatchingEntryListFilter.java | 79 --------------- .../PatternMatchingFileListFilterTests.java | 6 +- ...alidPatternMatchingFileListFilterTests.xml | 2 +- 8 files changed, 3 insertions(+), 385 deletions(-) delete mode 100644 spring-integration-file/src/main/java/org/springframework/integration/file/entries/AbstractEntryListFilter.java delete mode 100644 spring-integration-file/src/main/java/org/springframework/integration/file/entries/AcceptAllEntryListFilter.java delete mode 100644 spring-integration-file/src/main/java/org/springframework/integration/file/entries/AcceptOnceEntryFileListFilter.java delete mode 100644 spring-integration-file/src/main/java/org/springframework/integration/file/entries/CompositeEntryListFilter.java delete mode 100644 spring-integration-file/src/main/java/org/springframework/integration/file/entries/EntryListFilter.java delete mode 100644 spring-integration-file/src/main/java/org/springframework/integration/file/entries/PatternMatchingEntryListFilter.java diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/AbstractEntryListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/entries/AbstractEntryListFilter.java deleted file mode 100644 index 8ec4156798..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/AbstractEntryListFilter.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2002-2010 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.file.entries; - -import org.springframework.beans.factory.InitializingBean; - -import java.util.ArrayList; -import java.util.List; - -/** - * A convenience base class for any {@link EntryListFilter} whose criteria can be - * evaluated against each File in isolation. If the entire List of files is - * required for evaluation, implement the {@link EntryListFilter} interface directly. - * - * @author Mark Fisher - * @author Iwein Fuld - * @author Josh Long - */ -public abstract class AbstractEntryListFilter implements InitializingBean, EntryListFilter { - - /** - * subclasses may override this if initialization is required - */ - public void afterPropertiesSet() throws Exception { - } - - /** - * {@inheritDoc} - */ - public List filterEntries(T[] entries) { - List accepted = new ArrayList(); - if (entries != null) { - for (T t : entries) { - if (this.accept(t)) { - accepted.add(t); - } - } - } - return accepted; - } - - /** - * subclasses must implement this method - */ - public abstract boolean accept(T entry); - -} diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/AcceptAllEntryListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/entries/AcceptAllEntryListFilter.java deleted file mode 100644 index 2aa2f746fb..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/AcceptAllEntryListFilter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2002-2010 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.file.entries; - -/** - * Simple NO-OP implementation of {@link org.springframework.integration.file.entries.EntryListFilter}. - * Suitable as a default. - * - * @author Iwein Fuld - * @author Josh Long - * @param - */ -public class AcceptAllEntryListFilter extends AbstractEntryListFilter { - - @Override - public boolean accept(T entry) { - return true; - } - -} diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/AcceptOnceEntryFileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/entries/AcceptOnceEntryFileListFilter.java deleted file mode 100644 index fa24d65bd3..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/AcceptOnceEntryFileListFilter.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2002-2010 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.file.entries; - -import java.util.Queue; -import java.util.concurrent.LinkedBlockingQueue; - -/** - * {@link EntryListFilter} that passes files only one time. This can - * conveniently be used to prevent duplication of files, as is done in - * {@link org.springframework.integration.file.FileReadingMessageSource}. - *

- * This implementation is thread safe. - * - * @author Iwein Fuld - * @since 1.0.0 - */ -public class AcceptOnceEntryFileListFilter extends AbstractEntryListFilter { - - private final Queue seen; - - private final Object monitor = new Object(); - - - /** - * Creates an {@link org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter} - * that is based on a bounded queue. If the queue overflows, files that fall out will be passed - * through this filter again if passed to the {@link #filterEntries(Object[])} method. - * - * @param maxCapacity the maximum number of Files to maintain in the 'seen' queue. - */ - public AcceptOnceEntryFileListFilter(int maxCapacity) { - this.seen = new LinkedBlockingQueue(maxCapacity); - } - - /** - * Creates an AcceptOnceFileFilter based on an unbounded queue. - */ - public AcceptOnceEntryFileListFilter() { - this.seen = new LinkedBlockingQueue(); - } - - - public boolean accept(T pathname) { - synchronized (this.monitor) { - if (this.seen.contains(pathname)) { - return false; - } - if (!this.seen.offer(pathname)) { - this.seen.poll(); - this.seen.add(pathname); - } - return true; - } - } - -} diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/CompositeEntryListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/entries/CompositeEntryListFilter.java deleted file mode 100644 index 415c5bc1d4..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/CompositeEntryListFilter.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2002-2010 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.file.entries; - -import org.springframework.beans.factory.InitializingBean; -import org.springframework.util.Assert; - -import java.util.*; - -/** - * Simple {@link org.springframework.integration.file.entries.EntryListFilter} that predicates its matches - * against any of many configured {@link org.springframework.integration.file.entries.EntryListFilter} - * - * @author Iwein Fuld - * @author Josh Long - * - * @param - */ -public class CompositeEntryListFilter implements EntryListFilter { - - private final Set> fileFilters; - - - public CompositeEntryListFilter() { - this.fileFilters = new LinkedHashSet>(); - } - - public CompositeEntryListFilter(Collection> fileFilters) { - this.fileFilters = new LinkedHashSet>(fileFilters); - } - - - public CompositeEntryListFilter addFilter(EntryListFilter filter) { - return this.addFilters(Collections.singletonList(filter)); - } - - /** - * @param filters one or more new filters to add - * @return this CompositeFileFilter instance with the added filters - * @see #addFilters(Collection) - */ - public CompositeEntryListFilter addFilters(EntryListFilter... filters) { - return addFilters(Arrays.asList(filters)); - } - - /** - * Not thread safe. Only a single thread may add filters at a time. - *

- * Add the new filters to this CompositeFileFilter while maintaining the existing filters. - * - * @param filtersToAdd a list of filters to add - * @return this CompositeEntryListFilter instance with the added filters - */ - public CompositeEntryListFilter addFilters(Collection> filtersToAdd) { - for (EntryListFilter elf : filtersToAdd) { - if (elf instanceof InitializingBean) { - try { - ((InitializingBean) elf).afterPropertiesSet(); - } - catch (Exception e) { - throw new RuntimeException(e); - } - } - } - this.fileFilters.addAll(filtersToAdd); - return this; - } - - - @SuppressWarnings("unchecked") - public List filterEntries(T[] entries) { - Assert.notNull(entries, "'files' should not be null"); - List leftOver = Arrays.asList(entries); - for (EntryListFilter fileFilter : this.fileFilters) { - T[] ts = (T[]) leftOver.toArray(); - leftOver = fileFilter.filterEntries(ts); - } - return leftOver; - } - -} diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/EntryListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/entries/EntryListFilter.java deleted file mode 100644 index 9a49b253e1..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/EntryListFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2002-2010 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.file.entries; - -import java.util.List; - -/** - * Strategy interface for filtering entries representing files on a local or remote file system. This is a generic - * variant of FileListFilter that also works with references to remote files. - *

- * Implementations must be thread safe. - * - * @author Josh Long - * @author Iwein Fuld - * @since 2.0 - * @see org.springframework.integration.file.filters.FileListFilter - */ -public interface EntryListFilter { - - /** - * Filters out entries and returns the entries that are left in a list, or an - * empty list when null is passed in. - */ - List filterEntries(T[] entries); - -} diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/PatternMatchingEntryListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/entries/PatternMatchingEntryListFilter.java deleted file mode 100644 index 2fdc2def3c..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/PatternMatchingEntryListFilter.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2002-2010 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.file.entries; - -import org.springframework.beans.factory.InitializingBean; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -import java.util.regex.Pattern; - -/** - * Filters a listing of entries (T) by qualifying their 'name' (as determined by {@link org.springframework.integration.file.entries.EntryNameExtractor}) - * against a regular expression (an instance of {@link java.util.regex.Pattern}) - * - * @author Iwein Fuld - * @author Josh Long - * @param the type of entry - * @since 2.0 - */ -public class PatternMatchingEntryListFilter extends AbstractEntryListFilter implements InitializingBean { - - private volatile EntryNameExtractor entryNameExtractor; - - private volatile Pattern pattern; - - private volatile String patternExpression; - - - public PatternMatchingEntryListFilter(EntryNameExtractor entryNameExtractor, String pattern) { - this.entryNameExtractor = entryNameExtractor; - this.patternExpression = pattern; - } - - public PatternMatchingEntryListFilter(EntryNameExtractor entryNameExtractor, Pattern pattern) { - this.entryNameExtractor = entryNameExtractor; - this.pattern = pattern; - } - - - public void setEntryNameExtractor(EntryNameExtractor entryNameExtractor) { - this.entryNameExtractor = entryNameExtractor; - } - - public void setPattern(Pattern pattern) { - this.pattern = pattern; - } - - public void setPatternExpression(String patternExpression) { - this.patternExpression = patternExpression; - } - - public void afterPropertiesSet() throws Exception { - if (StringUtils.hasText(this.patternExpression) && (pattern == null)) { - this.pattern = Pattern.compile(this.patternExpression); - } - Assert.notNull(this.entryNameExtractor, "'entryNameExtractor' must not be null!"); - Assert.notNull(this.pattern, "'pattern' must not be null!"); - } - - @Override - public boolean accept(T entry) { - return (entry != null) && this.pattern.matcher(this.entryNameExtractor.getName(entry)).matches(); - } - -} diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java index a02b72beb7..65f749c70c 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java @@ -28,7 +28,6 @@ import org.junit.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.file.entries.FileEntryNameExtractor; -import org.springframework.integration.file.entries.PatternMatchingEntryListFilter; import org.springframework.integration.file.filters.FileListFilter; import org.springframework.integration.file.filters.PatternMatchingFileListFilter; @@ -66,14 +65,13 @@ public class PatternMatchingFileListFilterTests { new File("/some/path/bar.not") }; Pattern pattern = Pattern.compile("[a-z]+\\.txt"); - PatternMatchingEntryListFilter filter = new PatternMatchingEntryListFilter(this.fileEntryNameExtractor, pattern); - List accepted = filter.filterEntries(files); + PatternMatchingFileListFilter filter = new PatternMatchingFileListFilter(this.fileEntryNameExtractor, pattern); + List accepted = filter.filterFiles(files); assertEquals(2, accepted.size()); assertTrue(accepted.contains(new File("/some/path/foo.txt"))); assertTrue(accepted.contains(new File("/some/path/bar.txt"))); } - @Test @SuppressWarnings("unchecked") public void patternEditorInContext() { diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/invalidPatternMatchingFileListFilterTests.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/invalidPatternMatchingFileListFilterTests.xml index 9a8517c663..f138c5a104 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/invalidPatternMatchingFileListFilterTests.xml +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/invalidPatternMatchingFileListFilterTests.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - +