moved spaces to tabs for the file adapters entries.* package

This commit is contained in:
Josh Long
2010-08-24 22:07:00 +00:00
parent 245ae1d5fa
commit 0ec4e095d5
9 changed files with 162 additions and 167 deletions

View File

@@ -21,7 +21,6 @@ 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
@@ -29,26 +28,26 @@ import java.util.List;
*
* @author Mark Fisher
* @author Iwein Fuld
* @author Josh Long
* @author Josh Long
*/
public abstract class AbstractEntryListFilter<T> implements InitializingBean, EntryListFilter<T> {
public abstract boolean accept(T t);
public abstract boolean accept(T t);
public List<T> filterEntries(T[] entries) {
List<T> accepted = new ArrayList<T>();
public List<T> filterEntries(T[] entries) {
List<T> accepted = new ArrayList<T>();
if (entries != null) {
for (T t : entries) {
if (this.accept(t)) {
accepted.add(t);
}
}
}
if (entries != null) {
for (T t : entries) {
if (this.accept(t)) {
accepted.add(t);
}
}
}
return accepted;
}
return accepted;
}
public void afterPropertiesSet() throws Exception {
// its all you!
}
public void afterPropertiesSet() throws Exception {
// its all you!
}
}

View File

@@ -18,15 +18,15 @@ package org.springframework.integration.file.entries;
/**
* Simple NOOP implementation for {@link org.springframework.integration.file.entries.EntryListFilter} implementation.
* Simple NOOP implementation for {@link org.springframework.integration.file.entries.EntryListFilter} implementation.
* Suitable as a default in implementations.
*
* @author Josh Long
* @param <T>
*/
public class AcceptAllEntryListFilter<T> extends AbstractEntryListFilter<T> {
@Override
public boolean accept(T t) {
return true;
}
@Override
public boolean accept(T t) {
return true;
}
}

View File

@@ -19,7 +19,6 @@ 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
@@ -29,42 +28,42 @@ import java.util.concurrent.LinkedBlockingQueue;
*
* @author Iwein Fuld
* @since 1.0.0
*/
*/
public class AcceptOnceEntryFileListFilter<T> extends AbstractEntryListFilter<T> {
private final Queue<T> seen;
private final Object monitor = new Object();
private final Queue<T> 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<T>(maxCapacity);
}
/**
* 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<T>(maxCapacity);
}
/**
* Creates an AcceptOnceFileFilter based on an unbounded queue.
*/
public AcceptOnceEntryFileListFilter() {
this.seen = new LinkedBlockingQueue<T>();
}
/**
* Creates an AcceptOnceFileFilter based on an unbounded queue.
*/
public AcceptOnceEntryFileListFilter() {
this.seen = new LinkedBlockingQueue<T>();
}
public boolean accept(T pathname) {
synchronized (this.monitor) {
if (seen.contains(pathname)) {
return false;
}
public boolean accept(T pathname) {
synchronized (this.monitor) {
if (seen.contains(pathname)) {
return false;
}
if (!seen.offer(pathname)) {
seen.poll();
seen.add(pathname);
}
if (!seen.offer(pathname)) {
seen.poll();
seen.add(pathname);
}
return true;
}
}
return true;
}
}
}

View File

@@ -22,64 +22,64 @@ import java.util.*;
public class CompositeEntryListFilter<T> implements EntryListFilter<T> {
private final Set<EntryListFilter<T>> fileFilters;
private final Set<EntryListFilter<T>> fileFilters;
public CompositeEntryListFilter() {
this.fileFilters = new LinkedHashSet<EntryListFilter<T>>();
}
public CompositeEntryListFilter() {
this.fileFilters = new LinkedHashSet<EntryListFilter<T>>();
}
public CompositeEntryListFilter(Collection<?extends EntryListFilter<T>> fileFilters) {
this.fileFilters = new LinkedHashSet<EntryListFilter<T>>(fileFilters);
}
public CompositeEntryListFilter(Collection<? extends EntryListFilter<T>> fileFilters) {
this.fileFilters = new LinkedHashSet<EntryListFilter<T>>(fileFilters);
}
@SuppressWarnings("unchecked")
public List<T> filterEntries(T[] entries) {
Assert.notNull(entries, "'files' should not be null");
@SuppressWarnings("unchecked")
public List<T> filterEntries(T[] entries) {
Assert.notNull(entries, "'files' should not be null");
List<T> leftOver = Arrays.asList(entries);
List<T> leftOver = Arrays.asList(entries);
for (EntryListFilter<T> fileFilter : this.fileFilters) {
T[] ts = (T[]) leftOver.toArray();
leftOver = fileFilter.filterEntries(ts);
}
for (EntryListFilter<T> fileFilter : this.fileFilters) {
T[] ts = (T[]) leftOver.toArray();
leftOver = fileFilter.filterEntries(ts);
}
return leftOver;
}
return leftOver;
}
public CompositeEntryListFilter<T> addFilter(EntryListFilter<T> filter) {
return this.addFilters(Arrays.asList(filter));
}
public CompositeEntryListFilter<T> addFilter(EntryListFilter<T> filter) {
return this.addFilters(Arrays.asList(filter));
}
/**
* @param filters one or more new filters to add
* @return this CompositeFileFilter instance with the added filters
* @see #addFilters(Collection)
*/
@SuppressWarnings("unused")
public CompositeEntryListFilter<T> addFilters(EntryListFilter<T>[] filters) {
return addFilters(Arrays.asList(filters));
}
/**
* @param filters one or more new filters to add
* @return this CompositeFileFilter instance with the added filters
* @see #addFilters(Collection)
*/
@SuppressWarnings("unused")
public CompositeEntryListFilter<T> addFilters(EntryListFilter<T>[] filters) {
return addFilters(Arrays.asList(filters));
}
/**
* Not thread safe. Only a single thread may add filters at a time.
* <p/>
* 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<T> addFilters(Collection<EntryListFilter<T>> filtersToAdd) {
for (EntryListFilter<T> elf : filtersToAdd)
if (elf instanceof InitializingBean) {
try {
((InitializingBean) elf).afterPropertiesSet();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Not thread safe. Only a single thread may add filters at a time.
* <p/>
* 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<T> addFilters(Collection<EntryListFilter<T>> filtersToAdd) {
for (EntryListFilter<T> elf : filtersToAdd)
if (elf instanceof InitializingBean) {
try {
((InitializingBean) elf).afterPropertiesSet();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
this.fileFilters.addAll(filtersToAdd);
this.fileFilters.addAll(filtersToAdd);
return this;
}
return this;
}
}

View File

@@ -32,5 +32,5 @@ import java.util.List;
* @since 1.0.0
*/
public interface EntryListFilter<T> {
List<T> filterEntries(T[] entries);
List<T> filterEntries(T[] entries);
}

View File

@@ -17,19 +17,18 @@ package org.springframework.integration.file.entries;
/**
* Responsible for coercing a String identification out of the T entry.
* @param <T> the type of entry (there's an implementation for FTP, SFTP, and plain-old java.io.Files)
*
* @author Josh Long
* @param <T> the type of entry (there's an implementation for FTP, SFTP, and plain-old java.io.Files)
*/
public interface EntryNamer<T> {
/**
* This is the one place I couldn't spackle over the interface differences between an FTPFile (FTP adapter), File (File adapter), and LsEntry (SFTP adapter)
* with generics alone. So we have a typed strategy implementation for accessing a property ....
*
*
* @param entry the entry in a file system listing
* @return the String name that might be used to reference that entry or to do regular expression checks against
*/
String nameOf(T entry);
/**
* This is the one place I couldn't spackle over the interface differences between an FTPFile (FTP adapter), File (File adapter), and LsEntry (SFTP adapter)
* with generics alone. So we have a typed strategy implementation for accessing a property ....
*
* @param entry the entry in a file system listing
* @return the String name that might be used to reference that entry or to do regular expression checks against
*/
String nameOf(T entry);
}

View File

@@ -21,14 +21,13 @@ import java.io.File;
/**
* {@link java.io.File} implementation of the {@link org.springframework.integration.file.entries.EntryNamer} strategy.
*
* <p/>
* This part feels a little over-engineered...
*
* @author Josh Long
*
*/
public class FileEntryNamer implements EntryNamer<File> {
public String nameOf(File entry) {
return (entry != null) ? entry.getName() : null;
}
public String nameOf(File entry) {
return (entry != null) ? entry.getName() : null;
}
}

View File

@@ -16,7 +16,6 @@
package org.springframework.integration.file.entries;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -33,42 +32,42 @@ import java.util.regex.Pattern;
* @param <T> the type of entry
*/
public class PatternMatchingEntryListFilter<T> extends AbstractEntryListFilter<T> implements InitializingBean {
private Pattern pattern;
private String patternExpression;
private EntryNamer<T> entryNamer;
private Pattern pattern;
private String patternExpression;
private EntryNamer<T> entryNamer;
public PatternMatchingEntryListFilter(EntryNamer<T> en, String p) {
this.entryNamer = en;
this.patternExpression = p;
}
public PatternMatchingEntryListFilter(EntryNamer<T> en, String p) {
this.entryNamer = en;
this.patternExpression = p;
}
public PatternMatchingEntryListFilter(EntryNamer<T> en, Pattern p) {
this.entryNamer = en;
this.pattern = p;
}
public PatternMatchingEntryListFilter(EntryNamer<T> en, Pattern p) {
this.entryNamer = en;
this.pattern = p;
}
public void setPattern(Pattern pattern) {
this.pattern = pattern;
}
public void setPattern(Pattern pattern) {
this.pattern = pattern;
}
public void setPatternExpression(String patternExpression) {
this.patternExpression = patternExpression;
}
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.entryNamer, "'entryNamer' must not be null!");
Assert.notNull(this.pattern, "'pattern' mustn't be null!");
}
@Override
public boolean accept(T t) {
return (t != null) && this.pattern.matcher(this.entryNamer.nameOf(t)).matches();
}
public void afterPropertiesSet() throws Exception {
if (StringUtils.hasText(this.patternExpression) && (pattern == null)) {
this.pattern = Pattern.compile(this.patternExpression);
}
Assert.notNull(this.entryNamer, "'entryNamer' must not be null!");
Assert.notNull(this.pattern, "'pattern' mustn't be null!");
}
public void setEntryNamer(EntryNamer<T> entryNamer) {
this.entryNamer = entryNamer;
}
@Override
public boolean accept(T t) {
return (t != null) && this.pattern.matcher(this.entryNamer.nameOf(t)).matches();
}
public void setEntryNamer(EntryNamer<T> entryNamer) {
this.entryNamer = entryNamer;
}
}

View File

@@ -27,20 +27,20 @@ import org.springframework.util.Assert;
*/
public class SingleEntryAdaptingEntryListFilter<T> extends AbstractEntryListFilter<T> {
/**
* the {@link org.springframework.integration.file.entries.EntryListFilter} that you'd like to delegate to
*/
private volatile EntryListFilter<T> entryFilter;
/**
* the {@link org.springframework.integration.file.entries.EntryListFilter} that you'd like to delegate to
*/
private volatile EntryListFilter<T> entryFilter;
public SingleEntryAdaptingEntryListFilter(EntryListFilter<T> ef) {
this.entryFilter = ef;
Assert.notNull(this.entryFilter, "the entryFilter can't be null");
}
public SingleEntryAdaptingEntryListFilter(EntryListFilter<T> ef) {
this.entryFilter = ef;
Assert.notNull(this.entryFilter, "the entryFilter can't be null");
}
@Override
@SuppressWarnings("unchecked")
public boolean accept(T t) {
T[] ts = (T[]) new Object[] { t };
return this.entryFilter.filterEntries(ts).size() == 1;
}
@Override
@SuppressWarnings("unchecked")
public boolean accept(T t) {
T[] ts = (T[]) new Object[]{t};
return this.entryFilter.filterEntries(ts).size() == 1;
}
}