com.g2forge.gearbox.browser.operation.WrappedOperationBuilder Maven / Gradle / Ivy
package com.g2forge.gearbox.browser.operation;
import com.g2forge.alexandria.java.function.IConsumer1;
import com.g2forge.alexandria.java.function.IFunction1;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class WrappedOperationBuilder implements IOperationBuilder {
protected final IFunction1 super T, IOperationWrapper> factory;
protected final IOperationBuilder operation;
@Override
public T execute(IConsumer1 super T> operation) {
return this.operation.execute(t -> {
final IOperationWrapper wrapper = factory.apply(t);
operation.curry(t).wrap(wrapper::pre, wrapper::post).run();
});
}
@Override
public V until(int seconds, IFunction1 super T, ? extends V> function) {
return this.operation.until(seconds, t -> {
final IOperationWrapper wrapper = factory.apply(t);
return function.curry(t).wrap(wrapper::pre, wrapper::post);
}).get();
}
@Override
public IOperationBuilder wrap(IFunction1 super T, IOperationWrapper> factory) {
return new WrappedOperationBuilder<>(factory, this);
}
}