BATCH-1906: Fixed documentation and whitespace

This commit is contained in:
Michael Minella
2013-03-04 18:08:37 -06:00
parent 6e7b290727
commit c993e4c4e7
4 changed files with 104 additions and 86 deletions

View File

@@ -1,3 +1,18 @@
/*
* Copyright 20013 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;
import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader;
@@ -9,7 +24,11 @@ import org.springframework.batch.item.support.AbstractItemCountingItemStreamItem
* @author Jimmy Praet
*/
public interface ItemCountAware {
void setItemCount(int count);
/**
* Setter for the injection of the current item count.
*
* @param count the number of items that have been processed in this execution.
*/
void setItemCount(int count);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 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.
@@ -74,7 +74,7 @@ public abstract class AbstractItemCountingItemStreamItemReader<T> extends Abstra
}
}
@Override
@Override
public final T read() throws Exception, UnexpectedInputException, ParseException {
if (currentItemCount >= maxItemCount) {
return null;
@@ -82,8 +82,8 @@ public abstract class AbstractItemCountingItemStreamItemReader<T> extends Abstra
currentItemCount++;
T item = doRead();
if(item instanceof ItemCountAware) {
((ItemCountAware) item).setItemCount(currentItemCount);
}
((ItemCountAware) item).setItemCount(currentItemCount);
}
return item;
}
@@ -120,9 +120,9 @@ public abstract class AbstractItemCountingItemStreamItemReader<T> extends Abstra
this.maxItemCount = count;
}
@Override
@Override
public void close() throws ItemStreamException {
super.close();
super.close();
currentItemCount = 0;
try {
doClose();
@@ -132,9 +132,9 @@ public abstract class AbstractItemCountingItemStreamItemReader<T> extends Abstra
}
}
@Override
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
super.open(executionContext);
super.open(executionContext);
try {
doOpen();
}
@@ -166,9 +166,9 @@ public abstract class AbstractItemCountingItemStreamItemReader<T> extends Abstra
}
@Override
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
super.update(executionContext);
super.update(executionContext);
if (saveState) {
Assert.notNull(executionContext, "ExecutionContext must not be null");
executionContext.putInt(getExecutionContextKey(READ_COUNT), currentItemCount);
@@ -187,7 +187,7 @@ public abstract class AbstractItemCountingItemStreamItemReader<T> extends Abstra
* @param name the name for the component
*/
public void setName(String name) {
this.setExecutionContextName(name);
this.setExecutionContextName(name);
}
/**

View File

@@ -32,7 +32,7 @@ public class FlatFileItemReaderTests {
private String TEST_STRING = "FlatFileInputTemplate-TestData";
private FlatFileItemReader<String> reader = new FlatFileItemReader<String>();
private FlatFileItemReader<Item> itemReader = new FlatFileItemReader<Item>();
private ExecutionContext executionContext = new ExecutionContext();
@@ -54,18 +54,18 @@ public class FlatFileItemReaderTests {
// 1 record = 2 lines
boolean pair = true;
@Override
@Override
public boolean isEndOfRecord(String line) {
pair = !pair;
return pair;
}
@Override
@Override
public String postProcess(String record) {
return record;
}
@Override
@Override
public String preProcess(String record) {
return record;
}
@@ -92,18 +92,18 @@ public class FlatFileItemReaderTests {
// 1 record = 2 lines
boolean pair = true;
@Override
@Override
public boolean isEndOfRecord(String line) {
pair = !pair;
return pair;
}
@Override
@Override
public String postProcess(String record) {
return record;
}
@Override
@Override
public String preProcess(String record) {
return record;
}
@@ -131,17 +131,17 @@ public class FlatFileItemReaderTests {
reader.setRecordSeparatorPolicy(new RecordSeparatorPolicy() {
@Override
@Override
public boolean isEndOfRecord(String line) {
return StringUtils.hasText(line);
}
@Override
@Override
public String postProcess(String record) {
return StringUtils.hasText(record) ? record : null;
}
@Override
@Override
public String preProcess(String record) {
return record;
}
@@ -165,7 +165,7 @@ public class FlatFileItemReaderTests {
// 1 record = 2 lines
boolean pair = true;
@Override
@Override
public boolean isEndOfRecord(String line) {
if (StringUtils.hasText(line)) {
pair = !pair;
@@ -173,12 +173,12 @@ public class FlatFileItemReaderTests {
return pair;
}
@Override
@Override
public String postProcess(String record) {
return StringUtils.hasText(record) ? record : null;
}
@Override
@Override
public String preProcess(String record) {
return record;
}
@@ -323,17 +323,17 @@ public class FlatFileItemReaderTests {
public void testOpenBadIOInput() throws Exception {
reader.setResource(new AbstractResource() {
@Override
@Override
public String getDescription() {
return null;
}
@Override
@Override
public InputStream getInputStream() throws IOException {
throw new IOException();
}
@Override
@Override
public boolean exists() {
return true;
}
@@ -408,7 +408,7 @@ public class FlatFileItemReaderTests {
@Test
public void testMappingExceptionWrapping() throws Exception {
LineMapper<String> exceptionLineMapper = new LineMapper<String>() {
@Override
@Override
public String mapLine(String line, int lineNumber) throws Exception {
if (lineNumber == 2) {
throw new Exception("Couldn't map line 2");
@@ -433,7 +433,7 @@ public class FlatFileItemReaderTests {
assertEquals("Parsing error at line: 2 in resource=[resource loaded from byte array], input=[testLine2]", expected.getMessage());
}
}
@Test
public void testItemCountAware() throws Exception {
itemReader.open(executionContext);
@@ -445,13 +445,13 @@ public class FlatFileItemReaderTests {
assertEquals(2, item2.getItemCount());
itemReader.update(executionContext);
itemReader.close();
itemReader.open(executionContext);
Item item3 = itemReader.read();
assertEquals("testLine3", item3.getValue());
assertEquals(3, item3.getItemCount());
}
@Test
public void testItemCountAwareMultiLine() throws Exception {
itemReader.setRecordSeparatorPolicy(new RecordSeparatorPolicy() {
@@ -459,7 +459,7 @@ public class FlatFileItemReaderTests {
// 1 record = 2 lines
boolean pair = true;
@Override
@Override
public boolean isEndOfRecord(String line) {
if (StringUtils.hasText(line)) {
pair = !pair;
@@ -467,17 +467,17 @@ public class FlatFileItemReaderTests {
return pair;
}
@Override
@Override
public String postProcess(String record) {
return StringUtils.hasText(record) ? record : null;
}
@Override
@Override
public String preProcess(String record) {
return record;
}
});
});
itemReader.open(executionContext);
Item item1 = itemReader.read();
assertEquals("testLine1testLine2", item1.getValue());
@@ -487,12 +487,12 @@ public class FlatFileItemReaderTests {
assertEquals(2, item2.getItemCount());
itemReader.update(executionContext);
itemReader.close();
itemReader.open(executionContext);
Item item3 = itemReader.read();
assertEquals("testLine5testLine6", item3.getValue());
assertEquals(3, item3.getItemCount());
}
}
private Resource getInputResource(String input) {
return new ByteArrayResource(input.getBytes());
@@ -503,57 +503,58 @@ public class FlatFileItemReaderTests {
public NonExistentResource() {
}
@Override
@Override
public boolean exists() {
return false;
}
@Override
@Override
public String getDescription() {
return "NonExistentResource";
}
@Override
@Override
public InputStream getInputStream() throws IOException {
return null;
}
}
private static class Item implements ItemCountAware {
private String value;
private int itemCount;
public Item(String value) {
this.value = value;
}
@SuppressWarnings("unused")
public void setValue(String value) {
this.value = value;
}
public String getValue() {
return value;
}
@Override
public void setItemCount(int count) {
this.itemCount = count;
}
public int getItemCount() {
return itemCount;
}
}
private static final class ItemLineMapper implements LineMapper<Item> {
@Override
public Item mapLine(String line, int lineNumber) throws Exception {
return new Item(line);
}
}
}

View File

@@ -116,7 +116,7 @@ public class StaxEventItemReaderTests {
source.close();
}
@Test
public void testItemCountAwareFragment() throws Exception {
StaxEventItemReader<ItemCountAwareFragment> source = createNewItemCountAwareInputSouce();
@@ -127,8 +127,8 @@ public class StaxEventItemReaderTests {
assertNull(source.read()); // there are only two fragments
source.close();
}
}
@Test
public void testItemCountAwareFragmentRestart() throws Exception {
StaxEventItemReader<ItemCountAwareFragment> source = createNewItemCountAwareInputSouce();
@@ -144,7 +144,7 @@ public class StaxEventItemReaderTests {
assertNull(source.read()); // there are only two fragments
source.close();
}
}
@Test
public void testFragmentNamespace() throws Exception {
@@ -265,14 +265,14 @@ public class StaxEventItemReaderTests {
assertNull(source.read());
source.update(executionContext);
source.close();
assertEquals(3, executionContext.getInt(ClassUtils.getShortName(StaxEventItemReader.class) + ".read.count"));
source = createNewInputSouce();
source.open(executionContext);
assertNull(source.read());
}
@Test
public void testRestoreWorksFromClosedStream() throws Exception {
source.close();
@@ -341,17 +341,17 @@ public class StaxEventItemReaderTests {
public void testOpenBadIOInput() throws Exception {
source.setResource(new AbstractResource() {
@Override
@Override
public String getDescription() {
return null;
}
@Override
@Override
public InputStream getInputStream() throws IOException {
throw new IOException();
}
@Override
@Override
public boolean exists() {
return true;
}
@@ -456,12 +456,12 @@ public class StaxEventItemReaderTests {
public static final String MESSAGE = "Unmarshallers on strike.";
@Override
@Override
public Object unmarshal(Source source) throws XmlMappingException, IOException {
throw new UnmarshallingFailureException(MESSAGE);
}
@Override
@Override
@SuppressWarnings("rawtypes")
public boolean supports(Class clazz) {
return true;
@@ -481,7 +481,7 @@ public class StaxEventItemReaderTests {
return newSource;
}
private StaxEventItemReader<ItemCountAwareFragment> createNewItemCountAwareInputSouce() {
Resource resource = new ByteArrayResource(xml.getBytes());
@@ -493,7 +493,7 @@ public class StaxEventItemReaderTests {
newSource.setSaveState(true);
return newSource;
}
}
/**
* A simple XMLEvent unmarshaller mock - check for the start and end document events for the fragment root & end
@@ -519,7 +519,7 @@ public class StaxEventItemReaderTests {
return events;
}
@Override
@Override
@SuppressWarnings("rawtypes")
public boolean supports(Class clazz) {
return true;
@@ -531,7 +531,7 @@ public class StaxEventItemReaderTests {
* @param source
* @return list of the events from fragment body
*/
@Override
@Override
public Object unmarshal(Source source) throws XmlMappingException, IOException {
List<XMLEvent> fragmentContent;
@@ -567,11 +567,12 @@ public class StaxEventItemReaderTests {
}
}
@SuppressWarnings("unchecked")
private static class ItemCountAwareMockFragmentUnmarshaller extends MockFragmentUnmarshaller {
@Override
public Object unmarshal(Source source) throws XmlMappingException,
IOException {
IOException {
List<XMLEvent> fragment = (List<XMLEvent>) super.unmarshal(source);
if(fragment != null) {
return new ItemCountAwareFragment(fragment);
@@ -580,33 +581,30 @@ public class StaxEventItemReaderTests {
}
}
}
private static class ItemCountAwareFragment implements ItemCountAware {
private List<XMLEvent> fragment;
private int itemCount;
private int itemCount;
public ItemCountAwareFragment(List<XMLEvent> fragment) {
this.fragment = fragment;
}
@Override
public void setItemCount(int count) {
this.itemCount = count;
}
public int getItemCount() {
return itemCount;
}
}
private static class MockStaxEventItemReader extends StaxEventItemReader<List<XMLEvent>> {
private boolean openCalled = false;
@Override
@Override
public void open(ExecutionContext executionContext) {
super.open(executionContext);
openCalled = true;
@@ -626,17 +624,17 @@ public class StaxEventItemReaderTests {
public NonExistentResource() {
}
@Override
@Override
public boolean exists() {
return false;
}
@Override
@Override
public String getDescription() {
return "NonExistantResource";
}
@Override
@Override
public InputStream getInputStream() throws IOException {
return null;
}