Skip to content
Permalink
Browse files
BATCHEE-31 TypedProcesser should also define return type
txs to Reinhard Sandtner for the patch!
  • Loading branch information
struberg committed Apr 27, 2014
1 parent 703d241 commit 0096011ddac3c120cefb0eb862f2cc564484bfd6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
@@ -19,7 +19,7 @@
import java.io.Serializable;
import java.util.Iterator;

import org.apache.batchee.extras.typed.TypedReader;
import org.apache.batchee.extras.typed.TypedItemReader;


/**
@@ -35,7 +35,7 @@
*
* @param <R> the return type of the reader
*/
public abstract class BufferedItemReader<R> extends TypedReader<R, Serializable> {
public abstract class BufferedItemReader<R> extends TypedItemReader<R, Serializable> {

private Iterator<R> valuesIt = null;

@@ -18,11 +18,17 @@

import javax.batch.api.chunk.ItemProcessor;

public abstract class TypedProcessor<R> implements ItemProcessor {
protected abstract Object doProcessItem(R item);
/**
* Typesafe ItemProcessor
*
* @param <I> InputType
* @param <O> ReturnType
*/
public abstract class TypedItemProcessor<I, O> implements ItemProcessor {
protected abstract O doProcessItem(I item);

@Override
public Object processItem(Object item) throws Exception {
return doProcessItem((R) item);
return doProcessItem((I) item);
}
}
@@ -25,7 +25,7 @@
* @param <R> The type of the item returned in {@link #readItem()}.
* @param <C> The type of the Checkpoint. See {@link #doCheckpointInfo()} and {@link #doRead()}
*/
public abstract class TypedReader<R, C extends Serializable> implements ItemReader {
public abstract class TypedItemReader<R, C extends Serializable> implements ItemReader {
protected abstract void doOpen(C checkpoint);
protected abstract R doRead();

@@ -20,7 +20,7 @@
import java.io.Serializable;
import java.util.List;

public abstract class TypedWriter<R, C extends Serializable> implements ItemWriter {
public abstract class TypedItemWriter<R, C extends Serializable> implements ItemWriter {
protected abstract void doOpen(C checkpoint);
protected abstract C doCheckpointInfo();
protected abstract void doWriteItems(List<R> items);
@@ -16,7 +16,7 @@
*/
package org.apache.batchee.extras;

import org.apache.batchee.extras.typed.TypedProcessor;
import org.apache.batchee.extras.typed.TypedItemProcessor;
import org.apache.batchee.util.Batches;
import org.testng.annotations.Test;

@@ -92,11 +92,11 @@ public Serializable checkpointInfo() throws Exception {
}
}

public static abstract class StoreItems extends TypedProcessor<Object> {
public final Collection<Object> items = new ArrayList<Object>();
public static abstract class StoreItems extends TypedItemProcessor<String, String> {
public final Collection<String> items = new ArrayList<String>();

@Override
protected Object doProcessItem(Object item) {
protected String doProcessItem(String item) {
final String value = "" + item + " " + hashCode();
items.add(value);
return value;
@@ -16,7 +16,7 @@
*/
package org.apache.batchee.extras;

import org.apache.batchee.extras.typed.TypedProcessor;
import org.apache.batchee.extras.typed.TypedItemProcessor;
import org.apache.batchee.extras.util.MyProvider;
import org.apache.batchee.extras.util.Person;
import org.apache.batchee.util.Batches;
@@ -65,11 +65,11 @@ public void read() throws Exception {
}
}

public static class StoreItems extends TypedProcessor<Person> {
public static final Collection<Object> ITEMS = new ArrayList<Object>();
public static class StoreItems extends TypedItemProcessor<Person, Person> {
public static final Collection<String> ITEMS = new ArrayList<String>();

@Override
protected Object doProcessItem(Person item) {
protected Person doProcessItem(Person item) {
ITEMS.add(item.getName());
return item;
}

0 comments on commit 0096011

Please sign in to comment.