BATCH-1023: Added javadocs to several classes

This commit is contained in:
dhgarrette
2009-01-27 19:55:05 +00:00
parent cf68753006
commit bd6ff9dd55
7 changed files with 218 additions and 182 deletions

View File

@@ -1,25 +1,30 @@
/*
* Copyright 2006-2007 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.batch.item.file.mapping;
public class PassThroughLineMapper implements LineMapper<String>{
public String mapLine(String line, int lineNumber) throws Exception {
return line;
}
}
/*
* Copyright 2006-2007 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.batch.item.file.mapping;
/**
* Pass through {@link LineMapper} useful for passing the original
* {@link String} back directly rather than a mapped object.
*
*/
public class PassThroughLineMapper implements LineMapper<String>{
public String mapLine(String line, int lineNumber) throws Exception {
return line;
}
}

View File

@@ -1,43 +1,46 @@
/*
* Copyright 2006-2007 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.batch.item.file.transform;
import org.springframework.util.StringUtils;
/**
* @author Dave Syer
*
*/
public class DelimitedLineAggregator<T> extends ExtractorLineAggregator<T> {
private String delimiter = ",";
/**
* Public setter for the delimiter.
* @param delimiter the delimiter to set
*/
public void setDelimiter(String delimiter) {
this.delimiter = delimiter;
}
/**
* @see org.springframework.batch.item.file.transform.ExtractorLineAggregator#doAggregate(java.lang.Object[])
*/
public String doAggregate(Object[] item) {
return StringUtils.arrayToDelimitedString(item, this.delimiter);
}
}
/*
* Copyright 2006-2007 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.batch.item.file.transform;
import org.springframework.util.StringUtils;
/**
* A {@link LineAggregator} implementation that converts an object into a
* delimited list of strings. The default delimiter is a comma.
*
* @author Dave Syer
*
*/
public class DelimitedLineAggregator<T> extends ExtractorLineAggregator<T> {
private String delimiter = ",";
/**
* Public setter for the delimiter.
* @param delimiter the delimiter to set
*/
public void setDelimiter(String delimiter) {
this.delimiter = delimiter;
}
/**
* @see org.springframework.batch.item.file.transform.ExtractorLineAggregator#doAggregate(java.lang.Object[])
*/
public String doAggregate(Object[] item) {
return StringUtils.arrayToDelimitedString(item, this.delimiter);
}
}

View File

@@ -23,6 +23,9 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* A {@link LineTokenizer} implementation that splits the input String on a
* configurable delimiter. This implementation also supports the use of an
* escape character to escape delimiters and line endings.
*
* @author Rob Harrop
* @author Dave Syer

View File

@@ -1,57 +1,62 @@
/*
* Copyright 2006-2007 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.batch.item.file.transform;
import org.springframework.util.Assert;
/**
* @author Dan Garrette
* @since 2.0
*/
public abstract class ExtractorLineAggregator<T> implements LineAggregator<T> {
private FieldExtractor<T> fieldExtractor = new PassThroughFieldExtractor<T>();
/**
* Public setter for the field extractor responsible for splitting an input
* object up into an array of objects. Defaults to
* {@link PassThroughFieldExtractor}.
*
* @param fieldExtractor The field extractor to set
*/
public void setFieldExtractor(FieldExtractor<T> fieldExtractor) {
this.fieldExtractor = fieldExtractor;
}
/**
* Extract fields from the given item using the {@link FieldExtractor} and
* then aggregate them. Null items are not allowed.
*
* @see org.springframework.batch.item.file.transform.LineAggregator#aggregate(java.lang.Object)
*/
public String aggregate(T item) {
Assert.notNull(item);
return this.doAggregate(this.fieldExtractor.extract(item));
}
/**
* Aggregate provided fields into single String.
*
* @param fields An array of the fields that must be aggregated
* @return aggregated string
*/
protected abstract String doAggregate(Object[] fields);
}
/*
* Copyright 2006-2007 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.batch.item.file.transform;
import org.springframework.util.Assert;
/**
* An abstract {@link LineAggregator} implementation that utilizes a
* {@link FieldExtractor} to convert the incoming object to an array of its
* parts. Extending classes must decide how those parts will be aggregated
* together.
*
* @author Dan Garrette
* @since 2.0
*/
public abstract class ExtractorLineAggregator<T> implements LineAggregator<T> {
private FieldExtractor<T> fieldExtractor = new PassThroughFieldExtractor<T>();
/**
* Public setter for the field extractor responsible for splitting an input
* object up into an array of objects. Defaults to
* {@link PassThroughFieldExtractor}.
*
* @param fieldExtractor The field extractor to set
*/
public void setFieldExtractor(FieldExtractor<T> fieldExtractor) {
this.fieldExtractor = fieldExtractor;
}
/**
* Extract fields from the given item using the {@link FieldExtractor} and
* then aggregate them. Null items are not allowed.
*
* @see org.springframework.batch.item.file.transform.LineAggregator#aggregate(java.lang.Object)
*/
public String aggregate(T item) {
Assert.notNull(item);
return this.doAggregate(this.fieldExtractor.extract(item));
}
/**
* Aggregate provided fields into single String.
*
* @param fields An array of the fields that must be aggregated
* @return aggregated string
*/
protected abstract String doAggregate(Object[] fields);
}

View File

@@ -1,26 +1,32 @@
/*
* Copyright 2006-2007 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.batch.item.file.transform;
/**
* @author Dave Syer
*
*/
public interface FieldExtractor<T> {
Object[] extract(T item);
}
/*
* Copyright 2006-2007 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.batch.item.file.transform;
/**
* This class will convert an object to an array of its parts.
*
* @author Dave Syer
*
*/
public interface FieldExtractor<T> {
/**
* @param item
* @return an array containing item's parts
*/
Object[] extract(T item);
}

View File

@@ -1,31 +1,35 @@
/*
* Copyright 2006-2007 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.batch.item.file.transform;
public class PassThroughLineAggregator<T> implements LineAggregator<T> {
/**
* Simply convert to a String with toString().
*
* @see org.springframework.batch.item.file.transform.LineAggregator#aggregate(java.lang.Object)
*/
public String aggregate(T item) {
return item.toString();
}
}
/*
* Copyright 2006-2007 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.batch.item.file.transform;
/**
* A {@link LineAggregator} implementation that simply calls
* {@link Object#toString()} on the given object
*
*/
public class PassThroughLineAggregator<T> implements LineAggregator<T> {
/**
* Simply convert to a String with toString().
*
* @see org.springframework.batch.item.file.transform.LineAggregator#aggregate(java.lang.Object)
*/
public String aggregate(T item) {
return item.toString();
}
}

View File

@@ -21,6 +21,16 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
* A {@link LineTokenizer} implementation that stores a mapping of String
* prefixes to delegate {@link LineTokenizer}s. Each line tokenizied will be
* checked for its prefix. If the prefix matches a key in the map of delegates,
* then the corresponding delegate {@link LineTokenizer} will be used.
* Otherwise, the default {@link LineTokenizer} will be used. The default
* {@link LineTokenizer} can be configured in the delegate map by setting its
* corresponding prefix to the empty string.
*
*/
public class PrefixMatchingCompositeLineTokenizer implements LineTokenizer {
private Map<String, LineTokenizer> tokenizers = new HashMap<String, LineTokenizer>();