-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50f0bda
commit 0de2ef5
Showing
9 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
nop-batch/nop-batch-core/src/main/java/io/nop/batch/core/consumer/EvalBatchConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.nop.batch.core.consumer; | ||
|
||
import io.nop.batch.core.IBatchChunkContext; | ||
import io.nop.batch.core.IBatchConsumerProvider; | ||
import io.nop.batch.core.IBatchTaskContext; | ||
import io.nop.core.lang.eval.IEvalFunction; | ||
|
||
import java.util.Collection; | ||
|
||
public class EvalBatchConsumer<R> implements IBatchConsumerProvider.IBatchConsumer<R>, IBatchConsumerProvider<R> { | ||
private final IEvalFunction func; | ||
|
||
public EvalBatchConsumer(IEvalFunction func) { | ||
this.func = func; | ||
} | ||
|
||
@Override | ||
public IBatchConsumer<R> setup(IBatchTaskContext context) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public void consume(Collection<R> records, IBatchChunkContext context) { | ||
func.call2(null, records, context, context.getEvalScope()); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...batch-core/src/main/java/io/nop/batch/core/consumer/TransformedBatchConsumerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.nop.batch.core.consumer; | ||
|
||
import io.nop.batch.core.IBatchChunkContext; | ||
import io.nop.batch.core.IBatchConsumerProvider; | ||
import io.nop.batch.core.IBatchTaskContext; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.function.BiFunction; | ||
|
||
public class TransformedBatchConsumerProvider<R> implements IBatchConsumerProvider<R> { | ||
private final IBatchConsumerProvider<R> provider; | ||
private final BiFunction<R, IBatchChunkContext, R> transformer; | ||
|
||
public TransformedBatchConsumerProvider(IBatchConsumerProvider<R> provider, BiFunction<R, IBatchChunkContext, R> transformer) { | ||
this.provider = provider; | ||
this.transformer = transformer; | ||
} | ||
|
||
@Override | ||
public IBatchConsumer<R> setup(IBatchTaskContext context) { | ||
return new TransformedBatchConsumer(provider.setup(context), transformer); | ||
} | ||
|
||
static class TransformedBatchConsumer<R> implements IBatchConsumer<R> { | ||
private final IBatchConsumer<R> consumer; | ||
private final BiFunction<R, IBatchChunkContext, R> transformer; | ||
|
||
public TransformedBatchConsumer(IBatchConsumer<R> consumer, BiFunction<R, IBatchChunkContext, R> transformer) { | ||
this.consumer = consumer; | ||
this.transformer = transformer; | ||
} | ||
|
||
@Override | ||
public void consume(Collection<R> items, IBatchChunkContext context) { | ||
List<R> list = new ArrayList<>(items.size()); | ||
for (R item : items) { | ||
R newItem = transformer.apply(item, context); | ||
if (newItem != null) | ||
list.add(newItem); | ||
} | ||
consumer.consume(list, context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters