All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.giffing.easyxml.reader.item.ItemReaderBuilder Maven / Gradle / Ivy

There is a newer version: 0.0.8
Show newest version
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);
			}
		};
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy