com.giffing.easyxml.reader.item.ItemReaderBuilder Maven / Gradle / Ivy
package com.giffing.easyxml.reader.item;
import java.util.function.Function;
import com.giffing.easyxml.context.ParseContext;
public class ItemReaderBuilder {
protected Function shouldHandle;
protected Function function;
public ItemReaderBuilder shouldHandle(Function shouldHandle) {
this.shouldHandle = shouldHandle;
return this;
}
public ItemReaderBuilder shouldHandle(String path) {
return this.shouldHandle((p) -> p.getPath().equals(path));
}
public ItemReaderBuilder withFunction(Function function) {
this.function = function;
return this;
}
public ItemReader build() {
return new ItemReader() {
@Override
public R read(T element) {
return function.apply(element);
}
@Override
public boolean shouldHandle(ParseContext context) {
return shouldHandle.apply(context);
}
};
}
}