Skip to content

Commit

Permalink
feat: Made function support different KeyValue subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed Apr 29, 2024
1 parent c711898 commit 0a4aa57
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package com.redis.spring.batch.gen;

import java.util.function.Function;
import java.util.function.Supplier;

import com.redis.spring.batch.KeyValue;
import com.redis.spring.batch.KeyValue.DataType;
import com.redis.spring.batch.gen.Item.Type;

public class ItemToKeyValueFunction implements Function<Item, KeyValue<String, Object>> {
public class ItemToKeyValueFunction<T extends KeyValue<String, Object>> implements Function<Item, T> {

private final Supplier<T> factory;

public ItemToKeyValueFunction(Supplier<T> factory) {
this.factory = factory;
}

@Override
public KeyValue<String, Object> apply(Item item) {
KeyValue<String, Object> kv = new KeyValue<>();
public T apply(Item item) {
T kv = factory.get();
kv.setKey(item.getKey());
kv.setTtl(item.getTtl());
kv.setType(toRedisTypeString(item.getType()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public abstract class AbstractTestBase {
public static final Duration DEFAULT_AWAIT_TIMEOUT = Duration.ofSeconds(3);

protected static final ItemProcessor<Item, KeyValue<String, Object>> genItemProcessor = new FunctionItemProcessor<>(
new ItemToKeyValueFunction());
new ItemToKeyValueFunction<>(KeyValue::new));

private int chunkSize = DEFAULT_CHUNK_SIZE;
private Duration idleTimeout = DEFAULT_IDLE_TIMEOUT;
Expand Down

0 comments on commit 0a4aa57

Please sign in to comment.